From 6221946c65fd17055d9d87cf6dfc9ed67a1caa57 Mon Sep 17 00:00:00 2001 From: rlskoeser Date: Fri, 19 Apr 2024 12:59:52 -0400 Subject: [PATCH] Clean up unit tests for parsing and transforming edtf dates --- .../test_dateformat/edtf/test_edtf_parser.py | 16 +++++++--------- .../edtf/test_edtf_transformer.py | 19 +++++-------------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/tests/test_dateformat/edtf/test_edtf_parser.py b/tests/test_dateformat/edtf/test_edtf_parser.py index 837d2b5..5a2b8ea 100644 --- a/tests/test_dateformat/edtf/test_edtf_parser.py +++ b/tests/test_dateformat/edtf/test_edtf_parser.py @@ -32,17 +32,15 @@ ] -def test_should_parse(): - for testcase in testcases: - tree = edtf_parser.parse(testcase) - assert tree - print(tree.pretty()) +@pytest.mark.parametrize("date_string", testcases) +def test_should_parse(date_string): + assert edtf_parser.parse(date_string) error_cases = ["1984-13", "Y1702"] -def test_should_error(): - for error_case in error_cases: - with pytest.raises(Exception): - edtf_parser.parse(error_cases) +@pytest.mark.parametrize("date_string", error_cases) +def test_should_error(date_string): + with pytest.raises(Exception): + edtf_parser.parse(date_string) diff --git a/tests/test_dateformat/edtf/test_edtf_transformer.py b/tests/test_dateformat/edtf/test_edtf_transformer.py index f8d70d8..8dba34d 100644 --- a/tests/test_dateformat/edtf/test_edtf_transformer.py +++ b/tests/test_dateformat/edtf/test_edtf_transformer.py @@ -36,18 +36,9 @@ ] -def test_transform(): +@pytest.mark.parametrize("date_string,expected", testcases) +def test_transform(date_string, expected): transformer = EDTFTransformer() - - for testinput, output in testcases: - parsetree = edtf_parser.parse(testinput) - assert transformer.transform(parsetree) == output - - -# error_cases = ["1984-13", "Y1702"] - - -# def test_should_error(): -# for error_case in error_cases: -# with pytest.raises(Exception): -# edtf_parser.parse(error_cases) + # parse the input string, then transform to undate object + parsetree = edtf_parser.parse(date_string) + assert transformer.transform(parsetree) == expected