From 280cb387ed4539a94551a1656c8a7d3e93bba8a9 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Mon, 25 Mar 2019 08:29:38 +0100 Subject: [PATCH 1/3] Basic tests for issue #797 --- tests/data_normalizer/test_python.py | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/data_normalizer/test_python.py diff --git a/tests/data_normalizer/test_python.py b/tests/data_normalizer/test_python.py new file mode 100644 index 000000000..1c79a1013 --- /dev/null +++ b/tests/data_normalizer/test_python.py @@ -0,0 +1,38 @@ +"""Tests for Java data normalizers.""" + +import pytest +from f8a_worker.data_normalizer import PythonDataNormalizer + + +@pytest.mark.parametrize('data,keymap,expected', [ + # pick one key which IS there + ({'author': 'me', 'version': '0.1.2'}, (('author',),), {'author': 'me'}), + # pick one key which IS NOT there + ({'author-name': 'me', 'version': '0.1.2'}, (('author',),), + {'author': None}), + # pick & and rename one key which IS there + ({'author-name': 'me'}, (('author-name', 'author',),), + {'author': 'me'}), + # pick & and rename one key which IS NOT there + ({'authors': 'they'}, (('author-name', 'author',),), + {'author': None}), + # pick one of keys + ({'license': 'MIT'}, ((('license', 'licenses',), ),), + {'license': 'MIT'}), + # pick one of keys + ({'licenses': ['MIT', 'BSD']}, ((('license', 'licenses',),),), + {'licenses': ['MIT', 'BSD']}), + # pick one of keys and rename it + ({'license': 'MIT'}, ((('license', 'licenses',), 'declared_licenses'),), + {'declared_licenses': 'MIT'}), +]) +def test_constructor(data, keymap, expected): + """Test AbstractDataNormalizer constructor.""" + dn = PythonDataNormalizer(data) + assert dn is not None + + +def test_constructor_error_input(): + """Test AbstractDataNormalizer constructor for error input.""" + dn = PythonDataNormalizer("error") + assert dn is not None From d7baca09550522b1b2ded566e507bcaaa6245707 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Mon, 25 Mar 2019 08:35:10 +0100 Subject: [PATCH 2/3] Dummy tests (for now) --- tests/data_normalizer/test_python.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/data_normalizer/test_python.py b/tests/data_normalizer/test_python.py index 1c79a1013..f748d7018 100644 --- a/tests/data_normalizer/test_python.py +++ b/tests/data_normalizer/test_python.py @@ -30,6 +30,8 @@ def test_constructor(data, keymap, expected): """Test AbstractDataNormalizer constructor.""" dn = PythonDataNormalizer(data) assert dn is not None + assert keymap + assert expected def test_constructor_error_input(): From ec6fceb60e864d96e7e5ca2ee596def659c3ec77 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Mon, 25 Mar 2019 08:40:13 +0100 Subject: [PATCH 3/3] Additional test for normalizer --- tests/data_normalizer/test_python.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/data_normalizer/test_python.py b/tests/data_normalizer/test_python.py index f748d7018..c5cf8c3e9 100644 --- a/tests/data_normalizer/test_python.py +++ b/tests/data_normalizer/test_python.py @@ -38,3 +38,11 @@ def test_constructor_error_input(): """Test AbstractDataNormalizer constructor for error input.""" dn = PythonDataNormalizer("error") assert dn is not None + + +def test_normalize_error_input(): + """Test AbstractDataNormalizer constructor for error input.""" + dn = PythonDataNormalizer("error") + assert dn is not None + n = dn.normalize() + assert n == {}