redvox.tests.api1000.test_sensors API documentation

# Module `redvox.tests.api1000.test_sensors`

Expand source code

    import unittest
    import numpy as np
    import redvox.api1000.wrapped_redvox_packet.sensors.sensors as sensor
    from redvox.api1000.common.common import Unit

    class TestSensor(unittest.TestCase):
        def setUp(self) -> None:
            self.empty_sensors: sensor.Sensors = sensor.Sensors.new()
            self.non_empty_sensors: sensor.Sensors = sensor.Sensors.new()
            self.non_empty_sensors.new_audio()
            self.non_empty_sensors.get_audio().get_samples().set_values(np.array([.1000, .50, .1025], dtype=int))
            self.non_empty_sensors.get_audio().set_sample_rate(80.0)
            self.non_empty_sensors.get_audio().set_first_sample_timestamp(1)
            self.non_empty_sensors.new_location()
            # self.non_empty_sensors.get_location().get_timestamps().set_default_unit()
            self.non_empty_sensors.get_location().get_timestamps().set_timestamps(np.array([1000, 2000, 3500, 5000]), True)
            self.non_empty_sensors.get_location().get_latitude_samples().set_values(np.array([0, 1, 1, 0]), True)
            self.non_empty_sensors.get_location().get_longitude_samples().set_values(np.array([1, 1, 0, 0]), True)
            self.non_empty_sensors.get_location().get_altitude_samples().set_values(np.array([0, 1, 2, 3]), True)
            self.non_empty_sensors.get_location().get_speed_samples().set_values(np.array([0, 0, 1, 0]), True)
            self.non_empty_sensors.get_location().get_bearing_samples().set_values(np.array([0, 90, 180, 270]), True)
            self.non_empty_sensors.get_location().get_horizontal_accuracy_samples().set_values(np.array([10, 10, 10, 10]),
                                                                                               True)
            self.non_empty_sensors.get_location().get_vertical_accuracy_samples().set_values(np.array([10, 10, 10, 10]),
                                                                                             True)
            self.non_empty_sensors.get_location().get_speed_accuracy_samples().set_values(np.array([10, 10, 10, 10]), True)
            self.non_empty_sensors.get_location().get_bearing_accuracy_samples().set_values(np.array([10, 10, 10, 10]),
                                                                                            True)
            self.non_empty_sensors.new_pressure()
            self.non_empty_sensors.get_pressure().set_sensor_description("Barometer")
            self.non_empty_sensors.get_pressure().get_timestamps().set_timestamps(np.array([1000, 2000, 3500, 5000]), True)
            self.non_empty_sensors.get_pressure().get_samples().set_values(np.array([100, 101, 102, 103]), True)
            self.non_empty_sensors.new_gyroscope()
            self.non_empty_sensors.get_gyroscope().set_sensor_description("Gyroscope")
            self.non_empty_sensors.get_gyroscope().get_timestamps().set_timestamps(np.array([1000, 2000, 3500, 5000]), True)
            self.non_empty_sensors.get_gyroscope().get_x_samples().set_values(np.array([0, 1, 2, 3]), True)
            self.non_empty_sensors.get_gyroscope().get_y_samples().set_values(np.array([3, 2, 1, 0]), True)
            self.non_empty_sensors.get_gyroscope().get_z_samples().set_values(np.array([0, 1, 2, 3]), True)

        def test_non_empty_sensor(self):
            self.assertEqual(self.non_empty_sensors.get_location().get_timestamps().get_timestamps()[0], 1000)
            self.assertEqual(self.non_empty_sensors.get_gyroscope().get_x_samples().get_unit(), Unit["RADIANS_PER_SECOND"])
            self.assertEqual(self.non_empty_sensors.get_relative_humidity(), None)
            self.non_empty_sensors.remove_gyroscope()
            self.assertEqual(self.non_empty_sensors.get_gyroscope(), None)
            self.assertFalse(self.non_empty_sensors.validate_velocity())
            self.assertTrue(self.non_empty_sensors.validate_audio())
            self.assertEqual(len(sensor.validate_sensors(self.non_empty_sensors)), 0)

        # todo: location sensors need to have best locations validated
        # def test_validate_sensors(self):
        #     error_list = sensor.validate_sensors(self.non_empty_sensors)
        #     self.assertEqual(error_list, [])
        #     error_list = sensor.validate_sensors(self.empty_sensors)
        #     self.assertNotEqual(error_list, [])

## Classes

`class TestSensor (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 TestSensor(unittest.TestCase):
          def setUp(self) -> None:
              self.empty_sensors: sensor.Sensors = sensor.Sensors.new()
              self.non_empty_sensors: sensor.Sensors = sensor.Sensors.new()
              self.non_empty_sensors.new_audio()
              self.non_empty_sensors.get_audio().get_samples().set_values(np.array([.1000, .50, .1025], dtype=int))
              self.non_empty_sensors.get_audio().set_sample_rate(80.0)
              self.non_empty_sensors.get_audio().set_first_sample_timestamp(1)
              self.non_empty_sensors.new_location()
              # self.non_empty_sensors.get_location().get_timestamps().set_default_unit()
              self.non_empty_sensors.get_location().get_timestamps().set_timestamps(np.array([1000, 2000, 3500, 5000]), True)
              self.non_empty_sensors.get_location().get_latitude_samples().set_values(np.array([0, 1, 1, 0]), True)
              self.non_empty_sensors.get_location().get_longitude_samples().set_values(np.array([1, 1, 0, 0]), True)
              self.non_empty_sensors.get_location().get_altitude_samples().set_values(np.array([0, 1, 2, 3]), True)
              self.non_empty_sensors.get_location().get_speed_samples().set_values(np.array([0, 0, 1, 0]), True)
              self.non_empty_sensors.get_location().get_bearing_samples().set_values(np.array([0, 90, 180, 270]), True)
              self.non_empty_sensors.get_location().get_horizontal_accuracy_samples().set_values(np.array([10, 10, 10, 10]),
                                                                                                 True)
              self.non_empty_sensors.get_location().get_vertical_accuracy_samples().set_values(np.array([10, 10, 10, 10]),
                                                                                               True)
              self.non_empty_sensors.get_location().get_speed_accuracy_samples().set_values(np.array([10, 10, 10, 10]), True)
              self.non_empty_sensors.get_location().get_bearing_accuracy_samples().set_values(np.array([10, 10, 10, 10]),
                                                                                              True)
              self.non_empty_sensors.new_pressure()
              self.non_empty_sensors.get_pressure().set_sensor_description("Barometer")
              self.non_empty_sensors.get_pressure().get_timestamps().set_timestamps(np.array([1000, 2000, 3500, 5000]), True)
              self.non_empty_sensors.get_pressure().get_samples().set_values(np.array([100, 101, 102, 103]), True)
              self.non_empty_sensors.new_gyroscope()
              self.non_empty_sensors.get_gyroscope().set_sensor_description("Gyroscope")
              self.non_empty_sensors.get_gyroscope().get_timestamps().set_timestamps(np.array([1000, 2000, 3500, 5000]), True)
              self.non_empty_sensors.get_gyroscope().get_x_samples().set_values(np.array([0, 1, 2, 3]), True)
              self.non_empty_sensors.get_gyroscope().get_y_samples().set_values(np.array([3, 2, 1, 0]), True)
              self.non_empty_sensors.get_gyroscope().get_z_samples().set_values(np.array([0, 1, 2, 3]), True)

          def test_non_empty_sensor(self):
              self.assertEqual(self.non_empty_sensors.get_location().get_timestamps().get_timestamps()[0], 1000)
              self.assertEqual(self.non_empty_sensors.get_gyroscope().get_x_samples().get_unit(), Unit["RADIANS_PER_SECOND"])
              self.assertEqual(self.non_empty_sensors.get_relative_humidity(), None)
              self.non_empty_sensors.remove_gyroscope()
              self.assertEqual(self.non_empty_sensors.get_gyroscope(), None)
              self.assertFalse(self.non_empty_sensors.validate_velocity())
              self.assertTrue(self.non_empty_sensors.validate_audio())
              self.assertEqual(len(sensor.validate_sensors(self.non_empty_sensors)), 0)

          # todo: location sensors need to have best locations validated
          # def test_validate_sensors(self):
          #     error_list = sensor.validate_sensors(self.non_empty_sensors)
          #     self.assertEqual(error_list, [])
          #     error_list = sensor.validate_sensors(self.empty_sensors)
          #     self.assertNotEqual(error_list, [])

  ### Ancestors

  - unittest.case.TestCase

  ### Methods

  `def setUp(self) ‑> NoneType`

    Hook method for setting up the test fixture before exercising it.

    Expand source code

        def setUp(self) -> None:
            self.empty_sensors: sensor.Sensors = sensor.Sensors.new()
            self.non_empty_sensors: sensor.Sensors = sensor.Sensors.new()
            self.non_empty_sensors.new_audio()
            self.non_empty_sensors.get_audio().get_samples().set_values(np.array([.1000, .50, .1025], dtype=int))
            self.non_empty_sensors.get_audio().set_sample_rate(80.0)
            self.non_empty_sensors.get_audio().set_first_sample_timestamp(1)
            self.non_empty_sensors.new_location()
            # self.non_empty_sensors.get_location().get_timestamps().set_default_unit()
            self.non_empty_sensors.get_location().get_timestamps().set_timestamps(np.array([1000, 2000, 3500, 5000]), True)
            self.non_empty_sensors.get_location().get_latitude_samples().set_values(np.array([0, 1, 1, 0]), True)
            self.non_empty_sensors.get_location().get_longitude_samples().set_values(np.array([1, 1, 0, 0]), True)
            self.non_empty_sensors.get_location().get_altitude_samples().set_values(np.array([0, 1, 2, 3]), True)
            self.non_empty_sensors.get_location().get_speed_samples().set_values(np.array([0, 0, 1, 0]), True)
            self.non_empty_sensors.get_location().get_bearing_samples().set_values(np.array([0, 90, 180, 270]), True)
            self.non_empty_sensors.get_location().get_horizontal_accuracy_samples().set_values(np.array([10, 10, 10, 10]),
                                                                                               True)
            self.non_empty_sensors.get_location().get_vertical_accuracy_samples().set_values(np.array([10, 10, 10, 10]),
                                                                                             True)
            self.non_empty_sensors.get_location().get_speed_accuracy_samples().set_values(np.array([10, 10, 10, 10]), True)
            self.non_empty_sensors.get_location().get_bearing_accuracy_samples().set_values(np.array([10, 10, 10, 10]),
                                                                                            True)
            self.non_empty_sensors.new_pressure()
            self.non_empty_sensors.get_pressure().set_sensor_description("Barometer")
            self.non_empty_sensors.get_pressure().get_timestamps().set_timestamps(np.array([1000, 2000, 3500, 5000]), True)
            self.non_empty_sensors.get_pressure().get_samples().set_values(np.array([100, 101, 102, 103]), True)
            self.non_empty_sensors.new_gyroscope()
            self.non_empty_sensors.get_gyroscope().set_sensor_description("Gyroscope")
            self.non_empty_sensors.get_gyroscope().get_timestamps().set_timestamps(np.array([1000, 2000, 3500, 5000]), True)
            self.non_empty_sensors.get_gyroscope().get_x_samples().set_values(np.array([0, 1, 2, 3]), True)
            self.non_empty_sensors.get_gyroscope().get_y_samples().set_values(np.array([3, 2, 1, 0]), True)
            self.non_empty_sensors.get_gyroscope().get_z_samples().set_values(np.array([0, 1, 2, 3]), True)

  `def test_non_empty_sensor(self)`
    Expand source code

        def test_non_empty_sensor(self):
            self.assertEqual(self.non_empty_sensors.get_location().get_timestamps().get_timestamps()[0], 1000)
            self.assertEqual(self.non_empty_sensors.get_gyroscope().get_x_samples().get_unit(), Unit["RADIANS_PER_SECOND"])
            self.assertEqual(self.non_empty_sensors.get_relative_humidity(), None)
            self.non_empty_sensors.remove_gyroscope()
            self.assertEqual(self.non_empty_sensors.get_gyroscope(), None)
            self.assertFalse(self.non_empty_sensors.validate_velocity())
            self.assertTrue(self.non_empty_sensors.validate_audio())
            self.assertEqual(len(sensor.validate_sensors(self.non_empty_sensors)), 0)