Browse Source

Formatting changes after switching to "ruff" for linting

main
Holger Frey 2 years ago
parent
commit
6494836db6
  1. 2
      .pre-commit-config.yaml
  2. 2
      src/sensospot_tools/__init__.py
  3. 5
      src/sensospot_tools/hdr.py
  4. 3
      src/sensospot_tools/helpers.py
  5. 18
      tests/test_hdr.py
  6. 4
      tests/test_helpers.py
  7. 4
      tests/test_selection.py
  8. 10
      tests/test_sensospot_tools.py

2
.pre-commit-config.yaml

@ -22,7 +22,7 @@ repos:
language: system language: system
pass_filenames: false pass_filenames: false
- id: pytest - id: pytest
name: pytest name: Testing the project with "pytest"
entry: pytest tests entry: pytest tests
language: system language: system
pass_filenames: false pass_filenames: false

2
src/sensospot_tools/__init__.py

@ -6,4 +6,4 @@ Some small tools for working with parsed Sensospot data.
__version__ = "0.1.1" __version__ = "0.1.1"
from .hdr import normalize, select_hdr_data # noqa: F401 from .hdr import normalize, select_hdr_data # noqa: F401
from .selection import split, select # noqa: F401 from .selection import select, split # noqa: F401

5
src/sensospot_tools/hdr.py

@ -2,7 +2,7 @@ from typing import Union
import pandas import pandas
from .helpers import ensure_list, check_columns_exist from .helpers import check_columns_exist, ensure_list
from .selection import select from .selection import select
@ -95,7 +95,8 @@ def normalize(
""" """
check_columns_exist(data, time_column, value_columns) check_columns_exist(data, time_column, value_columns)
if template == template.format("a"): 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() data = data.copy()

3
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)): if not check_cols.issubset(set(data.columns)):
unknown_columns = sorted(check_cols.difference(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 return True

18
tests/test_hdr.py

@ -49,24 +49,24 @@ def csv_to_data_frame(text):
return pandas.read_csv(buffer, sep="\t") return pandas.read_csv(buffer, sep="\t")
@pytest.fixture @pytest.fixture()
def full_source_data(): 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(): 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(): 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(): 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): 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): def test_normalize_raises_error_no_templae_string(hdr_data):
from sensospot_tools.hdr import normalize from sensospot_tools.hdr import normalize
with pytest.raises(ValueError): with pytest.raises(ValueError): # noqa: PT011
normalize( normalize(
hdr_data, hdr_data,
normalized_time=200, normalized_time=200,

4
tests/test_helpers.py

@ -2,7 +2,7 @@ import pytest
@pytest.mark.parametrize( @pytest.mark.parametrize(
"provided, expected", ("provided", "expected"),
[ [
("abc", ["abc"]), ("abc", ["abc"]),
(tuple("abc"), ["a", "b", "c"]), (tuple("abc"), ["a", "b", "c"]),
@ -29,7 +29,6 @@ def test_helpers_ensure_list(provided, expected):
) )
def test_helpers_check_columns_exist_ok(arguments): def test_helpers_check_columns_exist_ok(arguments):
import pandas import pandas
from sensospot_tools.helpers import check_columns_exist from sensospot_tools.helpers import check_columns_exist
columns = ["A", "B", "C", "D"] 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(): def test_helpers_check_columns_exist_raises_error_on_wrong_column():
import pandas import pandas
from sensospot_tools.helpers import check_columns_exist from sensospot_tools.helpers import check_columns_exist
columns = ["A", "B", "C", "D"] columns = ["A", "B", "C", "D"]

4
tests/test_selection.py

@ -10,14 +10,14 @@ horse 9
""" """
@pytest.fixture @pytest.fixture()
def example(): def example():
import io import io
import pandas import pandas
buffer = io.StringIO(CSV_DATA.strip()) 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): def test_selection_select(example):

10
tests/test_sensospot_tools.py

@ -1,6 +1,8 @@
def test_api(): def test_api():
"""test if the provided functionality is importable""" """test if the provided functionality is importable"""
from sensospot_tools import split # noqa: F401 from sensospot_tools import (
from sensospot_tools import select # noqa: F401 normalize, # noqa: F401
from sensospot_tools import normalize # noqa: F401 select, # noqa: F401
from sensospot_tools import select_hdr_data # noqa: F401 select_hdr_data, # noqa: F401
split, # noqa: F401
)

Loading…
Cancel
Save