diff options
author | Hartmut Goebel <h.goebel@crazy-compilers.com> | 2019-01-19 21:24:22 +0100 |
---|---|---|
committer | Hartmut Goebel <h.goebel@crazy-compilers.com> | 2019-01-19 21:24:22 +0100 |
commit | a755de67aece9b1d1e4564fb5fd3eeed5cc542fa (patch) | |
tree | 1dc91856aac9ed868cd07f3c30646f7e02aa50d6 | |
parent | 87ecb652bf4abaac99b104a3dcbb49721d758ff3 (diff) |
Add test-cases for strings.string_to_absolute_time.
-rw-r--r-- | tests/unit/test_strings.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/unit/test_strings.py b/tests/unit/test_strings.py new file mode 100644 index 0000000..a0b5617 --- /dev/null +++ b/tests/unit/test_strings.py @@ -0,0 +1,32 @@ +import pytest + +from gnunet import strings + +import locale +locale.setlocale(locale.LC_ALL, "en_US.UTF-8") + +test_dates = ( + ("Sat Jan 07 19:54:12 2008", (2008, 1, 7, 19, 54, 12)), + ("Thu 27 Mar 2005 11:05:25 PM CET", (2005, 3, 27, 23, 5, 25)), + # FIXME: need test-case for %Ec + ("2019-02-23 16:07:22", (2019, 2, 23, 16, 7, 22)), + ("1998-08-17 14:33", (1998, 8, 17, 14, 33, 0)), + ("12/15/2007", (2007, 12, 15, 0, 0, 0)), + # FIXME: need test-case for %Ex + ("2019-02-26", (2019, 2, 26, 0, 0, 0)), + ("2014-03-23", (2014, 3, 23, 0, 0, 0)), + ("2020", (2020, 1, 1, 0, 0, 0)) + ) + +@pytest.mark.parametrize("datestr,expected", test_dates) +def test_string_to_absolute_time(datestr, expected): + dt = strings.string_to_absolute_time(datestr) + assert dt.timetuple()[:6] == expected + +def test_string_to_absolute_time_end_of_time(): + assert strings.string_to_absolute_time("end of time") is None + +def test_string_to_absolute_invalid(): + with pytest.raises(ValueError) as excinfo: + strings.string_to_absolute_time("asdfgh") + assert str(excinfo.value).startswith("asdfgh is not a properly formatted") |