diff --git a/src/sensospot_parser/__init__.py b/src/sensospot_parser/__init__.py index 8124da2..8450620 100644 --- a/src/sensospot_parser/__init__.py +++ b/src/sensospot_parser/__init__.py @@ -12,7 +12,7 @@ import click import pandas from . import columns # noqa: F401 -from .parser import parse_file, parse_folder # noqa: F401 +from .csv_parser import parse_file, parse_folder # noqa: F401 DEFAULT_OUTPUT_FILENAME = "collected_data.csv" diff --git a/src/sensospot_parser/parser.py b/src/sensospot_parser/csv_parser.py similarity index 100% rename from src/sensospot_parser/parser.py rename to src/sensospot_parser/csv_parser.py diff --git a/tests/test_parser.py b/tests/test_csv_parser.py similarity index 86% rename from tests/test_parser.py rename to tests/test_csv_parser.py index c9659b1..4ab9480 100644 --- a/tests/test_parser.py +++ b/tests/test_csv_parser.py @@ -25,7 +25,7 @@ from .conftest import ( ], ) def test_parse_csv(example_dir, sub_dir, file_name): - from sensospot_parser.parser import _parse_csv + from sensospot_parser.csv_parser import _parse_csv result = _parse_csv(example_dir / sub_dir / file_name) @@ -60,7 +60,7 @@ def test_parse_csv(example_dir, sub_dir, file_name): def test_parse_csv_no_array(example_dir): - from sensospot_parser.parser import _parse_csv + from sensospot_parser.csv_parser import _parse_csv result = _parse_csv(example_dir / "no_array_A1_1.csv") @@ -74,7 +74,7 @@ def test_parse_csv_no_array(example_dir): def test_guess_decimal_separator_returns_correct_separator(input, expected): from io import StringIO - from sensospot_parser.parser import _guess_decimal_separator + from sensospot_parser.csv_parser import _guess_decimal_separator handle = StringIO(f"header\n{input}\n") result = _guess_decimal_separator(handle) @@ -85,7 +85,7 @@ def test_guess_decimal_separator_returns_correct_separator(input, expected): def test_guess_decimal_separator_rewinds_handle(): from io import StringIO - from sensospot_parser.parser import _guess_decimal_separator + from sensospot_parser.csv_parser import _guess_decimal_separator handle = StringIO("\n".join(["header", "data_line"])) _guess_decimal_separator(handle) @@ -94,7 +94,7 @@ def test_guess_decimal_separator_rewinds_handle(): def test_well_regex_ok(): - from sensospot_parser.parser import REGEX_WELL + from sensospot_parser.csv_parser import REGEX_WELL result = REGEX_WELL.match("AbC123") @@ -104,7 +104,7 @@ def test_well_regex_ok(): @pytest.mark.parametrize("input", ["", "A", "1", "1A", "-1", "A-"]) def test_well_regex_no_match(input): - from sensospot_parser.parser import REGEX_WELL + from sensospot_parser.csv_parser import REGEX_WELL result = REGEX_WELL.match(input) @@ -116,7 +116,7 @@ def test_well_regex_no_match(input): [("A1_1.csv", ("A", 1, 1)), ("test/measurement_1_H12_2", ("H", 12, 2))], ) def test_extract_measurement_info_ok(filename, expected): - from sensospot_parser.parser import _extract_measurement_info + from sensospot_parser.csv_parser import _extract_measurement_info result = _extract_measurement_info(filename) @@ -125,7 +125,7 @@ def test_extract_measurement_info_ok(filename, expected): @pytest.mark.parametrize("filename", ["wrong_exposure_A1_B", "no_well_XX_1"]) def test_extract_measurement_info_raises_error(filename): - from sensospot_parser.parser import _extract_measurement_info + from sensospot_parser.csv_parser import _extract_measurement_info with pytest.raises(ValueError): _extract_measurement_info(filename) @@ -134,7 +134,7 @@ def test_extract_measurement_info_raises_error(filename): def test_cleanup_data_columns(): from pandas import DataFrame - from sensospot_parser.parser import _cleanup_data_columns + from sensospot_parser.csv_parser import _cleanup_data_columns columns = ["Rect.", "Contour", " ID ", "Found", "Dia."] data = {col: [i] for i, col in enumerate(columns)} @@ -149,7 +149,7 @@ def test_cleanup_data_columns(): def test_parse_file(example_file): - from sensospot_parser.parser import parse_file + from sensospot_parser.csv_parser import parse_file result = parse_file(example_file) @@ -191,7 +191,7 @@ def test_parse_file(example_file): def test_parse_file_raises_error(example_dir): - from sensospot_parser.parser import parse_file + from sensospot_parser.csv_parser import parse_file csv_file = ( example_dir / EXAMPLE_DIR_WITH_PARAMS / "should_raise_value_error.csv" @@ -202,7 +202,7 @@ def test_parse_file_raises_error(example_dir): def test_parse_file_silenced_returns_data_frame(example_file): - from sensospot_parser.parser import _parse_file_silenced + from sensospot_parser.csv_parser import _parse_file_silenced result = _parse_file_silenced(example_file) @@ -212,7 +212,7 @@ def test_parse_file_silenced_returns_data_frame(example_file): def test_parse_file_silenced_returns_none_on_error(example_dir): - from sensospot_parser.parser import _parse_file_silenced + from sensospot_parser.csv_parser import _parse_file_silenced csv_file = ( example_dir / EXAMPLE_DIR_WITH_PARAMS / "should_raise_value_error.csv" @@ -234,7 +234,7 @@ def test_parse_file_silenced_returns_none_on_error(example_dir): ], ) def testparse_multiple_files_ok(example_dir, file_list): - from sensospot_parser.parser import parse_multiple_files + from sensospot_parser.csv_parser import parse_multiple_files sub_dir = example_dir / EXAMPLE_DIR_WO_PARAMS files = [sub_dir / file for file in file_list] @@ -247,14 +247,14 @@ def testparse_multiple_files_ok(example_dir, file_list): def testparse_multiple_files_empty_file_list(): - from sensospot_parser.parser import parse_multiple_files + from sensospot_parser.csv_parser import parse_multiple_files with pytest.raises(ValueError): parse_multiple_files([]) def testparse_multiple_files_empty_array(example_dir): - from sensospot_parser.parser import parse_multiple_files + from sensospot_parser.csv_parser import parse_multiple_files files = [example_dir / "no_array_A1_1.csv"] @@ -265,7 +265,7 @@ def testparse_multiple_files_empty_array(example_dir): def test_find_csv_files(example_dir): - from sensospot_parser.parser import find_csv_files + from sensospot_parser.csv_parser import find_csv_files result = list(find_csv_files(example_dir / EXAMPLE_DIR_WITH_PARAMS)) @@ -275,7 +275,7 @@ def test_find_csv_files(example_dir): def test_parse_folder_no_datetime_records(example_dir): - from sensospot_parser.parser import parse_folder + from sensospot_parser.csv_parser import parse_folder data_frame = parse_folder(example_dir / EXAMPLE_DIR_WITH_PARAMS) @@ -290,7 +290,7 @@ def test_parse_folder_no_datetime_records(example_dir): def test_parse_folder_with_datetime_records(example_dir): - from sensospot_parser.parser import parse_folder + from sensospot_parser.csv_parser import parse_folder data_frame = parse_folder(example_dir / EXAMPLE_DIR_WITH_RECORD) @@ -305,7 +305,7 @@ def test_parse_folder_with_datetime_records(example_dir): def test_sanity_check_ok(example_dir): - from sensospot_parser.parser import _sanity_check, parse_multiple_files + from sensospot_parser.csv_parser import _sanity_check, parse_multiple_files sub_dir = example_dir / EXAMPLE_DIR_WO_PARAMS file_list = [ @@ -321,7 +321,7 @@ def test_sanity_check_ok(example_dir): def test_sanity_check_raises_value_error(example_dir): - from sensospot_parser.parser import _sanity_check, parse_multiple_files + from sensospot_parser.csv_parser import _sanity_check, parse_multiple_files sub_dir = example_dir / EXAMPLE_DIR_WO_PARAMS file_list = [