def test_rfc3339_to_nanoseconds_since_epoch_with_and_without_strptime(self):
        # Verify corectness between two different implementations of this function
        input_strs = [
            "2015-08-06T14:40:56.123456Z",
            "2015-08-06T14:40:56Z",
            "2015-08-06T14:40:56.123456789Z",
        ]
        expected_tss = [
            scalyr_util.microseconds_since_epoch(
                datetime.datetime(2015, 8, 6, 14, 40, 56, 123456)
            )
            * 1000,
            scalyr_util.microseconds_since_epoch(
                datetime.datetime(2015, 8, 6, 14, 40, 56)
            )
            * 1000,
            scalyr_util.microseconds_since_epoch(
                datetime.datetime(2015, 8, 6, 14, 40, 56, 123456)
            )
            * 1000
            + 789,
        ]

        for input_str, expected_ts in zip(input_strs, expected_tss):
            result_with_strptime = (
                date_parsing_utils._rfc3339_to_nanoseconds_since_epoch_strptime(
                    input_str
                )
            )
            result_without_strptime = scalyr_util.rfc3339_to_nanoseconds_since_epoch(
                input_str
            )

            self.assertEqual(result_with_strptime, expected_ts)
            self.assertEqual(result_with_strptime, result_without_strptime)
Пример #2
0
    def test_rfc3339_to_nanoseconds_since_epoch_no_fractions(self):
        s = "2015-08-06T14:40:56"
        expected = (scalyr_util.microseconds_since_epoch(
            datetime.datetime(2015, 8, 6, 14, 40, 56)) * 1000)
        actual = scalyr_util.rfc3339_to_nanoseconds_since_epoch(s)
        self.assertEquals(expected, actual)

        s = "2015-08-06T14:40:56Z"
        expected = (scalyr_util.microseconds_since_epoch(
            datetime.datetime(2015, 8, 6, 14, 40, 56)) * 1000)
        actual = scalyr_util.rfc3339_to_nanoseconds_since_epoch(s)
        self.assertEquals(expected, actual)
 def test_rfc3339_to_nanoseconds_since_epoch_strange_value(self):
     s = "2017-09-20T20:44:00.123456Z"
     expected = (
         scalyr_util.microseconds_since_epoch(
             datetime.datetime(2017, 9, 20, 20, 44, 00, 123456)
         )
         * 1000
     )
     actual = scalyr_util.rfc3339_to_nanoseconds_since_epoch(s)
     self.assertEquals(expected, actual)
Пример #4
0
 def test_microseconds_since_epoch( self ):
     dt = datetime.datetime( 2015, 8, 6, 14, 40, 56, 123456 )
     expected = 1438872056123456
     actual = scalyr_util.microseconds_since_epoch( dt )
     self.assertEquals( expected, actual )
Пример #5
0
 def test_rfc3339_to_nanoseconds_since_epoch_strange_value( self ):
     s = "2017-09-20T20:44:00.123456Z"
     expected =  scalyr_util.microseconds_since_epoch( datetime.datetime( 2017, 9, 20, 20, 44, 00, 123456 ) ) * 1000
     actual = scalyr_util.rfc3339_to_nanoseconds_since_epoch( s )
     self.assertEquals( expected, actual )
Пример #6
0
 def test_rfc3339_to_nanoseconds_since_epoch_too_many_fractions( self ):
     s = "2015-08-06T14:40:56.123456789999Z"
     expected =  scalyr_util.microseconds_since_epoch( datetime.datetime( 2015, 8, 6, 14, 40, 56, 123456 ) ) * 1000 + 789
     actual = scalyr_util.rfc3339_to_nanoseconds_since_epoch( s )
     self.assertEquals( expected, actual )
Пример #7
0
 def test_microseconds_since_epoch(self):
     dt = datetime.datetime(2015, 8, 6, 14, 40, 56, 123456)
     expected = 1438872056123456
     actual = scalyr_util.microseconds_since_epoch(dt)
     self.assertEquals(expected, actual)
Пример #8
0
 def test_rfc3339_to_nanoseconds_since_epoch_too_many_fractions( self ):
     s = "2015-08-06T14:40:56.123456789999Z"
     expected =  scalyr_util.microseconds_since_epoch( datetime.datetime( 2015, 8, 6, 14, 40, 56, 123456 ) ) * 1000 + 789
     actual = scalyr_util.rfc3339_to_nanoseconds_since_epoch( s )
     self.assertEquals( expected, actual )