diff --git a/django/common/scripts/cleaning/__init__.py b/django/common/scripts/cleaning/__init__.py index afeb363ec..5e74f46ad 100644 --- a/django/common/scripts/cleaning/__init__.py +++ b/django/common/scripts/cleaning/__init__.py @@ -6,10 +6,10 @@ from .clean_date import clean_date from .clean_dateTime import clean_dateTime from .clean_instant import clean_instant +from .clean_long_text_ORBIS import clean_long_text_ORBIS from .clean_phone import clean_phone from .clean_quantity import clean_quantity from .clean_time import clean_time -from .clean_long_text_ORBIS import clean_long_text_ORBIS from .code_to_empty import code_to_empty from .if_valid import if_valid from .make_title import make_title diff --git a/django/common/scripts/merging/__init__.py b/django/common/scripts/merging/__init__.py index 9f2128929..0ebc3d9e2 100644 --- a/django/common/scripts/merging/__init__.py +++ b/django/common/scripts/merging/__init__.py @@ -1,7 +1,8 @@ # flake8: noqa from .merge_concat import merge_concat +from .merge_concat_without_separator import merge_concat_without_separator from .merge_datetime import merge_datetime -from .merge_instant import merge_instant from .merge_insee import merge_insee +from .merge_instant import merge_instant from .merge_status import merge_status from .select_first_not_empty import select_first_not_empty diff --git a/django/common/scripts/utils/concat_without_separator.py b/django/common/scripts/merging/merge_concat_without_separator.py similarity index 64% rename from django/common/scripts/utils/concat_without_separator.py rename to django/common/scripts/merging/merge_concat_without_separator.py index cc6bc609a..8fd6aeaa2 100644 --- a/django/common/scripts/utils/concat_without_separator.py +++ b/django/common/scripts/merging/merge_concat_without_separator.py @@ -1,5 +1,6 @@ -def concat_without_separator(*args): +def merge_concat_without_separator(*args): """Merging script with a simple concatenation, no separator""" values = [str(v) for v in args if v is not None] separator = "" - return separator.join(values) + + return separator.join(values) \ No newline at end of file diff --git a/django/common/scripts/utils/__init__.py b/django/common/scripts/utils/__init__.py index dcd2e1c10..d0675f120 100644 --- a/django/common/scripts/utils/__init__.py +++ b/django/common/scripts/utils/__init__.py @@ -1,4 +1,3 @@ -from .concat_without_separator import concat_without_separator # noqa from .is_empty import is_empty # noqa from .select_max import select_max # noqa from .select_min import select_min # noqa diff --git a/tests/common/scripts/cleaning/test_concat_without_separator.py b/tests/common/scripts/cleaning/test_concat_without_separator.py deleted file mode 100644 index fe5e4ed97..000000000 --- a/tests/common/scripts/cleaning/test_concat_without_separator.py +++ /dev/null @@ -1,53 +0,0 @@ -import datetime - -from common.scripts import utils - - -def test_concat_without_separator(): - - # Tests string - - assert utils.concat_without_separator("1") == "1" - - assert utils.concat_without_separator("1", "2") == "12" - - assert utils.concat_without_separator("1", "2", "3") == "123" - - assert utils.concat_without_separator("a", "b", "ab") == "abab" - - assert utils.concat_without_separator("a ", " b", " ab") == "a b ab" - - assert ( - utils.concat_without_separator("Pyrog ", " Is ", " Awesome ") - == "Pyrog Is Awesome " - ) - - # Tests integer - - assert utils.concat_without_separator(1, 2) == "12" - - assert utils.concat_without_separator(1, 2, 3) == "123" - - # Tests datetime - - dateNow = datetime.datetime.now() - assert utils.concat_without_separator("a", dateNow) == "a" + str(dateNow) - - assert utils.concat_without_separator("testing", datetime.datetime(2020, 5, 17)) == "testing2020-05-17 00:00:00" - - # Test date - - assert utils.concat_without_separator("testing", datetime.date(2020, 5, 17)) == "testing2020-05-17" - - # Test boolean - - assert utils.concat_without_separator(True) == "True" - - assert utils.concat_without_separator(True, False) == "TrueFalse" - - # Test mixed - dateNow = datetime.datetime.now() - assert ( - utils.concat_without_separator("a", dateNow, datetime.date(2020, 5, 17), True) - == "a" + str(dateNow) + "2020-05-17True" - ) diff --git a/tests/common/scripts/merging/test_merge_concat.py b/tests/common/scripts/merging/test_merge_concat.py index d5171d6fb..7a42cd0ec 100644 --- a/tests/common/scripts/merging/test_merge_concat.py +++ b/tests/common/scripts/merging/test_merge_concat.py @@ -1,42 +1,80 @@ import datetime -from common.scripts.merging import merge_concat +import pytest +from common.scripts.merging import merge_concat, merge_concat_without_separator -def test_merge_concat(): +datenow = datetime.datetime.now() - # Tests string +# Boolean - assert merge_concat("1") == "1" - assert merge_concat("1", "2") == "1 2" +@pytest.mark.parametrize("test_input,expected", [((True,), "True"), ((True, False), "TrueFalse")]) +def test_merge_concat_without_separator_bool(test_input, expected): + assert merge_concat_without_separator(*test_input) == expected - assert merge_concat("1", "2", "3") == "1 2 3" - assert merge_concat("a", "b", "ab") == "a b ab" +@pytest.mark.parametrize("test_input,expected", [((True,), "True"), ((True, False), "True False")]) +def test_merge_concat_bool(test_input, expected): + assert merge_concat(*test_input) == expected - # Tests integer - assert merge_concat(1, 2) == "1 2" +# Date - assert merge_concat(1, 2, 3) == "1 2 3" - # Tests datetime +@pytest.mark.parametrize( + "test_input,expected", + [(("a", datenow), f"a{datenow}"), (("testing", datetime.date(2020, 5, 17)), "testing2020-05-17")], +) +def test_merge_concat_without_separator_date(test_input, expected): + assert merge_concat_without_separator(*test_input) == expected - dateNow = datetime.datetime.now() - assert merge_concat("a", dateNow) == "a " + str(dateNow) - assert merge_concat("testing", datetime.datetime(2020, 5, 17)) == "testing 2020-05-17 00:00:00" - # Test date +@pytest.mark.parametrize( + "test_input,expected", + [(("a", datenow), f"a {datenow}"), (("testing", datetime.date(2020, 5, 17)), "testing 2020-05-17")], +) +def test_merge_concat_date(test_input, expected): + assert merge_concat(*test_input) == expected - assert merge_concat("testing", datetime.date(2020, 5, 17)) == "testing 2020-05-17" - # Test boolean +# Integer +@pytest.mark.parametrize("test_input,expected", [((1, 2), "12"), ((1, 2, 3), "123")]) +def test_merge_concat_without_separator_int(test_input, expected): + assert merge_concat_without_separator(*test_input) == expected - assert merge_concat(True) == "True" - assert merge_concat(True, False) == "True False" +@pytest.mark.parametrize("test_input,expected", [((1, 2), "1 2"), ((1, 2, 3), "1 2 3")]) +def test_merge_concat_int(test_input, expected): + assert merge_concat(*test_input) == expected - # Test mixed - dateNow = datetime.datetime.now() - assert merge_concat("a", dateNow, datetime.date(2020, 5, 17), True) == "a " + str(dateNow) + " 2020-05-17 True" + +# Mixed +@pytest.mark.parametrize( + "test_input,expected", [(("a", datenow, datetime.date(2020, 5, 17), True), f"a{datenow}2020-05-17True")] +) +def test_merge_concat_without_separator_mix(test_input, expected): + assert merge_concat_without_separator(*test_input) == expected + + +@pytest.mark.parametrize( + "test_input,expected", [(("a", datenow, datetime.date(2020, 5, 17), True), f"a {datenow} 2020-05-17 True")] +) +def test_merge_concat_mix(test_input, expected): + assert merge_concat(*test_input) == expected + + +# String +@pytest.mark.parametrize( + "test_input,expected", [(("1",), "1"), (("1", "2"), "12"), (("1", "2", "3"), "123"), (("a", "b", "ab"), "abab")] +) +def test_merge_concat_without_separator_string(test_input, expected): + assert merge_concat_without_separator(*test_input) == expected + + +@pytest.mark.parametrize( + "test_input,expected", + [(("1",), "1"), (("1", "2"), "1 2"), (("1", "2", "3"), "1 2 3"), (("a", "b", "ab"), "a b ab")], +) +def test_merge_concat_string(test_input, expected): + assert merge_concat(*test_input) == expected diff --git a/tests/common/scripts/merging/test_merge_instant.py b/tests/common/scripts/merging/test_merge_instant.py index 93a8cec62..945da88b0 100644 --- a/tests/common/scripts/merging/test_merge_instant.py +++ b/tests/common/scripts/merging/test_merge_instant.py @@ -1,6 +1,7 @@ -from common.scripts.merging import merge_instant import pytest +from common.scripts.merging import merge_instant + def test_merge_instant(): assert merge_instant("2015-02-07", "13:28:17") == "2015-02-07T13:28:17+02:00"