|
|
@ -21,7 +21,7 @@ from .conftest import EXAMPLE_DIR_WO_PARAMS, EXAMPLE_DIR_WITH_PARAMS |
|
|
|
], |
|
|
|
], |
|
|
|
) |
|
|
|
) |
|
|
|
def test_parse_csv(example_dir, sub_dir, file_name): |
|
|
|
def test_parse_csv(example_dir, sub_dir, file_name): |
|
|
|
from sensospot_data.parser import _parse_csv |
|
|
|
from sensospot_parser.parser import _parse_csv |
|
|
|
|
|
|
|
|
|
|
|
result = _parse_csv(example_dir / sub_dir / file_name) |
|
|
|
result = _parse_csv(example_dir / sub_dir / file_name) |
|
|
|
|
|
|
|
|
|
|
@ -56,7 +56,7 @@ def test_parse_csv(example_dir, sub_dir, file_name): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_csv_no_array(example_dir): |
|
|
|
def test_parse_csv_no_array(example_dir): |
|
|
|
from sensospot_data.parser import _parse_csv |
|
|
|
from sensospot_parser.parser import _parse_csv |
|
|
|
|
|
|
|
|
|
|
|
result = _parse_csv(example_dir / "no_array_A1_1.csv") |
|
|
|
result = _parse_csv(example_dir / "no_array_A1_1.csv") |
|
|
|
|
|
|
|
|
|
|
@ -70,7 +70,7 @@ def test_parse_csv_no_array(example_dir): |
|
|
|
def test_guess_decimal_separator_returns_correct_separator(input, expected): |
|
|
|
def test_guess_decimal_separator_returns_correct_separator(input, expected): |
|
|
|
from io import StringIO |
|
|
|
from io import StringIO |
|
|
|
|
|
|
|
|
|
|
|
from sensospot_data.parser import _guess_decimal_separator |
|
|
|
from sensospot_parser.parser import _guess_decimal_separator |
|
|
|
|
|
|
|
|
|
|
|
handle = StringIO(f"header\n{input}\n") |
|
|
|
handle = StringIO(f"header\n{input}\n") |
|
|
|
result = _guess_decimal_separator(handle) |
|
|
|
result = _guess_decimal_separator(handle) |
|
|
@ -81,7 +81,7 @@ def test_guess_decimal_separator_returns_correct_separator(input, expected): |
|
|
|
def test_guess_decimal_separator_rewinds_handle(): |
|
|
|
def test_guess_decimal_separator_rewinds_handle(): |
|
|
|
from io import StringIO |
|
|
|
from io import StringIO |
|
|
|
|
|
|
|
|
|
|
|
from sensospot_data.parser import _guess_decimal_separator |
|
|
|
from sensospot_parser.parser import _guess_decimal_separator |
|
|
|
|
|
|
|
|
|
|
|
handle = StringIO("\n".join(["header", "data_line"])) |
|
|
|
handle = StringIO("\n".join(["header", "data_line"])) |
|
|
|
_guess_decimal_separator(handle) |
|
|
|
_guess_decimal_separator(handle) |
|
|
@ -90,7 +90,7 @@ def test_guess_decimal_separator_rewinds_handle(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_well_regex_ok(): |
|
|
|
def test_well_regex_ok(): |
|
|
|
from sensospot_data.parser import REGEX_WELL |
|
|
|
from sensospot_parser.parser import REGEX_WELL |
|
|
|
|
|
|
|
|
|
|
|
result = REGEX_WELL.match("AbC123") |
|
|
|
result = REGEX_WELL.match("AbC123") |
|
|
|
|
|
|
|
|
|
|
@ -100,7 +100,7 @@ def test_well_regex_ok(): |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("input", ["", "A", "1", "1A", "-1", "A-"]) |
|
|
|
@pytest.mark.parametrize("input", ["", "A", "1", "1A", "-1", "A-"]) |
|
|
|
def test_well_regex_no_match(input): |
|
|
|
def test_well_regex_no_match(input): |
|
|
|
from sensospot_data.parser import REGEX_WELL |
|
|
|
from sensospot_parser.parser import REGEX_WELL |
|
|
|
|
|
|
|
|
|
|
|
result = REGEX_WELL.match(input) |
|
|
|
result = REGEX_WELL.match(input) |
|
|
|
|
|
|
|
|
|
|
@ -112,7 +112,7 @@ def test_well_regex_no_match(input): |
|
|
|
[("A1_1.csv", ("A", 1, 1)), ("test/measurement_1_H12_2", ("H", 12, 2))], |
|
|
|
[("A1_1.csv", ("A", 1, 1)), ("test/measurement_1_H12_2", ("H", 12, 2))], |
|
|
|
) |
|
|
|
) |
|
|
|
def test_extract_measurement_info_ok(filename, expected): |
|
|
|
def test_extract_measurement_info_ok(filename, expected): |
|
|
|
from sensospot_data.parser import _extract_measurement_info |
|
|
|
from sensospot_parser.parser import _extract_measurement_info |
|
|
|
|
|
|
|
|
|
|
|
result = _extract_measurement_info(filename) |
|
|
|
result = _extract_measurement_info(filename) |
|
|
|
|
|
|
|
|
|
|
@ -121,7 +121,7 @@ def test_extract_measurement_info_ok(filename, expected): |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("filename", ["wrong_exposure_A1_B", "no_well_XX_1"]) |
|
|
|
@pytest.mark.parametrize("filename", ["wrong_exposure_A1_B", "no_well_XX_1"]) |
|
|
|
def test_extract_measurement_info_raises_error(filename): |
|
|
|
def test_extract_measurement_info_raises_error(filename): |
|
|
|
from sensospot_data.parser import _extract_measurement_info |
|
|
|
from sensospot_parser.parser import _extract_measurement_info |
|
|
|
|
|
|
|
|
|
|
|
with pytest.raises(ValueError): |
|
|
|
with pytest.raises(ValueError): |
|
|
|
_extract_measurement_info(filename) |
|
|
|
_extract_measurement_info(filename) |
|
|
@ -130,7 +130,7 @@ def test_extract_measurement_info_raises_error(filename): |
|
|
|
def test_cleanup_data_columns(): |
|
|
|
def test_cleanup_data_columns(): |
|
|
|
from pandas import DataFrame |
|
|
|
from pandas import DataFrame |
|
|
|
|
|
|
|
|
|
|
|
from sensospot_data.parser import _cleanup_data_columns |
|
|
|
from sensospot_parser.parser import _cleanup_data_columns |
|
|
|
|
|
|
|
|
|
|
|
columns = ["Rect.", "Contour", " ID ", "Found", "Dia."] |
|
|
|
columns = ["Rect.", "Contour", " ID ", "Found", "Dia."] |
|
|
|
data = {col: [i] for i, col in enumerate(columns)} |
|
|
|
data = {col: [i] for i, col in enumerate(columns)} |
|
|
@ -145,7 +145,7 @@ def test_cleanup_data_columns(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_file(example_file): |
|
|
|
def test_parse_file(example_file): |
|
|
|
from sensospot_data.parser import parse_file |
|
|
|
from sensospot_parser.parser import parse_file |
|
|
|
|
|
|
|
|
|
|
|
result = parse_file(example_file) |
|
|
|
result = parse_file(example_file) |
|
|
|
|
|
|
|
|
|
|
@ -184,7 +184,7 @@ def test_parse_file(example_file): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_file_raises_error(example_dir): |
|
|
|
def test_parse_file_raises_error(example_dir): |
|
|
|
from sensospot_data.parser import parse_file |
|
|
|
from sensospot_parser.parser import parse_file |
|
|
|
|
|
|
|
|
|
|
|
csv_file = ( |
|
|
|
csv_file = ( |
|
|
|
example_dir / EXAMPLE_DIR_WITH_PARAMS / "should_raise_value_error.csv" |
|
|
|
example_dir / EXAMPLE_DIR_WITH_PARAMS / "should_raise_value_error.csv" |
|
|
@ -195,7 +195,7 @@ def test_parse_file_raises_error(example_dir): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_file_silenced_returns_data_frame(example_file): |
|
|
|
def test_parse_file_silenced_returns_data_frame(example_file): |
|
|
|
from sensospot_data.parser import _parse_file_silenced |
|
|
|
from sensospot_parser.parser import _parse_file_silenced |
|
|
|
|
|
|
|
|
|
|
|
result = _parse_file_silenced(example_file) |
|
|
|
result = _parse_file_silenced(example_file) |
|
|
|
|
|
|
|
|
|
|
@ -205,7 +205,7 @@ def test_parse_file_silenced_returns_data_frame(example_file): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_file_silenced_returns_none_on_error(example_dir): |
|
|
|
def test_parse_file_silenced_returns_none_on_error(example_dir): |
|
|
|
from sensospot_data.parser import _parse_file_silenced |
|
|
|
from sensospot_parser.parser import _parse_file_silenced |
|
|
|
|
|
|
|
|
|
|
|
csv_file = ( |
|
|
|
csv_file = ( |
|
|
|
example_dir / EXAMPLE_DIR_WITH_PARAMS / "should_raise_value_error.csv" |
|
|
|
example_dir / EXAMPLE_DIR_WITH_PARAMS / "should_raise_value_error.csv" |
|
|
@ -227,7 +227,7 @@ def test_parse_file_silenced_returns_none_on_error(example_dir): |
|
|
|
], |
|
|
|
], |
|
|
|
) |
|
|
|
) |
|
|
|
def testparse_multiple_files_ok(example_dir, file_list): |
|
|
|
def testparse_multiple_files_ok(example_dir, file_list): |
|
|
|
from sensospot_data.parser import parse_multiple_files |
|
|
|
from sensospot_parser.parser import parse_multiple_files |
|
|
|
|
|
|
|
|
|
|
|
sub_dir = example_dir / EXAMPLE_DIR_WO_PARAMS |
|
|
|
sub_dir = example_dir / EXAMPLE_DIR_WO_PARAMS |
|
|
|
files = [sub_dir / file for file in file_list] |
|
|
|
files = [sub_dir / file for file in file_list] |
|
|
@ -240,14 +240,14 @@ def testparse_multiple_files_ok(example_dir, file_list): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def testparse_multiple_files_empty_file_list(): |
|
|
|
def testparse_multiple_files_empty_file_list(): |
|
|
|
from sensospot_data.parser import parse_multiple_files |
|
|
|
from sensospot_parser.parser import parse_multiple_files |
|
|
|
|
|
|
|
|
|
|
|
with pytest.raises(ValueError): |
|
|
|
with pytest.raises(ValueError): |
|
|
|
parse_multiple_files([]) |
|
|
|
parse_multiple_files([]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def testparse_multiple_files_empty_array(example_dir): |
|
|
|
def testparse_multiple_files_empty_array(example_dir): |
|
|
|
from sensospot_data.parser import parse_multiple_files |
|
|
|
from sensospot_parser.parser import parse_multiple_files |
|
|
|
|
|
|
|
|
|
|
|
files = [example_dir / "no_array_A1_1.csv"] |
|
|
|
files = [example_dir / "no_array_A1_1.csv"] |
|
|
|
|
|
|
|
|
|
|
@ -258,7 +258,7 @@ def testparse_multiple_files_empty_array(example_dir): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_find_csv_files(example_dir): |
|
|
|
def test_find_csv_files(example_dir): |
|
|
|
from sensospot_data.parser import find_csv_files |
|
|
|
from sensospot_parser.parser import find_csv_files |
|
|
|
|
|
|
|
|
|
|
|
result = list(find_csv_files(example_dir / EXAMPLE_DIR_WITH_PARAMS)) |
|
|
|
result = list(find_csv_files(example_dir / EXAMPLE_DIR_WITH_PARAMS)) |
|
|
|
|
|
|
|
|
|
|
@ -268,7 +268,7 @@ def test_find_csv_files(example_dir): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_folder(example_dir): |
|
|
|
def test_parse_folder(example_dir): |
|
|
|
from sensospot_data.parser import parse_folder |
|
|
|
from sensospot_parser.parser import parse_folder |
|
|
|
|
|
|
|
|
|
|
|
data_frame = parse_folder(example_dir / EXAMPLE_DIR_WITH_PARAMS) |
|
|
|
data_frame = parse_folder(example_dir / EXAMPLE_DIR_WITH_PARAMS) |
|
|
|
|
|
|
|
|
|
|
@ -282,7 +282,7 @@ def test_parse_folder(example_dir): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_sanity_check_ok(example_dir): |
|
|
|
def test_sanity_check_ok(example_dir): |
|
|
|
from sensospot_data.parser import _sanity_check, parse_multiple_files |
|
|
|
from sensospot_parser.parser import _sanity_check, parse_multiple_files |
|
|
|
|
|
|
|
|
|
|
|
sub_dir = example_dir / EXAMPLE_DIR_WO_PARAMS |
|
|
|
sub_dir = example_dir / EXAMPLE_DIR_WO_PARAMS |
|
|
|
file_list = [ |
|
|
|
file_list = [ |
|
|
@ -298,7 +298,7 @@ def test_sanity_check_ok(example_dir): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_sanity_check_raises_value_error(example_dir): |
|
|
|
def test_sanity_check_raises_value_error(example_dir): |
|
|
|
from sensospot_data.parser import _sanity_check, parse_multiple_files |
|
|
|
from sensospot_parser.parser import _sanity_check, parse_multiple_files |
|
|
|
|
|
|
|
|
|
|
|
sub_dir = example_dir / EXAMPLE_DIR_WO_PARAMS |
|
|
|
sub_dir = example_dir / EXAMPLE_DIR_WO_PARAMS |
|
|
|
file_list = [ |
|
|
|
file_list = [ |
|
|
|