Module redvox.tests.api900.sensors.test_evenly_sampled_sensor

Expand source code
from redvox.api900 import reader
from redvox.tests import *

import unittest


class TestEvenlySampledSensor(unittest.TestCase):
    def setUp(self):
        self.example_packet = reader.read_rdvxz_file(test_data("example.rdvxz"))
        self.example_sensor = self.example_packet.microphone_sensor()
        self.empty_sensor = reader.EvenlySampledSensor()

    def test_get_sensor_name(self):
        self.assertEqual("example_mic", self.example_sensor.sensor_name())
        self.assertEqual("", self.empty_sensor.sensor_name())

    def test_set_sensor_name(self):
        self.assertEqual("foo", self.example_sensor.set_sensor_name("foo").sensor_name())
        self.assertEqual("foo", self.empty_sensor.set_sensor_name("foo").sensor_name())

    def test_get_sample_rate_hz(self):
        self.assertAlmostEqual(80.0, self.example_sensor.sample_rate_hz())
        self.assertAlmostEqual(0.0, self.empty_sensor.sample_rate_hz())

    def test_set_sample_rate_hz(self):
        self.assertAlmostEqual(100.0, self.example_sensor.set_sample_rate_hz(100.0).sample_rate_hz())
        self.assertAlmostEqual(100.0, self.empty_sensor.set_sample_rate_hz(100.0).sample_rate_hz())

    def test_get_first_sample_timestamp_microseconds_utc(self):
        self.assertEqual(1552075743960137, self.example_sensor.first_sample_timestamp_epoch_microseconds_utc())
        self.assertEqual(0, self.empty_sensor.first_sample_timestamp_epoch_microseconds_utc())

    def test_set_first_sample_timestamp_microseconds_utc(self):
        self.assertEqual(100, self.example_sensor.set_first_sample_timestamp_epoch_microseconds_utc(
            100).first_sample_timestamp_epoch_microseconds_utc())
        self.assertEqual(100, self.empty_sensor.set_first_sample_timestamp_epoch_microseconds_utc(
            100).first_sample_timestamp_epoch_microseconds_utc())

    def test_get_metadata(self):
        self.assertEqual(["foo", "bar"], self.example_sensor.metadata())
        self.assertEqual([], self.empty_sensor.metadata())

    def test_set_metadata(self):
        self.assertEqual(["a", "b"], self.example_sensor.set_metadata(["a", "b"]).metadata())
        self.assertEqual(["a", "b"], self.empty_sensor.set_metadata(["a", "b"]).metadata())

    def test_get_metadata_as_dict(self):
        self.assertEqual("bar", self.example_sensor.metadata_as_dict()["foo"])
        self.assertEqual(0, len(self.empty_sensor.metadata_as_dict()))

    def test_set_metadata_as_dict(self):
        self.assertEqual("b", self.example_sensor.set_metadata_as_dict({"a": "b"}).metadata_as_dict()["a"])
        self.assertEqual("b", self.empty_sensor.set_metadata_as_dict({"a": "b"}).metadata_as_dict()["a"])

    def test_eq(self):
        other_sensor = self.example_packet.clone().microphone_sensor()
        self.assertEqual(self.example_sensor, other_sensor)
        other_sensor.set_sensor_name("foo")
        self.assertNotEqual(self.example_sensor, other_sensor)

    def test_diff(self):
        other_sensor = self.example_packet.clone().microphone_sensor()
        self.assertEqual([], self.example_sensor.diff(other_sensor))
        other_sensor.set_sensor_name("foo")
        self.assertEqual(["example_mic != foo"], self.example_sensor.diff(other_sensor))

Classes

class TestEvenlySampledSensor (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 TestEvenlySampledSensor(unittest.TestCase):
    def setUp(self):
        self.example_packet = reader.read_rdvxz_file(test_data("example.rdvxz"))
        self.example_sensor = self.example_packet.microphone_sensor()
        self.empty_sensor = reader.EvenlySampledSensor()

    def test_get_sensor_name(self):
        self.assertEqual("example_mic", self.example_sensor.sensor_name())
        self.assertEqual("", self.empty_sensor.sensor_name())

    def test_set_sensor_name(self):
        self.assertEqual("foo", self.example_sensor.set_sensor_name("foo").sensor_name())
        self.assertEqual("foo", self.empty_sensor.set_sensor_name("foo").sensor_name())

    def test_get_sample_rate_hz(self):
        self.assertAlmostEqual(80.0, self.example_sensor.sample_rate_hz())
        self.assertAlmostEqual(0.0, self.empty_sensor.sample_rate_hz())

    def test_set_sample_rate_hz(self):
        self.assertAlmostEqual(100.0, self.example_sensor.set_sample_rate_hz(100.0).sample_rate_hz())
        self.assertAlmostEqual(100.0, self.empty_sensor.set_sample_rate_hz(100.0).sample_rate_hz())

    def test_get_first_sample_timestamp_microseconds_utc(self):
        self.assertEqual(1552075743960137, self.example_sensor.first_sample_timestamp_epoch_microseconds_utc())
        self.assertEqual(0, self.empty_sensor.first_sample_timestamp_epoch_microseconds_utc())

    def test_set_first_sample_timestamp_microseconds_utc(self):
        self.assertEqual(100, self.example_sensor.set_first_sample_timestamp_epoch_microseconds_utc(
            100).first_sample_timestamp_epoch_microseconds_utc())
        self.assertEqual(100, self.empty_sensor.set_first_sample_timestamp_epoch_microseconds_utc(
            100).first_sample_timestamp_epoch_microseconds_utc())

    def test_get_metadata(self):
        self.assertEqual(["foo", "bar"], self.example_sensor.metadata())
        self.assertEqual([], self.empty_sensor.metadata())

    def test_set_metadata(self):
        self.assertEqual(["a", "b"], self.example_sensor.set_metadata(["a", "b"]).metadata())
        self.assertEqual(["a", "b"], self.empty_sensor.set_metadata(["a", "b"]).metadata())

    def test_get_metadata_as_dict(self):
        self.assertEqual("bar", self.example_sensor.metadata_as_dict()["foo"])
        self.assertEqual(0, len(self.empty_sensor.metadata_as_dict()))

    def test_set_metadata_as_dict(self):
        self.assertEqual("b", self.example_sensor.set_metadata_as_dict({"a": "b"}).metadata_as_dict()["a"])
        self.assertEqual("b", self.empty_sensor.set_metadata_as_dict({"a": "b"}).metadata_as_dict()["a"])

    def test_eq(self):
        other_sensor = self.example_packet.clone().microphone_sensor()
        self.assertEqual(self.example_sensor, other_sensor)
        other_sensor.set_sensor_name("foo")
        self.assertNotEqual(self.example_sensor, other_sensor)

    def test_diff(self):
        other_sensor = self.example_packet.clone().microphone_sensor()
        self.assertEqual([], self.example_sensor.diff(other_sensor))
        other_sensor.set_sensor_name("foo")
        self.assertEqual(["example_mic != foo"], self.example_sensor.diff(other_sensor))

Ancestors

  • unittest.case.TestCase

Methods

def setUp(self)

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

Expand source code
def setUp(self):
    self.example_packet = reader.read_rdvxz_file(test_data("example.rdvxz"))
    self.example_sensor = self.example_packet.microphone_sensor()
    self.empty_sensor = reader.EvenlySampledSensor()
def test_diff(self)
Expand source code
def test_diff(self):
    other_sensor = self.example_packet.clone().microphone_sensor()
    self.assertEqual([], self.example_sensor.diff(other_sensor))
    other_sensor.set_sensor_name("foo")
    self.assertEqual(["example_mic != foo"], self.example_sensor.diff(other_sensor))
def test_eq(self)
Expand source code
def test_eq(self):
    other_sensor = self.example_packet.clone().microphone_sensor()
    self.assertEqual(self.example_sensor, other_sensor)
    other_sensor.set_sensor_name("foo")
    self.assertNotEqual(self.example_sensor, other_sensor)
def test_get_first_sample_timestamp_microseconds_utc(self)
Expand source code
def test_get_first_sample_timestamp_microseconds_utc(self):
    self.assertEqual(1552075743960137, self.example_sensor.first_sample_timestamp_epoch_microseconds_utc())
    self.assertEqual(0, self.empty_sensor.first_sample_timestamp_epoch_microseconds_utc())
def test_get_metadata(self)
Expand source code
def test_get_metadata(self):
    self.assertEqual(["foo", "bar"], self.example_sensor.metadata())
    self.assertEqual([], self.empty_sensor.metadata())
def test_get_metadata_as_dict(self)
Expand source code
def test_get_metadata_as_dict(self):
    self.assertEqual("bar", self.example_sensor.metadata_as_dict()["foo"])
    self.assertEqual(0, len(self.empty_sensor.metadata_as_dict()))
def test_get_sample_rate_hz(self)
Expand source code
def test_get_sample_rate_hz(self):
    self.assertAlmostEqual(80.0, self.example_sensor.sample_rate_hz())
    self.assertAlmostEqual(0.0, self.empty_sensor.sample_rate_hz())
def test_get_sensor_name(self)
Expand source code
def test_get_sensor_name(self):
    self.assertEqual("example_mic", self.example_sensor.sensor_name())
    self.assertEqual("", self.empty_sensor.sensor_name())
def test_set_first_sample_timestamp_microseconds_utc(self)
Expand source code
def test_set_first_sample_timestamp_microseconds_utc(self):
    self.assertEqual(100, self.example_sensor.set_first_sample_timestamp_epoch_microseconds_utc(
        100).first_sample_timestamp_epoch_microseconds_utc())
    self.assertEqual(100, self.empty_sensor.set_first_sample_timestamp_epoch_microseconds_utc(
        100).first_sample_timestamp_epoch_microseconds_utc())
def test_set_metadata(self)
Expand source code
def test_set_metadata(self):
    self.assertEqual(["a", "b"], self.example_sensor.set_metadata(["a", "b"]).metadata())
    self.assertEqual(["a", "b"], self.empty_sensor.set_metadata(["a", "b"]).metadata())
def test_set_metadata_as_dict(self)
Expand source code
def test_set_metadata_as_dict(self):
    self.assertEqual("b", self.example_sensor.set_metadata_as_dict({"a": "b"}).metadata_as_dict()["a"])
    self.assertEqual("b", self.empty_sensor.set_metadata_as_dict({"a": "b"}).metadata_as_dict()["a"])
def test_set_sample_rate_hz(self)
Expand source code
def test_set_sample_rate_hz(self):
    self.assertAlmostEqual(100.0, self.example_sensor.set_sample_rate_hz(100.0).sample_rate_hz())
    self.assertAlmostEqual(100.0, self.empty_sensor.set_sample_rate_hz(100.0).sample_rate_hz())
def test_set_sensor_name(self)
Expand source code
def test_set_sensor_name(self):
    self.assertEqual("foo", self.example_sensor.set_sensor_name("foo").sensor_name())
    self.assertEqual("foo", self.empty_sensor.set_sensor_name("foo").sensor_name())