Пример #1
0
 def test_value_from_str(self):
     """
     Makes sure that a string can be converted to a datetime.
     """
     key = TimestampKey("test")
     self.assertEqual(key.value_from_str(self._datetime_string),
                      self._datetime)
     self.assertEqual(key.value_from_str(unicode(self._datetime_string)),
                      self._datetime)
Пример #2
0
 def test_value_from_str(self):
     """
     Makes sure that a string can be converted to a datetime.
     """
     key = TimestampKey("test")
     self.assertEqual(
         key.value_from_str(self._datetime_string),
         self._datetime
     )
     self.assertEqual(
         key.value_from_str(unicode(self._datetime_string)),
         self._datetime
     )
Пример #3
0
    def test_bad_str(self):
        """
        Test with strings that don't match the specified format.
        """
        key = TimestampKey("test")
        # bad format
        with self.assertRaisesRegex(TankError, "Invalid string"):
            key.value_from_str("1 2 3")
        # out of bound values
        with self.assertRaisesRegex(TankError, "Invalid string"):
            key.value_from_str("2015-06-33-21-20-30")

        # Too much data
        with self.assertRaisesRegex(TankError, "Invalid string"):
            key.value_from_str(self._datetime_string + "bad date")
Пример #4
0
    def test_bad_str(self):
        """
        Test with strings that don't match the specified format.
        """
        key = TimestampKey("test")
        # bad format
        with self.assertRaisesRegex(TankError, "Invalid string"):
            key.value_from_str("1 2 3")
        # out of bound values
        with self.assertRaisesRegex(TankError, "Invalid string"):
            key.value_from_str("2015-06-33-21-20-30")

        # Too much data
        with self.assertRaisesRegex(TankError, "Invalid string"):
            key.value_from_str(self._datetime_string + "bad date")