Beispiel #1
0
def test_invalid_time_string():
    with pytest.raises(tf.errors.InvalidArgumentError):
        text.parse_time(
            time_string="INVALID",
            time_format="%Y-%m-%dT%H:%M:%E*S%Ez",
            output_unit="SECOND",
        )
Beispiel #2
0
def test_invalid_time_format():
    with pytest.raises(tf.errors.InvalidArgumentError):
        text.parse_time(
            time_string="2019-05-17T23:56:09.05Z",
            time_format="INVALID",
            output_unit="SECOND",
        )
Beispiel #3
0
 def test_invalid_output_unit(self):
     errors = (ValueError, tf.errors.InvalidArgumentError)
     with self.assertRaises(errors):
         text.parse_time(
             time_string="2019-05-17T23:56:09.05Z",
             time_format="%Y-%m-%dT%H:%M:%E*S%Ez",
             output_unit="INVALID")
Beispiel #4
0
def test_parse_time():
    time_format = "%Y-%m-%dT%H:%M:%E*S%Ez"
    items = [
        ("2019-05-17T23:56:09.05Z", time_format, "NANOSECOND",
         1558137369050000000),
        ("2019-05-17T23:56:09.05Z", time_format, "MICROSECOND",
         1558137369050000),
        ("2019-05-17T23:56:09.05Z", time_format, "MILLISECOND", 1558137369050),
        ("2019-05-17T23:56:09.05Z", time_format, "SECOND", 1558137369),
        (
            [
                "2019-05-17T23:56:09.05Z",
                "2019-05-20T11:22:33.44Z",
                "2019-05-30T22:33:44.55Z",
            ],
            time_format,
            "MILLISECOND",
            [1558137369050, 1558351353440, 1559255624550],
        ),
    ]
    for time_string, time_format, output_unit, expected in items:
        result = text.parse_time(
            time_string=time_string,
            time_format=time_format,
            output_unit=output_unit,
        )
        np.testing.assert_equal(expected, result.numpy())
Beispiel #5
0
 def test_invalid_time_string(self):
     with self.assertRaises(tf.errors.InvalidArgumentError):
         self.evaluate(
             text.parse_time(
                 time_string="INVALID",
                 time_format="%Y-%m-%dT%H:%M:%E*S%Ez",
                 output_unit="SECOND"))
Beispiel #6
0
 def test_invalid_time_format(self):
     with self.assertRaises(tf.errors.InvalidArgumentError):
         self.evaluate(
             text.parse_time(
                 time_string="2019-05-17T23:56:09.05Z",
                 time_format="INVALID",
                 output_unit="SECOND"))