Ejemplo n.º 1
0
 def test_formated(self):
     da = argument.DateArgument(parsed_name='--date')
     self.assertEqual(da.formated, None)
     date, format, exp = ('24-10-1917', '%d-%m-%Y',
                          'Wed Oct 24 00:00:00 1917')
     da._value = argument.dtm.strptime(date, format)
     self.assertEqual(da.formated, exp)
Ejemplo n.º 2
0
 def test_value(self):
     da = argument.DateArgument(parsed_name='--date')
     try:
         da.value = 'Something'
         self.assertFalse('CLIInvalidArgument error not raised!')
     except Exception as e:
         self.assertTrue(isinstance(e, errors.CLIInvalidArgument))
     da.value = '10/02/2001'
     self.assertEqual(da.value, da.timestamp)
     self.assertEqual(da.timestamp, 1001970000.0)
     self.assertEqual(da.formated, 'Tue Oct 02 00:00:00 2001')
     self.assertEqual(da.isoformat, '2001-10-02T00:00:00+03:00')
Ejemplo n.º 3
0
 def test_format_date(self):
     da = argument.DateArgument(parsed_name='--date')
     for datestr, exp in (('Wed Oct 24 01:02:03 1917',
                           datetime(1917, 10, 24, 1, 2,
                                    3)), ('24-10-1917',
                                          datetime(1917, 10, 24)),
                          ('01:02:03 24-10-1917',
                           datetime(1917, 10, 24, 1, 2, 3))):
         self.assertEqual(da.format_date(datestr), exp)
     for datestr, err in (('32-40-20134', errors.CLIError),
                          ('Wednesday, 24 Oct 2017', errors.CLIError),
                          (None, TypeError), (0.8, TypeError)):
         self.assertRaises(err, da.format_date, datestr)
Ejemplo n.º 4
0
 def test_timestamp(self):
     da = argument.DateArgument(parsed_name='--date')
     self.assertEqual(da.timestamp, None)
     date, format, exp = '24-10-1917', '%d-%m-%Y', -1646964000.0
     da._value = argument.dtm.strptime(date, format)
     self.assertEqual(da.timestamp, exp)