MCPcopy Create free account
hub / github.com/dateutil/dateutil / TestInputTypes

Class TestInputTypes

tests/test_parser.py:292–347  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

290
291
292class TestInputTypes:
293 def test_empty_string_invalid(self):
294 with pytest.raises(ParserError):
295 parse('')
296
297 def test_none_invalid(self):
298 with pytest.raises(TypeError):
299 parse(None)
300
301 def test_int_invalid(self):
302 with pytest.raises(TypeError):
303 parse(13)
304
305 def test_duck_typing(self):
306 # We want to support arbitrary classes that implement the stream
307 # interface.
308
309 class StringPassThrough:
310 def __init__(self, stream):
311 self.stream = stream
312
313 def read(self, *args, **kwargs):
314 return self.stream.read(*args, **kwargs)
315
316 dstr = StringPassThrough(StringIO('2014 January 19'))
317
318 res = parse(dstr)
319 expected = datetime(2014, 1, 19)
320 assert res == expected
321
322 def test_parse_stream(self):
323 dstr = StringIO('2014 January 19')
324
325 res = parse(dstr)
326 expected = datetime(2014, 1, 19)
327 assert res == expected
328
329 def test_parse_str(self):
330 # Parser should be able to handle bytestring and unicode
331 uni_str = '2014-05-01 08:00:00'
332 bytes_str = uni_str.encode()
333
334 res = parse(bytes_str)
335 expected = parse(uni_str)
336 assert res == expected
337
338 def test_parse_bytes(self):
339 res = parse(b'2014 January 19')
340 expected = datetime(2014, 1, 19)
341 assert res == expected
342
343 def test_parse_bytearray(self):
344 # GH#417
345 res = parse(bytearray(b'2014 January 19'))
346 expected = datetime(2014, 1, 19)
347 assert res == expected
348
349

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected