Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Add script: merge concat without space #602

Merged
merged 8 commits into from
Sep 2, 2021
2 changes: 1 addition & 1 deletion django/common/scripts/cleaning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion django/common/scripts/merging/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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)
nriss marked this conversation as resolved.
Show resolved Hide resolved
1 change: 0 additions & 1 deletion django/common/scripts/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -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
82 changes: 60 additions & 22 deletions tests/common/scripts/merging/test_merge_concat.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion tests/common/scripts/merging/test_merge_instant.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down