示例#1
0
    def test_Sensor_value_checks_consistency_of_read_dictionary(self, read):

        with self.subTest("Wrong type"):
            s = sensors.Dummy()
            read.return_value = {"random": int(42)}
            with self.assertRaises(TypeError):
                s.value

        with self.subTest("Incomplete"):
            s = sensors.Dummy()
            read.return_value = {}
            with self.assertRaises(KeyError):
                s.value
示例#2
0
 def test_measurment_has_last_acquisition_stored(self):
     m = Measurement(sensors.Dummy(), table="dummy_table")
     self.assertEqual(m.last, {})
     m.acquire()
     self.assertIn("time", m.last)
     for key in sensors.Dummy.dtypes.keys():
         self.assertIn(key, m.last)
示例#3
0
    def test_can_query_measurements_from_db(self):
        m = Measurement(sensors.Dummy(), table="query_table")
        m.acquire()
        time.sleep(0.1)
        ts = datetime.datetime.now()
        time.sleep(0.1)
        m.acquire()

        self.assertEqual(len(m.data()["random"]), 2)
        self.assertEqual(len(m.data(since=ts)["random"]), 1)
示例#4
0
    def test_can_retrieve_subset_of_columns(self):
        m = Measurement(sensors.Dummy(), table="dummy_table")
        m.acquire()

        with self.subTest("list argument"):
            data = m.data(columns=["randint"])
            self.assertNotIn("random", data)

        with self.subTest("string argument"):
            data = m.data(columns="randint")
            self.assertNotIn("random", data)
示例#5
0
 def test_data_returns_dict_even_if_table_is_empty(self):
     m = Measurement(sensors.Dummy(), table="empty_table")
     data = m.data()
     self.assertIn("time", data)
     self.assertListEqual(data["time"], [])
示例#6
0
 def test_measurement_fills_database_rows(self):
     m = Measurement(sensors.Dummy(), table="dummy_table")
     m.acquire()
     m.acquire()
     self.assertEqual(len(m.data()["random"]), 2)
示例#7
0
 def test_measurement_not_raises_if_table_exists(self):
     Measurement(sensors.Dummy(), table="dummy_table")
     Measurement(sensors.Dummy(), table="dummy_table")
示例#8
0
 def test_measurement_creates_db_table_on_initialization(self):
     Measurement(sensors.Dummy(), table="dummy_table")
     self.assertTrue(piweather.db.has_table("dummy_table"))
示例#9
0
 def test_measurement_job_calls_sensors_value(self, mock_value):
     Measurement(sensors.Dummy(), table="dummy", frequency=0.1)
     time.sleep(0.2)
     self.assertTrue(mock_value.called)
示例#10
0
 def test_measurement_with_0_frequency_does_not_have_a_job(self):
     meas = Measurement(sensors.Dummy(), table="dummy", frequency=60)
     self.assertNumberOfJobs(1)
     meas.frequency = 0
     self.assertNumberOfJobs(0)
示例#11
0
 def test_measurement_changing_frequency_does_not_add_another_job(self):
     meas = Measurement(sensors.Dummy(), table="dummy", frequency=60)
     self.assertNumberOfJobs(1)
     meas.frequency = 120
     self.assertNumberOfJobs(1)
示例#12
0
 def test_measurement_specifying_frequency_adds_job_to_scheduler(self):
     self.assertNumberOfJobs(0)
     meas = Measurement(sensors.Dummy(), table="dummy", frequency=60)
     self.assertNumberOfJobs(1)
     self.assertEqual(meas.frequency, 60)
示例#13
0
 def test_Sensor_returns_dictionary_with_correct_types(self):
     s = sensors.Dummy()
     values = s.value
     for k, v in s.dtypes.items():
         self.assertIsInstance(values[k], v)
示例#14
0
 def test_Sensor_knows_returned_datatypes(self):
     s = sensors.Dummy()
     self.assertIn("random", s.dtypes)
     self.assertEqual(s.dtypes["random"], float)
示例#15
0
 def test_Sensor_can_cache_time_for_value(self):
     s = sensors.Dummy(cache=0.1)
     val = s.value
     self.assertEqual(val, s.value)
     time.sleep(0.2)
     self.assertNotEqual(val, s.value)