Mercurial > libervia-backend
comparison tests/unit/test_plugin_xep_0082.py @ 4285:f1d0cde61af7
tests (unit): fix tests + black reformatting.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 14 Jul 2024 17:42:53 +0200 |
parents | 4b842c1fb686 |
children |
comparison
equal
deleted
inserted
replaced
4284:3a550e9a2b55 | 4285:f1d0cde61af7 |
---|---|
28 "test_date_formatting", | 28 "test_date_formatting", |
29 "test_date_parsing", | 29 "test_date_parsing", |
30 "test_datetime_formatting", | 30 "test_datetime_formatting", |
31 "test_datetime_parsing", | 31 "test_datetime_parsing", |
32 "test_time_formatting", | 32 "test_time_formatting", |
33 "test_time_parsing" | 33 "test_time_parsing", |
34 ] | 34 ] |
35 | 35 |
36 | 36 |
37 def test_date_formatting() -> None: # pylint: disable=missing-function-docstring | 37 def test_date_formatting() -> None: # pylint: disable=missing-function-docstring |
38 # The following tests don't check the output of format_date directly; instead, they | 38 # The following tests don't check the output of format_date directly; instead, they |
83 | 83 |
84 # Check that a datetime instance is returned when format_datetime is called without an | 84 # Check that a datetime instance is returned when format_datetime is called without an |
85 # explicit input | 85 # explicit input |
86 # datetime | 86 # datetime |
87 assert isinstance(XEP_0082.parse_datetime(XEP_0082.format_datetime()), datetime) | 87 assert isinstance(XEP_0082.parse_datetime(XEP_0082.format_datetime()), datetime) |
88 assert isinstance(XEP_0082.parse_datetime(XEP_0082.format_datetime( | 88 assert isinstance( |
89 include_microsecond=True | 89 XEP_0082.parse_datetime(XEP_0082.format_datetime(include_microsecond=True)), |
90 )), datetime) | 90 datetime, |
91 ) | |
91 assert XEP_0082.parse_datetime(XEP_0082.format_datetime()).tzinfo == timezone.utc | 92 assert XEP_0082.parse_datetime(XEP_0082.format_datetime()).tzinfo == timezone.utc |
92 | 93 |
93 | 94 |
94 def test_datetime_parsing() -> None: # pylint: disable=missing-function-docstring | 95 def test_datetime_parsing() -> None: # pylint: disable=missing-function-docstring |
95 # Datetime of the first human steps on the Moon (UTC) | 96 # Datetime of the first human steps on the Moon (UTC) |
107 # Without timezone, without a fraction of a second | 108 # Without timezone, without a fraction of a second |
108 with pytest.raises(exceptions.ParsingError): | 109 with pytest.raises(exceptions.ParsingError): |
109 XEP_0082.parse_datetime("1969-07-21T02:56:15") | 110 XEP_0082.parse_datetime("1969-07-21T02:56:15") |
110 | 111 |
111 # With timezone 'Z', with a fraction of a second consisting of two digits | 112 # With timezone 'Z', with a fraction of a second consisting of two digits |
112 assert XEP_0082.parse_datetime("1969-07-21T02:56:15.12Z") == \ | 113 assert XEP_0082.parse_datetime("1969-07-21T02:56:15.12Z") == value.replace( |
113 value.replace(microsecond=120000) | 114 microsecond=120000 |
115 ) | |
114 | 116 |
115 # With timezone 'Z', with a fraction of a second consisting of nine digits | 117 # With timezone 'Z', with a fraction of a second consisting of nine digits |
116 assert XEP_0082.parse_datetime("1969-07-21T02:56:15.123456789Z") == \ | 118 assert XEP_0082.parse_datetime("1969-07-21T02:56:15.123456789Z") == value.replace( |
117 value.replace(microsecond=123456) | 119 microsecond=123456 |
120 ) | |
118 | 121 |
119 # With timezone '+04:00', with a fraction of a second consisting of six digits | 122 # With timezone '+04:00', with a fraction of a second consisting of six digits |
120 assert XEP_0082.parse_datetime("1969-07-21T06:56:15.123456+04:00") == \ | 123 assert XEP_0082.parse_datetime("1969-07-21T06:56:15.123456+04:00") == value.replace( |
121 value.replace(microsecond=123456) | 124 microsecond=123456 |
125 ) | |
122 | 126 |
123 # With timezone '-05:00', with a fraction of a second consisting of zero digits | 127 # With timezone '-05:00', with a fraction of a second consisting of zero digits |
124 assert XEP_0082.parse_datetime("1969-07-20T21:56:15.-05:00") == value | 128 assert XEP_0082.parse_datetime("1969-07-20T21:56:15.-05:00") == value |
125 | 129 |
126 # Without timezone, with a fraction of a second consisting of six digits | 130 # Without timezone, with a fraction of a second consisting of six digits |
160 assert XEP_0082.parse_time(XEP_0082.format_time(value)).tzinfo is None | 164 assert XEP_0082.parse_time(XEP_0082.format_time(value)).tzinfo is None |
161 | 165 |
162 # Check that a time instance is returned when format_time is called without an | 166 # Check that a time instance is returned when format_time is called without an |
163 # explicit input date | 167 # explicit input date |
164 assert isinstance(XEP_0082.parse_time(XEP_0082.format_time()), time) | 168 assert isinstance(XEP_0082.parse_time(XEP_0082.format_time()), time) |
165 assert isinstance(XEP_0082.parse_time(XEP_0082.format_time( | 169 assert isinstance( |
166 include_microsecond=True | 170 XEP_0082.parse_time(XEP_0082.format_time(include_microsecond=True)), time |
167 )), time) | 171 ) |
168 assert XEP_0082.parse_time(XEP_0082.format_time()).tzinfo == timezone.utc | 172 assert XEP_0082.parse_time(XEP_0082.format_time()).tzinfo == timezone.utc |
169 | 173 |
170 | 174 |
171 def test_time_parsing() -> None: # pylint: disable=missing-function-docstring | 175 def test_time_parsing() -> None: # pylint: disable=missing-function-docstring |
172 # Time for tea | 176 # Time for tea |
189 | 193 |
190 # With timezone 'Z', with a fraction of a second consisting of nine digits | 194 # With timezone 'Z', with a fraction of a second consisting of nine digits |
191 assert XEP_0082.parse_time("16:00:00.123456789Z") == value.replace(microsecond=123456) | 195 assert XEP_0082.parse_time("16:00:00.123456789Z") == value.replace(microsecond=123456) |
192 | 196 |
193 # With timezone '+04:00', with a fraction of a second consisting of six digits | 197 # With timezone '+04:00', with a fraction of a second consisting of six digits |
194 assert XEP_0082.parse_time("20:00:00.123456+04:00") == \ | 198 assert XEP_0082.parse_time("20:00:00.123456+04:00") == value.replace( |
195 value.replace(microsecond=123456) | 199 microsecond=123456 |
200 ) | |
196 | 201 |
197 # With timezone '-05:00', with a fraction of a second consisting of zero digits | 202 # With timezone '-05:00', with a fraction of a second consisting of zero digits |
198 assert XEP_0082.parse_time("11:00:00.-05:00") == value | 203 assert XEP_0082.parse_time("11:00:00.-05:00") == value |
199 | 204 |
200 # Without a timezone, with a fraction of a second consisting of six digits | 205 # Without a timezone, with a fraction of a second consisting of six digits |
201 assert XEP_0082.parse_time("16:00:00.123456") == \ | 206 assert XEP_0082.parse_time("16:00:00.123456") == value.replace( |
202 value.replace(microsecond=123456, tzinfo=None) | 207 microsecond=123456, tzinfo=None |
208 ) |