def test_strings_vs_ints(self): # This is potentially confusing; it would be nice to have two # separate methods, or a flag to control the interpretation of # the field when a string with no suffix is supplied. # "dx login" can supply this form self.assertEqual(normalize_time_input("1414141414"), 1414141414000) # interpreted as sec # find methods can supply this form self.assertEqual(normalize_time_input(1414141414000), 1414141414000) # interpreted as ms
def test_normalize_time_input(self): # TODO: Add tests for negative time inputs e.g. "-12345", -12345, "-5d" for i, o in ((12345678, 12345678), ("0", 0), ("12345678", 12345678), ("15s", 15 * 1000), ("1d", (24 * 60 * 60 * 1000)), ("0w", 0), ("2015-10-01", int(time.mktime(dateutil.parser.parse("2015-10-01").timetuple()) * 1000))): self.assertEqual(normalize_time_input(i), o) # Test default_unit='s' for i, o in ((12345678, 12345678 * 1000), ("12345678", 12345678 * 1000), ("15s", 15 * 1000), ("1d", (24 * 60 * 60 * 1000)), ("0w", 0), ("2015-10-01", int(time.mktime(dateutil.parser.parse("2015-10-01").timetuple()) * 1000))): self.assertEqual(normalize_time_input(i, default_unit='s'), o) with self.assertRaises(ValueError): normalize_time_input("1223*") with self.assertRaises(ValueError): normalize_time_input("12345", default_unit='h') with self.assertRaises(ValueError): normalize_time_input(12345, default_unit='h') with self.assertRaises(ValueError): normalize_time_input("1234.5678") with self.assertRaises(ValueError): normalize_time_input(1234.5678)
def test_normalize_time_input(self): # TODO: Add tests for negative time inputs e.g. "-12345", -12345, "-5d" for i, o in ( (12345678, 12345678), ("0", 0), ("12345678", 12345678), ("15s", 15 * 1000), ("1d", (24 * 60 * 60 * 1000)), ("0w", 0), ("2015-10-01", int( time.mktime(dateutil.parser.parse("2015-10-01").timetuple()) * 1000))): self.assertEqual(normalize_time_input(i), o) # Test default_unit='s' for i, o in ( (12345678, 12345678 * 1000), ("12345678", 12345678 * 1000), ("15s", 15 * 1000), ("1d", (24 * 60 * 60 * 1000)), ("0w", 0), ("2015-10-01", int( time.mktime(dateutil.parser.parse("2015-10-01").timetuple()) * 1000))): self.assertEqual(normalize_time_input(i, default_unit='s'), o) with self.assertRaises(ValueError): normalize_time_input("1223*") with self.assertRaises(ValueError): normalize_time_input("12345", default_unit='h') with self.assertRaises(ValueError): normalize_time_input(12345, default_unit='h') with self.assertRaises(ValueError): normalize_time_input("1234.5678") with self.assertRaises(ValueError): normalize_time_input(1234.5678)