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

Class TestInputTypes

tests/test_parser.py:294–349  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected