diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 80b432599f1bcc7ca28fc6669da02657c02bf7c3..dcc7891582be1a453a89a7589d4d5ea7e779c045 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,10 +3,14 @@ image: python:3-buster before_script: - pip install -r requirements-dev.txt -test: +analyze: script: - bandit whatformat/*.py whatformat/util/*.py - flake8 --config=.flake8 whatformat/*.py whatformat/util/*.py - mypy whatformat/*.py whatformat/util/*.py - pydocstyle whatformat/*.py whatformat/util/*.py - pylint whatformat/*.py whatformat/util/*.py + +test: + script: + - python3 -m unittest diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/util/__init__.py b/tests/util/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/util/test_whatdateformat.py b/tests/util/test_whatdateformat.py new file mode 100644 index 0000000000000000000000000000000000000000..1db22d6b0c982b90582b25aa3c2fbcba5b4e17f0 --- /dev/null +++ b/tests/util/test_whatdateformat.py @@ -0,0 +1,45 @@ +"""Tests for util.whatdateformat.""" + +import unittest +from whatformat.util.whatdateformat import get_unique_format_strings + + +class WhatDateFormatTests(unittest.TestCase): + """Tests for util.whatdateformat.""" + + def test_get_unique_format_strings(self): + """Test for util.whatdateformat.get_unique_format_strings().""" + cases = [ + ('Jan 2', ['%b %-d']), + ('Jan 15', ['%b %d']), + ('1-2-1999', ['%-m-%-d-%Y']), + ('1.2.1999', ['%-m.%-d.%Y']), + ('1.2.1999.', ['%-m.%-d.%Y.']), + ('1/2/1999', ['%-m/%-d/%Y']), + ('1999.1.2', ['%Y.%-m.%-d']), + ('1999-1-2', ['%Y-%-m-%-d']), + ('1999. 2. 1', ['%Y. %-m. %-d']), + ('1999.2.1', ['%Y.%-m.%-d']), + ('1999/2/1', ['%Y/%-m/%-d']), + ('28-11-1999', ['%d-%m-%Y']), + ('28.11.1999', ['%d.%m.%Y']), + ('28.11.1999.', ['%d.%m.%Y.']), + ('28/11/1999', ['%d/%m/%Y']), + ('11.28.1999', ['%m.%d.%Y']), + ('11/28/1999', ['%m/%d/%Y']), + ('11-28-1999', ['%m-%d-%Y']), + ('1-28-1999', ['%-m-%d-%Y']), + ('1.28.1999', ['%-m.%d.%Y']), + ('1.28.1999.', ['%-m.%d.%Y.']), + ('1/28/1999', ['%-m/%d/%Y']), + ('11-28-1999', ['%m-%d-%Y']), + ('11/28/1999', ['%m/%d/%Y']), + ('1999-11-28', ['%Y-%m-%d']), + ('1999.11.28.', ['%Y.%m.%d.']), + ('1999/11/28', ['%Y/%m/%d']), + ('ayy lmao', []), + ('', []), + ] + for (date, formats) in cases: + self.assertEqual(set(get_unique_format_strings(date)), + set(formats))