|
|
@ -2,7 +2,7 @@ from datetime import datetime |
|
|
|
|
|
|
|
|
|
|
|
import pytest |
|
|
|
import pytest |
|
|
|
|
|
|
|
|
|
|
|
from .conftest import EXAMPLE_DIR_XML_WO_PARAMS, EXAMPLE_DIR_XML_WITH_PARAMS |
|
|
|
from .conftest import EXAMPLE_DIR_XML_WITH_PARAMS, EXAMPLE_DIR_XML_WO_PARAMS |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DummyDataFunc: |
|
|
|
class DummyDataFunc: |
|
|
@ -28,7 +28,7 @@ def test_parser_target_init(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
@pytest.mark.parametrize( |
|
|
|
"tag, attributes, expected", |
|
|
|
("tag", "attributes", "expected"), |
|
|
|
[ |
|
|
|
[ |
|
|
|
("UnknownTag", {"ID": "something"}, {}), |
|
|
|
("UnknownTag", {"ID": "something"}, {}), |
|
|
|
( |
|
|
|
( |
|
|
@ -84,7 +84,7 @@ def test_parser_target_start_image_file_name(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
@pytest.mark.parametrize( |
|
|
|
"data_type, value, expected", |
|
|
|
("data_type", "value", "expected"), |
|
|
|
[ |
|
|
|
[ |
|
|
|
("unknown type", 1, "1"), |
|
|
|
("unknown type", 1, "1"), |
|
|
|
("System.Int32", "12", 12), |
|
|
|
("System.Int32", "12", 12), |
|
|
@ -108,16 +108,40 @@ def test_parser_target_result_attributes_parser(data_type, value, expected): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
@pytest.mark.parametrize( |
|
|
|
"value, expected", |
|
|
|
("value", "expected"), |
|
|
|
[ |
|
|
|
[ |
|
|
|
("3/7/2022 5:31:47 PM", datetime(2022, 3, 7, 17, 31, 47)), |
|
|
|
( |
|
|
|
("03/7/2022 5:31:47 PM", datetime(2022, 3, 7, 17, 31, 47)), |
|
|
|
"3/7/2022 5:31:47 PM", |
|
|
|
("3/07/2022 5:31:47 PM", datetime(2022, 3, 7, 17, 31, 47)), |
|
|
|
datetime(2022, 3, 7, 17, 31, 47), # noqa: DTZ001 |
|
|
|
("03/07/2022 5:31:47 PM", datetime(2022, 3, 7, 17, 31, 47)), |
|
|
|
), |
|
|
|
("3/7/2022 5:3:47 PM", datetime(2022, 3, 7, 17, 3, 47)), |
|
|
|
( |
|
|
|
("3/7/2022 5:31:4 PM", datetime(2022, 3, 7, 17, 31, 4)), |
|
|
|
"03/7/2022 5:31:47 PM", |
|
|
|
("3/7/2022 5:31:47 pm", datetime(2022, 3, 7, 17, 31, 47)), |
|
|
|
datetime(2022, 3, 7, 17, 31, 47), # noqa: DTZ001 |
|
|
|
("3/7/2022 5:31:47 AM", datetime(2022, 3, 7, 5, 31, 47)), |
|
|
|
), |
|
|
|
|
|
|
|
( |
|
|
|
|
|
|
|
"3/07/2022 5:31:47 PM", |
|
|
|
|
|
|
|
datetime(2022, 3, 7, 17, 31, 47), # noqa: DTZ001 |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
( |
|
|
|
|
|
|
|
"03/07/2022 5:31:47 PM", |
|
|
|
|
|
|
|
datetime(2022, 3, 7, 17, 31, 47), # noqa: DTZ001 |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
( |
|
|
|
|
|
|
|
"3/7/2022 5:3:47 PM", |
|
|
|
|
|
|
|
datetime(2022, 3, 7, 17, 3, 47), # noqa: DTZ001 |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
( |
|
|
|
|
|
|
|
"3/7/2022 5:31:4 PM", |
|
|
|
|
|
|
|
datetime(2022, 3, 7, 17, 31, 4), # noqa: DTZ001 |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
( |
|
|
|
|
|
|
|
"3/7/2022 5:31:47 pm", |
|
|
|
|
|
|
|
datetime(2022, 3, 7, 17, 31, 47), # noqa: DTZ001 |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
( |
|
|
|
|
|
|
|
"3/7/2022 5:31:47 AM", |
|
|
|
|
|
|
|
datetime(2022, 3, 7, 5, 31, 47), # noqa: DTZ001 |
|
|
|
|
|
|
|
), |
|
|
|
], |
|
|
|
], |
|
|
|
) |
|
|
|
) |
|
|
|
def test_parser_target_data_timestamp_parser(value, expected): |
|
|
|
def test_parser_target_data_timestamp_parser(value, expected): |
|
|
@ -203,8 +227,6 @@ def test_find_result_xml_file_ok(tmp_path): |
|
|
|
xml_file = tmp_path / "result.xml" |
|
|
|
xml_file = tmp_path / "result.xml" |
|
|
|
xml_file.touch() |
|
|
|
xml_file.touch() |
|
|
|
|
|
|
|
|
|
|
|
print(list(tmp_path.iterdir())) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = _find_result_xml_file(tmp_path) |
|
|
|
result = _find_result_xml_file(tmp_path) |
|
|
|
|
|
|
|
|
|
|
|
assert result == xml_file |
|
|
|
assert result == xml_file |
|
|
@ -257,8 +279,6 @@ def test_find_result_hidden_xsl_file(tmp_path): |
|
|
|
xml_file = tmp_path / ".result.xml" |
|
|
|
xml_file = tmp_path / ".result.xml" |
|
|
|
xml_file.touch() |
|
|
|
xml_file.touch() |
|
|
|
|
|
|
|
|
|
|
|
print(list(tmp_path.iterdir())) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = _find_result_xml_file(tmp_path) |
|
|
|
result = _find_result_xml_file(tmp_path) |
|
|
|
|
|
|
|
|
|
|
|
assert result is None |
|
|
|
assert result is None |
|
|
@ -266,10 +286,9 @@ def test_find_result_hidden_xsl_file(tmp_path): |
|
|
|
|
|
|
|
|
|
|
|
def test_parse_xml_file_ok(example_dir): |
|
|
|
def test_parse_xml_file_ok(example_dir): |
|
|
|
import pandas |
|
|
|
import pandas |
|
|
|
|
|
|
|
|
|
|
|
from sensospot_parser.xml_parser import ( |
|
|
|
from sensospot_parser.xml_parser import ( |
|
|
|
parse_xml_file, |
|
|
|
|
|
|
|
_find_result_xml_file, |
|
|
|
_find_result_xml_file, |
|
|
|
|
|
|
|
parse_xml_file, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
folder = example_dir / EXAMPLE_DIR_XML_WO_PARAMS |
|
|
|
folder = example_dir / EXAMPLE_DIR_XML_WO_PARAMS |
|
|
@ -288,10 +307,10 @@ def test_parse_xml_file_ok(example_dir): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
@pytest.mark.parametrize( |
|
|
|
"file_name, message", |
|
|
|
("file_name", "message"), |
|
|
|
[ |
|
|
|
[ |
|
|
|
("not_existing.xml", "Xml file does not exist"), |
|
|
|
("not_existing.xml", "Xml file does not exist"), |
|
|
|
("incomplete.xml", "Could not parse assay results xml file"), |
|
|
|
("defect.xml", "Could not parse assay results xml file"), |
|
|
|
("malformed_data.xml", "Malformed data in xml file"), |
|
|
|
("malformed_data.xml", "Malformed data in xml file"), |
|
|
|
], |
|
|
|
], |
|
|
|
) |
|
|
|
) |
|
|
@ -300,14 +319,14 @@ def test_parse_xml_file_raies_error(file_name, message, example_dir): |
|
|
|
|
|
|
|
|
|
|
|
xml_file = example_dir / file_name |
|
|
|
xml_file = example_dir / file_name |
|
|
|
|
|
|
|
|
|
|
|
with pytest.raises(ValueError) as e: |
|
|
|
with pytest.raises(ValueError) as e: # noqa: PT011 |
|
|
|
parse_xml_file(xml_file) |
|
|
|
parse_xml_file(xml_file) |
|
|
|
assert message in str(e) |
|
|
|
|
|
|
|
|
|
|
|
assert message in str(e) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_xml_folder_with_params(example_dir): |
|
|
|
def test_parse_xml_folder_with_params(example_dir): |
|
|
|
import pandas |
|
|
|
import pandas |
|
|
|
|
|
|
|
|
|
|
|
from sensospot_parser.xml_parser import parse_xml_folder |
|
|
|
from sensospot_parser.xml_parser import parse_xml_folder |
|
|
|
|
|
|
|
|
|
|
|
folder = example_dir / EXAMPLE_DIR_XML_WITH_PARAMS |
|
|
|
folder = example_dir / EXAMPLE_DIR_XML_WITH_PARAMS |
|
|
@ -321,7 +340,6 @@ def test_parse_xml_folder_with_params(example_dir): |
|
|
|
|
|
|
|
|
|
|
|
def test_parse_xml_folder_without_params(example_dir): |
|
|
|
def test_parse_xml_folder_without_params(example_dir): |
|
|
|
import pandas |
|
|
|
import pandas |
|
|
|
|
|
|
|
|
|
|
|
from sensospot_parser.xml_parser import parse_xml_folder |
|
|
|
from sensospot_parser.xml_parser import parse_xml_folder |
|
|
|
|
|
|
|
|
|
|
|
folder = example_dir / EXAMPLE_DIR_XML_WO_PARAMS |
|
|
|
folder = example_dir / EXAMPLE_DIR_XML_WO_PARAMS |
|
|
@ -336,6 +354,7 @@ def test_parse_xml_folder_without_params(example_dir): |
|
|
|
def test_parse_xml_folder_non_existing_xml_file(tmp_path): |
|
|
|
def test_parse_xml_folder_non_existing_xml_file(tmp_path): |
|
|
|
from sensospot_parser.xml_parser import parse_xml_folder |
|
|
|
from sensospot_parser.xml_parser import parse_xml_folder |
|
|
|
|
|
|
|
|
|
|
|
with pytest.raises(ValueError) as e: |
|
|
|
with pytest.raises(ValueError) as e: # noqa: PT011 |
|
|
|
parse_xml_folder(tmp_path) |
|
|
|
parse_xml_folder(tmp_path) |
|
|
|
assert "Could not find assay results xml file" in str(e) |
|
|
|
|
|
|
|
|
|
|
|
assert "Could not find assay results xml file" in str(e) |
|
|
|