diff options
-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 @@ | |||
1 | import pytest | ||
2 | |||
3 | from gnunet import strings | ||
4 | |||
5 | import locale | ||
6 | locale.setlocale(locale.LC_ALL, "en_US.UTF-8") | ||
7 | |||
8 | test_dates = ( | ||
9 | ("Sat Jan 07 19:54:12 2008", (2008, 1, 7, 19, 54, 12)), | ||
10 | ("Thu 27 Mar 2005 11:05:25 PM CET", (2005, 3, 27, 23, 5, 25)), | ||
11 | # FIXME: need test-case for %Ec | ||
12 | ("2019-02-23 16:07:22", (2019, 2, 23, 16, 7, 22)), | ||
13 | ("1998-08-17 14:33", (1998, 8, 17, 14, 33, 0)), | ||
14 | ("12/15/2007", (2007, 12, 15, 0, 0, 0)), | ||
15 | # FIXME: need test-case for %Ex | ||
16 | ("2019-02-26", (2019, 2, 26, 0, 0, 0)), | ||
17 | ("2014-03-23", (2014, 3, 23, 0, 0, 0)), | ||
18 | ("2020", (2020, 1, 1, 0, 0, 0)) | ||
19 | ) | ||
20 | |||
21 | @pytest.mark.parametrize("datestr,expected", test_dates) | ||
22 | def test_string_to_absolute_time(datestr, expected): | ||
23 | dt = strings.string_to_absolute_time(datestr) | ||
24 | assert dt.timetuple()[:6] == expected | ||
25 | |||
26 | def test_string_to_absolute_time_end_of_time(): | ||
27 | assert strings.string_to_absolute_time("end of time") is None | ||
28 | |||
29 | def test_string_to_absolute_invalid(): | ||
30 | with pytest.raises(ValueError) as excinfo: | ||
31 | strings.string_to_absolute_time("asdfgh") | ||
32 | assert str(excinfo.value).startswith("asdfgh is not a properly formatted") | ||