diff options
Diffstat (limited to 't/utils.py')
| -rw-r--r-- | t/utils.py | 36 |
1 files changed, 27 insertions, 9 deletions
@@ -1,4 +1,5 @@ from aergia.aergia import Aergia +import yappi import unittest @@ -6,27 +7,44 @@ class AergiaUnitTestCase(unittest.TestCase): interval = 0.01 Aergia = Aergia(interval) + # yappi is a singleton def setUp(self): self.Aergia.clear() + yappi.stop() + yappi.clear_stats() + yappi.set_clock_type('wall') + yappi.set_context_id_callback(None) + yappi.set_context_name_callback(None) + yappi.set_tag_callback(None) + def assert_reasonable_delay(self, func_name, time_expected, samples): '''Compares the results reported by Aergia for FUNC_NAME with time_expected.''' - samples_expected = self.aergia_expected_samples(time_expected) samples_actual = self.aergia_extract_values_by_func(samples, func_name) - self.assert_roughly_equal(samples_actual, samples_expected) + time_actual = self.aergia_expected_time(samples_actual) + self.assert_roughly_equal(time_actual, time_expected) + + def assert_similar_delay(self, func_name, yappi_stats, aergia_samples): + time_yappi = self.yappi_extract_values_by_func(yappi_stats, func_name) + + samples_aergia = self.aergia_extract_values_by_func( + aergia_samples, func_name) + time_aergia = self.aergia_expected_time(samples_aergia) + + self.assert_roughly_equal(time_aergia, time_yappi) def assert_roughly_equal(self, v1, v2): - '''Throws an exception if values V1 and V2 are not within 2.5 - samples of each other.''' + '''Throws an exception if values V1 and V2 are not within 0.03 + seconds of each other.''' a = abs(v1 - v2) - self.assertTrue(a <= 2.5, f'{v1} (expected) not roughly {v2} (actual)') + self.assertTrue(a <= .03, f'{v1} (expected) not roughly {v2} (actual)') - def aergia_expected_samples(self, total_seconds): - '''Given TOTAL_SECONDS, returns the expected number of samples, using - the sampling interval.''' - return (total_seconds / self.interval) + def aergia_expected_time(self, total_samples): + '''Given TOTAL_SAMPLES, returns the total time, using the + sampling interval.''' + return total_samples * self.interval def aergia_extract_values_by_func(self, samples, func_name): '''Returns the total number of samples for function name, given an |
