def test_moving_average_of_all_measurements(sample_data, sample_measurement, sample_database, database_with_data): database_client = DatabaseClient(database_with_data, db_name=sample_database) expected = statistics.mean(sample_data) actual = database_client.moving_average( sample_measurement, time_window='{}s'.format(len(sample_data) + 1)) assert expected == actual
def test_moving_average_of_last_2_measurements(sample_data, sample_measurement, sample_database, database_with_data): database_client = DatabaseClient(database_with_data, db_name=sample_database) expected = statistics.mean(sample_data[-2:]) actual = database_client.moving_average(sample_measurement, time_window='3s') assert expected == actual
def test_moving_average_without_measurements(sample_measurement, sample_database, database): database_client = DatabaseClient(database, db_name=sample_database) with pytest.raises(RuntimeError): database_client.moving_average(sample_measurement, '1m')