From c6ac30d4ccc26553a12e8c37cdf9078cbe9084b3 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 10 Jul 2023 11:36:47 +0300 Subject: Fix linting errors caused by bump to Python 3.10 --- tests/unit/auth/test_groups.py | 4 +++- tests/unit/auth/test_privileges.py | 8 +++++--- tests/unit/auth/test_resources.py | 20 ++++++++++++-------- tests/unit/auth/test_roles.py | 4 +++- tests/unit/computations/test_partial_correlations.py | 2 +- tests/unit/db/test_case_attributes.py | 8 +++++--- tests/unit/db/test_db.py | 1 - tests/unit/test_heatmaps.py | 2 +- 8 files changed, 30 insertions(+), 19 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/auth/test_groups.py b/tests/unit/auth/test_groups.py index 4824e14..bd62405 100644 --- a/tests/unit/auth/test_groups.py +++ b/tests/unit/auth/test_groups.py @@ -19,7 +19,9 @@ create_group_failure = { "message": "Unauthorised: Failed to create group." } -uuid_fn = lambda : UUID("d32611e3-07fc-4564-b56c-786c6db6de2b") +def uuid_fn(): + """Return a specific 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..4894dfc 100644 --- a/tests/unit/auth/test_privileges.py +++ b/tests/unit/auth/test_privileges.py @@ -6,7 +6,9 @@ from gn3.auth.authorisation.privileges import Privilege, user_privileges from tests.unit.auth import conftest -SORT_KEY = lambda x: x.privilege_id +def sort_key(priv): + """Return the key to sort by""" + return priv.privilege_id PRIVILEGES = sorted( (Privilege("system:group:create-group", "Create a group"), @@ -29,7 +31,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=sort_key) @pytest.mark.unit_test @pytest.mark.parametrize( @@ -43,4 +45,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=sort_key) == expected diff --git a/tests/unit/auth/test_resources.py b/tests/unit/auth/test_resources.py index 2884add..a16dcb1 100644 --- a/tests/unit/auth/test_resources.py +++ b/tests/unit/auth/test_resources.py @@ -21,7 +21,9 @@ create_resource_failure = { "status": "error", "message": "Unauthorised: Could not create resource" } -uuid_fn = lambda : uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b") +def uuid_fn(): + """UUID function for tests.""" + return uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b") @pytest.mark.unit_test @pytest.mark.parametrize( @@ -71,7 +73,9 @@ 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 +def sort_key(resource): + """Return the sort key for resources.""" + return resource.resource_id @pytest.mark.unit_test def test_public_resources(fxtr_resources): @@ -81,12 +85,12 @@ 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=sort_key) == sorted(tuple( + res for res in conftest.TEST_RESOURCES if res.public), key=sort_key) PUBLIC_RESOURCES = sorted( {res.resource_id: res for res in conftest.TEST_RESOURCES_PUBLIC}.values(), - key=SORTKEY) + key=sort_key) @pytest.mark.unit_test @pytest.mark.parametrize( @@ -97,13 +101,13 @@ PUBLIC_RESOURCES = sorted( {res.resource_id: res for res in (conftest.TEST_RESOURCES_GROUP_01 + conftest.TEST_RESOURCES_PUBLIC)}.values(), - key=SORTKEY), + key=sort_key), sorted( {res.resource_id: res for res in ((conftest.TEST_RESOURCES_GROUP_01[1],) + conftest.TEST_RESOURCES_PUBLIC)}.values() , - key=SORTKEY), + key=sort_key), PUBLIC_RESOURCES, PUBLIC_RESOURCES)))) def test_user_resources(fxtr_group_user_roles, user, expected): """ @@ -114,4 +118,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=sort_key) == expected diff --git a/tests/unit/auth/test_roles.py b/tests/unit/auth/test_roles.py index 02fd9f7..3bb84a3 100644 --- a/tests/unit/auth/test_roles.py +++ b/tests/unit/auth/test_roles.py @@ -16,7 +16,9 @@ create_role_failure = { "message": "Unauthorised: Could not create role" } -uuid_fn = lambda : uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b") +def uuid_fn(): + """UUID function for tests""" + return uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b") PRIVILEGES = ( Privilege("group:resource:view-resource", diff --git a/tests/unit/computations/test_partial_correlations.py b/tests/unit/computations/test_partial_correlations.py index 20cd6bc..066c650 100644 --- a/tests/unit/computations/test_partial_correlations.py +++ b/tests/unit/computations/test_partial_correlations.py @@ -234,7 +234,7 @@ class TestPartialCorrelations(TestCase): tissue_correlation(primary, target, method) @pytest.mark.unit_test - def test_tissue_correlation(self): # pylint: disable=R0201 + def test_tissue_correlation(self): """ Test that the correct correlation values are computed for the given: - primary trait diff --git a/tests/unit/db/test_case_attributes.py b/tests/unit/db/test_case_attributes.py index 175249b..596f78a 100644 --- a/tests/unit/db/test_case_attributes.py +++ b/tests/unit/db/test_case_attributes.py @@ -140,7 +140,7 @@ def test_approve_deleting_case_attribute(mocker: MockFixture) -> None: "WHERE id = %s", (3,), ), - mocker.call("DELETE FROM CaseAttribute " "WHERE Id = %s", ("12",)), + mocker.call("DELETE FROM CaseAttribute WHERE Id = %s", ("12",)), mocker.call( "UPDATE caseattributes_audit SET " "status = 'approved' WHERE id = %s", @@ -183,14 +183,16 @@ def test_approve_modifying_case_attribute(mocker: MockFixture) -> None: (3,), ), mocker.call( - "UPDATE CaseAttribute SET " "Description = %s WHERE Id = %s", + "UPDATE CaseAttribute SET " + "Description = %s WHERE Id = %s", ( "Test", "12", ), ), mocker.call( - "UPDATE CaseAttribute SET " "Name = %s WHERE Id = %s", + "UPDATE CaseAttribute SET " + "Name = %s WHERE Id = %s", ( "Height (A)", "12", diff --git a/tests/unit/db/test_db.py b/tests/unit/db/test_db.py index 8ac468c..2b4151c 100644 --- a/tests/unit/db/test_db.py +++ b/tests/unit/db/test_db.py @@ -103,7 +103,6 @@ class TestCrudMethods(TestCase): (35, 'Rob')) @pytest.mark.unit_test - # pylint: disable=R0201 def test_probeset_called_with_right_columns(self): """Given a columns argument, test that the correct sql query is constructed""" diff --git a/tests/unit/test_heatmaps.py b/tests/unit/test_heatmaps.py index 8781d6f..3d4fc78 100644 --- a/tests/unit/test_heatmaps.py +++ b/tests/unit/test_heatmaps.py @@ -29,7 +29,7 @@ class TestHeatmap(TestCase): """Class for testing heatmap computation functions""" @pytest.mark.unit_test - def test_cluster_traits(self): # pylint: disable=R0201 + def test_cluster_traits(self): """ Test that the clustering is working as expected. """ -- cgit v1.2.3