From a35fce27875d9db80dce1976b6f8ee8c00ecfe0a Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 21 Feb 2022 16:23:06 +0300 Subject: Fix a myriad of linter issues * Use `with` in place of plain `open` * Use f-strings in place of `str.format()` * Remove string interpolation from queries - provide data as query parameters * other minor fixes --- tests/unit/db/test_datasets.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'tests/unit/db') diff --git a/tests/unit/db/test_datasets.py b/tests/unit/db/test_datasets.py index 0b24489..e4abd2f 100644 --- a/tests/unit/db/test_datasets.py +++ b/tests/unit/db/test_datasets.py @@ -15,14 +15,14 @@ class TestDatasetsDBFunctions(TestCase): @pytest.mark.unit_test def test_retrieve_dataset_name(self): """Test that the function is called correctly.""" - for trait_type, thresh, trait_name, dataset_name, columns, table, expected in [ - ["ProbeSet", 9, "probesetTraitName", "probesetDatasetName", + for trait_type, thresh, dataset_name, columns, table, expected in [ + ["ProbeSet", 9, "probesetDatasetName", "Id, Name, FullName, ShortName, DataScale", "ProbeSetFreeze", {"dataset_id": None, "dataset_name": "probesetDatasetName", "dataset_fullname": "probesetDatasetName"}], - ["Geno", 3, "genoTraitName", "genoDatasetName", + ["Geno", 3, "genoDatasetName", "Id, Name, FullName, ShortName", "GenoFreeze", {}], - ["Publish", 6, "publishTraitName", "publishDatasetName", + ["Publish", 6, "publishDatasetName", "Id, Name, FullName, ShortName", "PublishFreeze", {}]]: db_mock = mock.MagicMock() with self.subTest(trait_type=trait_type): @@ -30,16 +30,15 @@ class TestDatasetsDBFunctions(TestCase): cursor.fetchone.return_value = {} self.assertEqual( retrieve_dataset_name( - trait_type, thresh, trait_name, dataset_name, db_mock), + trait_type, thresh, dataset_name, db_mock), expected) cursor.execute.assert_called_once_with( - "SELECT {cols} " - "FROM {table} " + f"SELECT {columns} " + f"FROM {table} " "WHERE public > %(threshold)s AND " "(Name = %(name)s " "OR FullName = %(name)s " - "OR ShortName = %(name)s)".format( - table=table, cols=columns), + "OR ShortName = %(name)s)", {"threshold": thresh, "name": dataset_name}) @pytest.mark.unit_test -- cgit v1.2.3