Browse Source

renamed package to 'sensospot_parser'

xmlparsing
Holger Frey 3 years ago
parent
commit
fde3513809
  1. 10
      Makefile
  2. 8
      pyproject.toml
  3. 0
      sensospot_parser/__init__.py
  4. 0
      sensospot_parser/columns.py
  5. 0
      sensospot_parser/parameters.py
  6. 0
      sensospot_parser/parser.py
  7. 6
      tests/conftest.py
  8. 16
      tests/test_parameters.py
  9. 40
      tests/test_parser.py
  10. 8
      tests/test_sensospot_data.py

10
Makefile

@ -51,16 +51,16 @@ clean-test: ## remove test and coverage artifacts
rm -fr htmlcov/ rm -fr htmlcov/
lint: ## reformat with black and check style with flake8 lint: ## reformat with black and check style with flake8
isort sensospot_data isort sensospot_parser
isort tests isort tests
black sensospot_data tests black sensospot_parser tests
flake8 --ignore E231,W503,E402 sensospot_data tests flake8 --ignore E231,W503,E402 sensospot_parser tests
test: ## run tests quickly with the default Python test: ## run tests quickly with the default Python
pytest tests -x --disable-warnings --failed-first pytest tests -x --disable-warnings --failed-first
coverage: ## full test suite, check code coverage and open coverage report coverage: ## full test suite, check code coverage and open coverage report
pytest tests --cov=sensospot_data pytest tests --cov=sensospot_parser
coverage html coverage html
$(BROWSER) htmlcov/index.html $(BROWSER) htmlcov/index.html
@ -80,7 +80,7 @@ repo: devenv ## complete project setup with development environment and git repo
git init . git init .
git add . git add .
git commit -m "import of project template" git commit -m "import of project template"
git remote add origin https://git.cpi.imtek.uni-freiburg.de/holgi/sensospot_data.git git remote add origin https://git.cpi.imtek.uni-freiburg.de/holgi/sensospot_parser.git
git push -u origin master --no-verify git push -u origin master --no-verify
.venv/bin/pre-commit install --install-hooks .venv/bin/pre-commit install --install-hooks

8
pyproject.toml

@ -3,11 +3,11 @@ requires = ["flit"]
build-backend = "flit.buildapi" build-backend = "flit.buildapi"
[tool.flit.metadata] [tool.flit.metadata]
module = "sensospot_data" module = "sensospot_parser"
dist-name = "sensospot_data" dist-name = "sensospot_parser"
author = "Holger Frey" author = "Holger Frey"
author-email = "frey@imtek.de" author-email = "frey@imtek.de"
home-page = "https://git.cpi.imtek.uni-freiburg.de/holgi/sensospot_data.git" home-page = "https://git.cpi.imtek.uni-freiburg.de/holgi/sensospot_parser.git"
description-file = "README.md" description-file = "README.md"
license = "Beerware" license = "Beerware"
@ -48,7 +48,7 @@ dev = [
] ]
[tool.flit.scripts] [tool.flit.scripts]
sensospot_parse = "sensospot_data:main" sensospot_parse = "sensospot_parser:main"
[tool.black] [tool.black]
line-length = 79 line-length = 79

0
sensospot_data/__init__.py → sensospot_parser/__init__.py

0
sensospot_data/columns.py → sensospot_parser/columns.py

0
sensospot_data/parameters.py → sensospot_parser/parameters.py

0
sensospot_data/parser.py → sensospot_parser/parser.py

6
tests/conftest.py

@ -30,7 +30,7 @@ def exposure_df():
@pytest.fixture @pytest.fixture
def normalization_data_frame(): def normalization_data_frame():
from sensospot_data.columns import RAW_DATA_NORMALIZATION_MAP from sensospot_parser.columns import RAW_DATA_NORMALIZATION_MAP
overflow_test_values = [ overflow_test_values = [
(1, 1, 1, 50, 1, 0), (1, 1, 1, 50, 1, 0),
@ -92,14 +92,14 @@ def normalization_data_frame():
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def parsed_data_frame_with_params(example_dir): def parsed_data_frame_with_params(example_dir):
from sensospot_data.parser import parse_folder from sensospot_parser.parser import parse_folder
return parse_folder(example_dir / EXAMPLE_DIR_WITH_PARAMS) return parse_folder(example_dir / EXAMPLE_DIR_WITH_PARAMS)
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def parsed_data_frame_without_params(example_dir): def parsed_data_frame_without_params(example_dir):
from sensospot_data.parser import parse_folder from sensospot_parser.parser import parse_folder
return parse_folder(example_dir / EXAMPLE_DIR_WO_PARAMS) return parse_folder(example_dir / EXAMPLE_DIR_WO_PARAMS)

16
tests/test_parameters.py

@ -4,7 +4,7 @@ from .conftest import EXAMPLE_DIR_WO_PARAMS, EXAMPLE_DIR_WITH_PARAMS
def test_search_params_file_ok(example_dir): def test_search_params_file_ok(example_dir):
from sensospot_data.parameters import _search_params_file from sensospot_parser.parameters import _search_params_file
result = _search_params_file(example_dir / EXAMPLE_DIR_WITH_PARAMS) result = _search_params_file(example_dir / EXAMPLE_DIR_WITH_PARAMS)
@ -12,7 +12,7 @@ def test_search_params_file_ok(example_dir):
def test_search_params_file_no_parameters_folder(example_dir): def test_search_params_file_no_parameters_folder(example_dir):
from sensospot_data.parameters import _search_params_file from sensospot_parser.parameters import _search_params_file
result = _search_params_file(example_dir / EXAMPLE_DIR_WO_PARAMS) result = _search_params_file(example_dir / EXAMPLE_DIR_WO_PARAMS)
@ -20,7 +20,7 @@ def test_search_params_file_no_parameters_folder(example_dir):
def test_ssearch_measurement_params_file_parameters_file(tmpdir): def test_ssearch_measurement_params_file_parameters_file(tmpdir):
from sensospot_data.parameters import _search_params_file from sensospot_parser.parameters import _search_params_file
params_dir = tmpdir / "Parameters" params_dir = tmpdir / "Parameters"
params_dir.mkdir() params_dir.mkdir()
@ -31,7 +31,7 @@ def test_ssearch_measurement_params_file_parameters_file(tmpdir):
def test_parse_channel_info(example_dir): def test_parse_channel_info(example_dir):
from sensospot_data.parameters import ( from sensospot_parser.parameters import (
_search_params_file, _search_params_file,
_parse_measurement_params, _parse_measurement_params,
) )
@ -51,7 +51,7 @@ def test_parse_channel_info(example_dir):
def test_get_measurement_params_file_found(example_dir): def test_get_measurement_params_file_found(example_dir):
from sensospot_data.parameters import get_measurement_params from sensospot_parser.parameters import get_measurement_params
result = get_measurement_params(example_dir / EXAMPLE_DIR_WITH_PARAMS) result = get_measurement_params(example_dir / EXAMPLE_DIR_WITH_PARAMS)
@ -67,7 +67,7 @@ def test_get_measurement_params_file_found(example_dir):
def test_get_measurement_params_file_not_found(example_dir): def test_get_measurement_params_file_not_found(example_dir):
from sensospot_data.parameters import get_measurement_params from sensospot_parser.parameters import get_measurement_params
result = get_measurement_params(example_dir / EXAMPLE_DIR_WO_PARAMS) result = get_measurement_params(example_dir / EXAMPLE_DIR_WO_PARAMS)
@ -75,7 +75,7 @@ def test_get_measurement_params_file_not_found(example_dir):
def test_add_measurement_parameters_with_params_file(exposure_df, example_dir): def test_add_measurement_parameters_with_params_file(exposure_df, example_dir):
from sensospot_data.parameters import add_measurement_parameters from sensospot_parser.parameters import add_measurement_parameters
folder = example_dir / EXAMPLE_DIR_WITH_PARAMS folder = example_dir / EXAMPLE_DIR_WITH_PARAMS
exposure_df = add_measurement_parameters(exposure_df, folder) exposure_df = add_measurement_parameters(exposure_df, folder)
@ -91,7 +91,7 @@ def test_add_measurement_parameters_with_params_file(exposure_df, example_dir):
def test_add_measurement_parameters_without_params_file( def test_add_measurement_parameters_without_params_file(
exposure_df, example_dir exposure_df, example_dir
): ):
from sensospot_data.parameters import add_measurement_parameters from sensospot_parser.parameters import add_measurement_parameters
folder = example_dir / EXAMPLE_DIR_WO_PARAMS folder = example_dir / EXAMPLE_DIR_WO_PARAMS
exposure_df = add_measurement_parameters(exposure_df, folder) exposure_df = add_measurement_parameters(exposure_df, folder)

40
tests/test_parser.py

@ -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 = [

8
tests/test_sensospot_data.py

@ -2,7 +2,7 @@
def test_import_api(): def test_import_api():
from sensospot_data import main # noqa: F401 from sensospot_parser import main # noqa: F401
from sensospot_data import columns # noqa: F401 from sensospot_parser import columns # noqa: F401
from sensospot_data import parse_file # noqa: F401 from sensospot_parser import parse_file # noqa: F401
from sensospot_data import parse_folder # noqa: F401 from sensospot_parser import parse_folder # noqa: F401

Loading…
Cancel
Save