redvox.tests.common.test_timesync API documentation
Description: tests for timesync

# Module `redvox.tests.common.test_timesync`

tests for timesync

Expand source code

    """
    tests for timesync
    """
    import unittest
    import contextlib
    import redvox.tests as tests
    from redvox.common import timesync as ts
    from redvox.common import api_reader
    from redvox.common.io import ReadFilter

    class TimesyncTest(unittest.TestCase):
        @classmethod
        def setUpClass(cls) -> None:
            with contextlib.redirect_stdout(None):
                result = api_reader.ApiReader(tests.TEST_DATA_DIR, structured_dir=False,
                                              read_filter=ReadFilter(station_ids={"1637680001"}))
                cls.timesync = ts.TimeSync().from_raw_packets(result.read_files_by_id("1637680001"))

        def test_num_tri_messages(self):
            self.assertEqual(self.timesync.num_tri_messages(), 14)

        def test_latencies(self):
            self.assertEqual(len(self.timesync.latencies()[0]), 14)
            self.assertEqual(self.timesync.latencies()[0][0], 74559.5)

        def test_offsets(self):
            self.assertEqual(len(self.timesync.offsets()[0]), 14)
            self.assertEqual(self.timesync.offsets()[0][0], -22907018.5)

        def test_best_latencies_per_exchange(self):
            ltncs = self.timesync.best_latency_per_exchange()
            self.assertEqual(len(ltncs), 14)
            self.assertEqual(ltncs[0], 74559.5)
            self.assertEqual(self.timesync.best_latency(), ltncs[2])

        def test_best_offsets_per_exchange(self):
            ofsts = self.timesync.best_offset_per_exchange()
            self.assertEqual(len(ofsts), 14)
            self.assertEqual(ofsts[0], -22907018.5)
            self.assertEqual(self.timesync.best_offset(), ofsts[2])

        def test_best_latency(self):
            self.assertEqual(self.timesync.best_latency(), 69664.0)
            self.assertEqual(self.timesync.best_latency_index(), 2)

        def test_best_offset(self):
            self.assertEqual(self.timesync.best_offset(), -22906528.0)

        def test_latency_mean(self):
            self.assertAlmostEqual(self.timesync.mean_latency(), 118049.66, 2)

        def test_latency_std_dev(self):
            self.assertAlmostEqual(self.timesync.latency_std(), 84458.71, 2)

        def test_offset_mean(self):
            self.assertAlmostEqual(self.timesync.mean_offset(), -22903096.02, 2)

        def test_offset_std_dev(self):
            self.assertAlmostEqual(self.timesync.offset_std(), 91847.39, 2)

        def test_best_latency_timestamp(self):
            self.assertEqual(self.timesync.get_best_latency_timestamp(), 1532459236518989.)

## Classes

`class TimesyncTest (methodName='runTest')`

  A class whose instances are single test cases.

  By default, the test code itself should be placed in a method named 'runTest'.

  If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.

  Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.

  If it is necessary to override the init method, the base class init method must always be called. It is important that subclasses should not change the signature of their init method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.

  When subclassing TestCase, you can set these attributes: * failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'. * longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed. * maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.

  Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

  Expand source code

      class TimesyncTest(unittest.TestCase):
          @classmethod
          def setUpClass(cls) -> None:
              with contextlib.redirect_stdout(None):
                  result = api_reader.ApiReader(tests.TEST_DATA_DIR, structured_dir=False,
                                                read_filter=ReadFilter(station_ids={"1637680001"}))
                  cls.timesync = ts.TimeSync().from_raw_packets(result.read_files_by_id("1637680001"))

          def test_num_tri_messages(self):
              self.assertEqual(self.timesync.num_tri_messages(), 14)

          def test_latencies(self):
              self.assertEqual(len(self.timesync.latencies()[0]), 14)
              self.assertEqual(self.timesync.latencies()[0][0], 74559.5)

          def test_offsets(self):
              self.assertEqual(len(self.timesync.offsets()[0]), 14)
              self.assertEqual(self.timesync.offsets()[0][0], -22907018.5)

          def test_best_latencies_per_exchange(self):
              ltncs = self.timesync.best_latency_per_exchange()
              self.assertEqual(len(ltncs), 14)
              self.assertEqual(ltncs[0], 74559.5)
              self.assertEqual(self.timesync.best_latency(), ltncs[2])

          def test_best_offsets_per_exchange(self):
              ofsts = self.timesync.best_offset_per_exchange()
              self.assertEqual(len(ofsts), 14)
              self.assertEqual(ofsts[0], -22907018.5)
              self.assertEqual(self.timesync.best_offset(), ofsts[2])

          def test_best_latency(self):
              self.assertEqual(self.timesync.best_latency(), 69664.0)
              self.assertEqual(self.timesync.best_latency_index(), 2)

          def test_best_offset(self):
              self.assertEqual(self.timesync.best_offset(), -22906528.0)

          def test_latency_mean(self):
              self.assertAlmostEqual(self.timesync.mean_latency(), 118049.66, 2)

          def test_latency_std_dev(self):
              self.assertAlmostEqual(self.timesync.latency_std(), 84458.71, 2)

          def test_offset_mean(self):
              self.assertAlmostEqual(self.timesync.mean_offset(), -22903096.02, 2)

          def test_offset_std_dev(self):
              self.assertAlmostEqual(self.timesync.offset_std(), 91847.39, 2)

          def test_best_latency_timestamp(self):
              self.assertEqual(self.timesync.get_best_latency_timestamp(), 1532459236518989.)

  ### Ancestors

  - unittest.case.TestCase

  ### Static methods

  `def setUpClass() ‑> None`

    Hook method for setting up class fixture before running tests in the class.

    Expand source code

        @classmethod
        def setUpClass(cls) -> None:
            with contextlib.redirect_stdout(None):
                result = api_reader.ApiReader(tests.TEST_DATA_DIR, structured_dir=False,
                                              read_filter=ReadFilter(station_ids={"1637680001"}))
                cls.timesync = ts.TimeSync().from_raw_packets(result.read_files_by_id("1637680001"))

  ### Methods

  `def test_best_latencies_per_exchange(self)`
    Expand source code

        def test_best_latencies_per_exchange(self):
            ltncs = self.timesync.best_latency_per_exchange()
            self.assertEqual(len(ltncs), 14)
            self.assertEqual(ltncs[0], 74559.5)
            self.assertEqual(self.timesync.best_latency(), ltncs[2])

  `def test_best_latency(self)`
    Expand source code

        def test_best_latency(self):
            self.assertEqual(self.timesync.best_latency(), 69664.0)
            self.assertEqual(self.timesync.best_latency_index(), 2)

  `def test_best_latency_timestamp(self)`
    Expand source code

        def test_best_latency_timestamp(self):
            self.assertEqual(self.timesync.get_best_latency_timestamp(), 1532459236518989.)

  `def test_best_offset(self)`
    Expand source code

        def test_best_offset(self):
            self.assertEqual(self.timesync.best_offset(), -22906528.0)

  `def test_best_offsets_per_exchange(self)`
    Expand source code

        def test_best_offsets_per_exchange(self):
            ofsts = self.timesync.best_offset_per_exchange()
            self.assertEqual(len(ofsts), 14)
            self.assertEqual(ofsts[0], -22907018.5)
            self.assertEqual(self.timesync.best_offset(), ofsts[2])

  `def test_latencies(self)`
    Expand source code

        def test_latencies(self):
            self.assertEqual(len(self.timesync.latencies()[0]), 14)
            self.assertEqual(self.timesync.latencies()[0][0], 74559.5)

  `def test_latency_mean(self)`
    Expand source code

        def test_latency_mean(self):
            self.assertAlmostEqual(self.timesync.mean_latency(), 118049.66, 2)

  `def test_latency_std_dev(self)`
    Expand source code

        def test_latency_std_dev(self):
            self.assertAlmostEqual(self.timesync.latency_std(), 84458.71, 2)

  `def test_num_tri_messages(self)`
    Expand source code

        def test_num_tri_messages(self):
            self.assertEqual(self.timesync.num_tri_messages(), 14)

  `def test_offset_mean(self)`
    Expand source code

        def test_offset_mean(self):
            self.assertAlmostEqual(self.timesync.mean_offset(), -22903096.02, 2)

  `def test_offset_std_dev(self)`
    Expand source code

        def test_offset_std_dev(self):
            self.assertAlmostEqual(self.timesync.offset_std(), 91847.39, 2)

  `def test_offsets(self)`
    Expand source code

        def test_offsets(self):
            self.assertEqual(len(self.timesync.offsets()[0]), 14)
            self.assertEqual(self.timesync.offsets()[0][0], -22907018.5)