From 6494836db6aa01cef1c284b2863d9368dd6c0d2b Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Fri, 27 Jan 2023 16:37:28 +0100 Subject: [PATCH] Formatting changes after switching to "ruff" for linting --- .pre-commit-config.yaml | 2 +- src/sensospot_tools/__init__.py | 2 +- src/sensospot_tools/hdr.py | 5 +++-- src/sensospot_tools/helpers.py | 3 ++- tests/test_hdr.py | 18 +++++++++--------- tests/test_helpers.py | 4 +--- tests/test_selection.py | 4 ++-- tests/test_sensospot_tools.py | 10 ++++++---- 8 files changed, 25 insertions(+), 23 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8a2cd5a..a4437d0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,7 +22,7 @@ repos: language: system pass_filenames: false - id: pytest - name: pytest + name: Testing the project with "pytest" entry: pytest tests language: system pass_filenames: false diff --git a/src/sensospot_tools/__init__.py b/src/sensospot_tools/__init__.py index 7ab193b..e9c9b2e 100644 --- a/src/sensospot_tools/__init__.py +++ b/src/sensospot_tools/__init__.py @@ -6,4 +6,4 @@ Some small tools for working with parsed Sensospot data. __version__ = "0.1.1" from .hdr import normalize, select_hdr_data # noqa: F401 -from .selection import split, select # noqa: F401 +from .selection import select, split # noqa: F401 diff --git a/src/sensospot_tools/hdr.py b/src/sensospot_tools/hdr.py index bc29686..32e1a3e 100644 --- a/src/sensospot_tools/hdr.py +++ b/src/sensospot_tools/hdr.py @@ -2,7 +2,7 @@ from typing import Union import pandas -from .helpers import ensure_list, check_columns_exist +from .helpers import check_columns_exist, ensure_list from .selection import select @@ -95,7 +95,8 @@ def normalize( """ check_columns_exist(data, time_column, value_columns) if template == template.format("a"): - raise ValueError(f"Not a template string: '{template}'") + msg = f"Not a template string: '{template}'" + raise ValueError(msg) data = data.copy() diff --git a/src/sensospot_tools/helpers.py b/src/sensospot_tools/helpers.py index 623e6e3..609bad2 100644 --- a/src/sensospot_tools/helpers.py +++ b/src/sensospot_tools/helpers.py @@ -54,6 +54,7 @@ def check_columns_exist(data: pandas.DataFrame, *arguments) -> bool: if not check_cols.issubset(set(data.columns)): unknown_columns = sorted(check_cols.difference(set(data.columns))) - raise KeyError(f"Unknown column(s): {unknown_columns}") + msg = f"Unknown column(s): {unknown_columns}" + raise KeyError(msg) return True diff --git a/tests/test_hdr.py b/tests/test_hdr.py index 853e149..bcc2e37 100644 --- a/tests/test_hdr.py +++ b/tests/test_hdr.py @@ -49,24 +49,24 @@ def csv_to_data_frame(text): return pandas.read_csv(buffer, sep="\t") -@pytest.fixture +@pytest.fixture() def full_source_data(): - yield csv_to_data_frame(CSV_FULL_DATA) + return csv_to_data_frame(CSV_FULL_DATA) -@pytest.fixture +@pytest.fixture() def one_time_source_data(): - yield csv_to_data_frame(CSV_ONE_TIME_DATA) + return csv_to_data_frame(CSV_ONE_TIME_DATA) -@pytest.fixture +@pytest.fixture() def hdr_data(): - yield csv_to_data_frame(CSV_HDR_DATA) + return csv_to_data_frame(CSV_HDR_DATA) -@pytest.fixture +@pytest.fixture() def hdr_normalized_data(): - yield csv_to_data_frame(CSV_HDR_DATA) + return csv_to_data_frame(CSV_HDR_DATA) def test_select_hdr_data_full_data(full_source_data, hdr_data): @@ -141,7 +141,7 @@ def test_normalize_raises_error_on_wrong_column(hdr_data): def test_normalize_raises_error_no_templae_string(hdr_data): from sensospot_tools.hdr import normalize - with pytest.raises(ValueError): + with pytest.raises(ValueError): # noqa: PT011 normalize( hdr_data, normalized_time=200, diff --git a/tests/test_helpers.py b/tests/test_helpers.py index c280f98..58cb84c 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -2,7 +2,7 @@ import pytest @pytest.mark.parametrize( - "provided, expected", + ("provided", "expected"), [ ("abc", ["abc"]), (tuple("abc"), ["a", "b", "c"]), @@ -29,7 +29,6 @@ def test_helpers_ensure_list(provided, expected): ) def test_helpers_check_columns_exist_ok(arguments): import pandas - from sensospot_tools.helpers import check_columns_exist columns = ["A", "B", "C", "D"] @@ -40,7 +39,6 @@ def test_helpers_check_columns_exist_ok(arguments): def test_helpers_check_columns_exist_raises_error_on_wrong_column(): import pandas - from sensospot_tools.helpers import check_columns_exist columns = ["A", "B", "C", "D"] diff --git a/tests/test_selection.py b/tests/test_selection.py index c1c8aec..08897a5 100644 --- a/tests/test_selection.py +++ b/tests/test_selection.py @@ -10,14 +10,14 @@ horse 9 """ -@pytest.fixture +@pytest.fixture() def example(): import io import pandas buffer = io.StringIO(CSV_DATA.strip()) - yield pandas.read_csv(buffer, sep="\t") + return pandas.read_csv(buffer, sep="\t") def test_selection_select(example): diff --git a/tests/test_sensospot_tools.py b/tests/test_sensospot_tools.py index 1849345..18f021c 100644 --- a/tests/test_sensospot_tools.py +++ b/tests/test_sensospot_tools.py @@ -1,6 +1,8 @@ def test_api(): """test if the provided functionality is importable""" - from sensospot_tools import split # noqa: F401 - from sensospot_tools import select # noqa: F401 - from sensospot_tools import normalize # noqa: F401 - from sensospot_tools import select_hdr_data # noqa: F401 + from sensospot_tools import ( + normalize, # noqa: F401 + select, # noqa: F401 + select_hdr_data, # noqa: F401 + split, # noqa: F401 + )