From 01b15786a8ae02d364ff79011473bde90eb42e76 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sun, 4 Aug 2019 11:54:08 +0200 Subject: Add some tests --- tests/filters/test_birthday.py | 17 +++++++++ tests/filters/test_clean.py | 12 ++++++ tests/filters/test_datediff.py | 84 ++++++++++++++++++++++++++++++++++++++++++ tests/filters/test_dateedit.py | 30 +++++++++++++++ 4 files changed, 143 insertions(+) create mode 100644 tests/filters/test_birthday.py create mode 100644 tests/filters/test_clean.py create mode 100644 tests/filters/test_datediff.py create mode 100644 tests/filters/test_dateedit.py (limited to 'tests/filters') diff --git a/tests/filters/test_birthday.py b/tests/filters/test_birthday.py new file mode 100644 index 0000000..257f8c4 --- /dev/null +++ b/tests/filters/test_birthday.py @@ -0,0 +1,17 @@ +import pytest + +import resumejson_converter.filters as filters + + +def test_birthday_no_parameter(): + with pytest.raises(TypeError): + filters.birthday() + + +def test_birthday_false_date(): + with pytest.raises(ValueError): + filters.birthday("1990-10-25a") + + +def test_birthday(): + assert filters.birthday("1990-10-25") == "25 octobre 1990" diff --git a/tests/filters/test_clean.py b/tests/filters/test_clean.py new file mode 100644 index 0000000..32553b4 --- /dev/null +++ b/tests/filters/test_clean.py @@ -0,0 +1,12 @@ +import pytest + +import resumejson_converter.filters as filters + + +def test_clean_no_parameter(): + with pytest.raises(TypeError): + filters.clean() + + +def test_clean(): + assert filters.clean("0011223344") == "00 11 22 33 44" diff --git a/tests/filters/test_datediff.py b/tests/filters/test_datediff.py new file mode 100644 index 0000000..845330b --- /dev/null +++ b/tests/filters/test_datediff.py @@ -0,0 +1,84 @@ +import pytest + +import resumejson_converter.filters as filters + + +def test_datediff_only_one_parameter(): + with pytest.raises(TypeError): + filters.datediff() + + +def test_datediff_only_one_parameter(): + with pytest.raises(TypeError): + filters.datediff("Hello World") + + +def test_datediff_only_two_parameter(): + with pytest.raises(TypeError): + filters.datediff("Hello World", "2019-01-02") + + +def test_datediff_false_end_date(): + with pytest.raises(ValueError): + filters.datediff("Hello", "2019-01-02", "2019-01-02d") + + +def test_datediff_false_start_date(): + with pytest.raises(ValueError): + filters.datediff("Hello", "2019-01-02a", "2019-01-02") + + +def test_datediff_one_year(): + assert filters.datediff( + "Hello World!", + "2018-01-02", + "2019-01-03" + ) == "Hello World! - 1 an" + + +def test_datediff_two_year(): + assert filters.datediff( + "Hello World!", + "2017-01-02", + "2019-01-03" + ) == "Hello World! - 2 ans" + + +def test_datediff_two_years(): + assert filters.datediff( + "Hello World!", + "2017-01-02", + "2019-01-03" + ) == "Hello World! - 2 ans" + + +def test_datediff_one_month(): + assert filters.datediff( + "Hello World!", + "2019-01-02", + "2019-02-03" + ) == "Hello World! - 1 mois" + + +def test_datediff_one_week(): + assert filters.datediff( + "Hello World!", + "2019-01-01", + "2019-01-09" + ) == "Hello World! - 1 semaine" + + +def test_datediff_two_weeks(): + assert filters.datediff( + "Hello World!", + "2019-01-01", + "2019-01-16" + ) == "Hello World! - 2 semaines" + + +def test_datediff_two_days(): + assert filters.datediff( + "Hello World!", + "2019-01-02", + "2019-01-04" + ) == "Hello World! - 2 jours" diff --git a/tests/filters/test_dateedit.py b/tests/filters/test_dateedit.py new file mode 100644 index 0000000..5191b26 --- /dev/null +++ b/tests/filters/test_dateedit.py @@ -0,0 +1,30 @@ +import pytest + +import resumejson_converter.filters as filters + + +def test_dateedit_only_one_parameter(): + with pytest.raises(TypeError): + filters.dateedit() + + +def test_dateedit_only_one_parameter(): + with pytest.raises(TypeError): + filters.dateedit("2019-01-01") + + +def test_dateedit_false_date(): + with pytest.raises(ValueError): + filters.dateedit("2019-01-01i", "") + + +def test_dateedit_only_start_date(): + assert filters.dateedit("2019-01-01", "") == "2019 - Auj." + + +def test_dateedite_same_year(): + assert filters.dateedit("2019-01-01", "2019-02-02") == "2019" + + +def test_dateedit_start_date_and_end_date_different(): + assert filters.dateedit("2019-01-01", "2017-05-01") == "2019 - 2017" -- cgit v1.2.1