aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-09-05 14:41:41 +0300
committerBonfaceKilz2023-09-05 14:57:51 +0300
commit8bb89dd929506af37675ed5e65737ac79ca0678e (patch)
tree36c7bcdaefc62b33e1710d02d50df8f901c7c120
parentbf8296c5c3093aef32a5cd91fb008ad257e7a2f1 (diff)
downloadgenenetwork3-8bb89dd929506af37675ed5e65737ac79ca0678e.tar.gz
Fix C3001: Lambda expression assigned to a variable
Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
-rw-r--r--gn3/api/search.py6
-rw-r--r--gn3/auth/authentication/oauth2/endpoints/utilities.py3
-rw-r--r--gn3/auth/authentication/oauth2/models/oauth2token.py3
-rw-r--r--gn3/computations/partial_correlations.py6
-rw-r--r--gn3/db/partial_correlations.py3
-rw-r--r--tests/unit/auth/test_groups.py5
-rw-r--r--tests/unit/auth/test_privileges.py5
-rw-r--r--tests/unit/auth/test_resources.py25
-rw-r--r--tests/unit/auth/test_roles.py6
9 files changed, 38 insertions, 24 deletions
diff --git a/gn3/api/search.py b/gn3/api/search.py
index aa844ee..c741b15 100644
--- a/gn3/api/search.py
+++ b/gn3/api/search.py
@@ -152,7 +152,8 @@ def parse_position_field(location_slot: int, query: bytes) -> xapian.Query:
"""Parse position and return a xapian query."""
start, end = parse_position(query.decode("utf-8"))
# TODO: Convert the xapian index to use bases instead of megabases.
- to_megabases = lambda x: str(Decimal(x)/10**6)
+ def to_megabases(val):
+ return str(Decimal(val)/10**6)
return (xapian.NumberRangeProcessor(location_slot)
(start.maybe("", to_megabases), end.maybe("", to_megabases))) # type: ignore
@@ -176,7 +177,8 @@ def parse_location_field(species_query: xapian.Query,
def make_query(interval: ChromosomalInterval) -> xapian.Query:
# TODO: Convert the xapian index to use bases instead of megabases.
- to_megabases = lambda x: str(Decimal(x)/10**6)
+ def to_megabases(val):
+ return str(Decimal(val)/10**6)
return combine_queries(xapian.Query.OP_AND,
species_query,
xapian.Query(chromosome_prefix + interval.chromosome),
diff --git a/gn3/auth/authentication/oauth2/endpoints/utilities.py b/gn3/auth/authentication/oauth2/endpoints/utilities.py
index 299f151..e13784e 100644
--- a/gn3/auth/authentication/oauth2/endpoints/utilities.py
+++ b/gn3/auth/authentication/oauth2/endpoints/utilities.py
@@ -12,7 +12,8 @@ def query_token(# pylint: disable=[unused-argument]
endpoint_object: Any, token_str: str, token_type_hint) -> Optional[
OAuth2Token]:
"""Retrieve the token from the database."""
- __identity__ = lambda val: val
+ def __identity__(val):
+ return val
token = Nothing
with db.connection(current_app.config["AUTH_DB"]) as conn:
if token_type_hint == "access_token":
diff --git a/gn3/auth/authentication/oauth2/models/oauth2token.py b/gn3/auth/authentication/oauth2/models/oauth2token.py
index 72e20cc..bfe4aaf 100644
--- a/gn3/auth/authentication/oauth2/models/oauth2token.py
+++ b/gn3/auth/authentication/oauth2/models/oauth2token.py
@@ -51,7 +51,8 @@ class OAuth2Token(NamedTuple):
return self.revoked
def __token_from_resultset__(conn: db.DbConnection, rset) -> Maybe:
- __identity__ = lambda val: val
+ def __identity__(val):
+ return val
try:
the_user = user_by_id(conn, uuid.UUID(rset["user_id"]))
except NotFoundError as _nfe:
diff --git a/gn3/computations/partial_correlations.py b/gn3/computations/partial_correlations.py
index 9f02ad2..6eee299 100644
--- a/gn3/computations/partial_correlations.py
+++ b/gn3/computations/partial_correlations.py
@@ -421,9 +421,7 @@ def literature_correlation_by_list(
`web.webqtl.correlation.CorrelationPage.getLiteratureCorrelationByList`
function in GeneNetwork1.
"""
- if any((lambda t: (
- bool(t.get("tissue_corr")) and
- bool(t.get("tissue_p_value"))))(trait)
+ if any(bool(trait.get("tissue_corr")) and bool(trait.get("tissue_p_value"))
for trait in trait_list):
temporary_table_name = f"LITERATURE{random_string(8)}"
query1 = (
@@ -491,7 +489,7 @@ def tissue_correlation_by_list(
"tissue_p_value": result["p-val"]
}
- if any((lambda t: bool(t.get("l_corr")))(trait) for trait in trait_list):
+ if any(bool(trait.get("l_corr")) for trait in trait_list):
prim_trait_symbol_value_dict = fetch_gene_symbol_tissue_value_dict_for_trait(
(primary_trait_symbol,), tissue_probeset_freeze_id, conn)
if primary_trait_symbol.lower() in prim_trait_symbol_value_dict:
diff --git a/gn3/db/partial_correlations.py b/gn3/db/partial_correlations.py
index e8466f6..1368da0 100644
--- a/gn3/db/partial_correlations.py
+++ b/gn3/db/partial_correlations.py
@@ -422,8 +422,7 @@ def set_bxd(group_info):
return {
**group_info,
"group": (
- "BXD" if group_info.get("Name") == "BXD300"
- else group_info.get("Name", "")),
+ "BXD" if group_info.get("Name") == "BXD300" else group_info.get("Name", "")),
"groupid": group_info["Id"]
}
diff --git a/tests/unit/auth/test_groups.py b/tests/unit/auth/test_groups.py
index 4824e14..d3b8fd4 100644
--- a/tests/unit/auth/test_groups.py
+++ b/tests/unit/auth/test_groups.py
@@ -19,7 +19,10 @@ create_group_failure = {
"message": "Unauthorised: Failed to create group."
}
-uuid_fn = lambda : UUID("d32611e3-07fc-4564-b56c-786c6db6de2b")
+def uuid_fn():
+ """Mock function for uuid"""
+ return UUID("d32611e3-07fc-4564-b56c-786c6db6de2b")
+
GROUP = Group(UUID("9988c21d-f02f-4d45-8966-22c968ac2fbf"), "TheTestGroup",
{"group_description": "The test group"})
diff --git a/tests/unit/auth/test_privileges.py b/tests/unit/auth/test_privileges.py
index 8395293..3c645c7 100644
--- a/tests/unit/auth/test_privileges.py
+++ b/tests/unit/auth/test_privileges.py
@@ -6,7 +6,6 @@ from gn3.auth.authorisation.privileges import Privilege, user_privileges
from tests.unit.auth import conftest
-SORT_KEY = lambda x: x.privilege_id
PRIVILEGES = sorted(
(Privilege("system:group:create-group", "Create a group"),
@@ -29,7 +28,7 @@ PRIVILEGES = sorted(
Privilege("group:role:edit-role", "edit/update an existing role"),
Privilege("group:user:assign-role", "Assign a role to an existing user"),
Privilege("group:role:delete-role", "Delete an existing role")),
- key=SORT_KEY)
+ key=lambda x: x.privilege_id)
@pytest.mark.unit_test
@pytest.mark.parametrize(
@@ -43,4 +42,4 @@ def test_user_privileges(auth_testdb_path, fxtr_users, user, expected):# pylint:
"""
with db.connection(auth_testdb_path) as conn:
assert sorted(
- user_privileges(conn, user), key=SORT_KEY) == expected
+ user_privileges(conn, user), key=lambda x: x.privilege_id) == expected
diff --git a/tests/unit/auth/test_resources.py b/tests/unit/auth/test_resources.py
index 2884add..7b9798a 100644
--- a/tests/unit/auth/test_resources.py
+++ b/tests/unit/auth/test_resources.py
@@ -21,7 +21,12 @@ create_resource_failure = {
"status": "error",
"message": "Unauthorised: Could not create resource"
}
-uuid_fn = lambda : uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b")
+
+
+def uuid_fn():
+ """Mock function for uuid"""
+ return uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b")
+
@pytest.mark.unit_test
@pytest.mark.parametrize(
@@ -71,7 +76,6 @@ def test_create_resource_raises_for_unauthorised_users(
assert create_resource(
conn, "test_resource", resource_category, user, False) == expected
-SORTKEY = lambda resource: resource.resource_id
@pytest.mark.unit_test
def test_public_resources(fxtr_resources):
@@ -81,12 +85,16 @@ def test_public_resources(fxtr_resources):
THEN: only list the resources that are public
"""
conn, _res = fxtr_resources
- assert sorted(public_resources(conn), key=SORTKEY) == sorted(tuple(
- res for res in conftest.TEST_RESOURCES if res.public), key=SORTKEY)
+ assert sorted(
+ public_resources(conn),
+ key=lambda resource: resource.resource_id) == sorted(tuple(
+ res for res in
+ conftest.TEST_RESOURCES
+ if res.public), key=lambda resource: resource.resource_id)
PUBLIC_RESOURCES = sorted(
{res.resource_id: res for res in conftest.TEST_RESOURCES_PUBLIC}.values(),
- key=SORTKEY)
+ key=lambda resource: resource.resource_id)
@pytest.mark.unit_test
@pytest.mark.parametrize(
@@ -97,13 +105,12 @@ PUBLIC_RESOURCES = sorted(
{res.resource_id: res for res in
(conftest.TEST_RESOURCES_GROUP_01 +
conftest.TEST_RESOURCES_PUBLIC)}.values(),
- key=SORTKEY),
+ key=lambda resource: resource.resource_id),
sorted(
{res.resource_id: res for res in
((conftest.TEST_RESOURCES_GROUP_01[1],) +
conftest.TEST_RESOURCES_PUBLIC)}.values()
- ,
- key=SORTKEY),
+ , key=lambda resource: resource.resource_id),
PUBLIC_RESOURCES, PUBLIC_RESOURCES))))
def test_user_resources(fxtr_group_user_roles, user, expected):
"""
@@ -114,4 +121,4 @@ def test_user_resources(fxtr_group_user_roles, user, expected):
conn, *_others = fxtr_group_user_roles
assert sorted(
{res.resource_id: res for res in user_resources(conn, user)
- }.values(), key=SORTKEY) == expected
+ }.values(), key=lambda resource: resource.resource_id) == expected
diff --git a/tests/unit/auth/test_roles.py b/tests/unit/auth/test_roles.py
index 02fd9f7..8e22bb5 100644
--- a/tests/unit/auth/test_roles.py
+++ b/tests/unit/auth/test_roles.py
@@ -16,7 +16,11 @@ create_role_failure = {
"message": "Unauthorised: Could not create role"
}
-uuid_fn = lambda : uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b")
+
+def uuid_fn():
+ """Mock function for uuid"""
+ return uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b")
+
PRIVILEGES = (
Privilege("group:resource:view-resource",