示例#1
0
    def test_repr(self):
        datetime_repr, to_datetime_repr = t.DateTime(), t.ToDateTime()
        assert repr(datetime_repr) == '<DateTime %Y-%m-%d %H:%M:%S>'
        assert repr(to_datetime_repr) == '<ToDateTime %Y-%m-%d %H:%M:%S>'

        datetime_repr, to_datetime_repr = t.DateTime('%Y-%m-%d %H:%M'), t.ToDateTime('%Y-%m-%d %H:%M')
        assert repr(datetime_repr) == '<DateTime %Y-%m-%d %H:%M>'
        assert repr(to_datetime_repr) == '<ToDateTime %Y-%m-%d %H:%M>'
示例#2
0
 def test_datetime(self):
     now = datetime(year=2019, month=7, day=25, hour=21, minute=45)
     res = t.DateTime('%Y-%m-%d %H:%M').check(now)
     assert res == now
     res = t.DateTime('%Y-%m-%d %H:%M').check("2019-07-25 21:45")
     assert res == '2019-07-25 21:45'
     res = extract_error(t.DateTime(), "25-07-2019")
     assert res == 'value does not match format %Y-%m-%d %H:%M:%S'
     res = extract_error(t.DateTime(), 1564077758)
     assert res == 'value cannot be converted to datetime'