""" Stub file for testing the project """ from pathlib import Path import numpy import pytest EXAMPLE_DIR_WO_PARAMS = "mtp_wo_parameters" EXAMPLE_DIR_WITH_PARAMS = "mtp_with_parameters" @pytest.fixture def example_dir(request): root_dir = Path(request.config.rootdir) yield root_dir / "example_data" @pytest.fixture def example_file(example_dir): data_dir = example_dir / EXAMPLE_DIR_WO_PARAMS yield data_dir / "160210_SG2-010-001_Regen_cy3100_1_A1_1.csv" @pytest.mark.parametrize( "sub_dir,file_name", [ ( EXAMPLE_DIR_WO_PARAMS, "160218_SG2-013-001_Regen1_Cy3-100_1_A1_1.csv", ), ( EXAMPLE_DIR_WITH_PARAMS, "160210_SG2-010-001_Regen_cy3100_1_A1_1.csv", ), ], ) def test_parse_csv(example_dir, sub_dir, file_name): from sensovation_data_parser import _parse_csv result = _parse_csv(example_dir / sub_dir / file_name) columns = { " ID ": numpy.int64, "Pos.X": numpy.int64, "Pos.Y": numpy.int64, "Bkg.Mean": float, "Spot.Mean": float, "Bkg.Median": float, "Spot.Median": float, "Bkg.StdDev": float, "Spot.StdDev": float, "Bkg.Sum": numpy.int64, "Spot.Sum": numpy.int64, "Bkg.Area": numpy.int64, "Spot.Area": numpy.int64, "Spot.Sat. (%)": numpy.int64, "Found": numpy.bool_, "Pos.Nom.X": numpy.int64, "Pos.Nom.Y": numpy.int64, "Dia.": numpy.int64, "Rect.": str, "Contour": object, # ignore the type of contour } assert set(result.columns) == set(columns.keys()) assert len(result[" ID "].unique()) == 100 assert len(result) == 100 for column, value_type in columns.items(): assert isinstance(result[column][0], value_type) @pytest.mark.parametrize( "input,expected", [("", "."), ("..,", "."), (".,,", ","), ("..,,", "."),] ) def test_guess_decimal_separator_returns_correct_separator(input, expected): from sensovation_data_parser import _guess_decimal_separator from io import StringIO handle = StringIO(f"header\n{input}\n") result = _guess_decimal_separator(handle) assert result == expected def test_guess_decimal_separator_rewinds_handle(): from sensovation_data_parser import _guess_decimal_separator from io import StringIO handle = StringIO(f"header\n{input}\n") _guess_decimal_separator(handle) assert next(handle) == "header\n"