summaryrefslogtreecommitdiff
path: root/t/utils.py
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-07-22 02:37:17 -0600
committerbd <bdunahu@operationnull.com>2025-07-22 02:37:17 -0600
commit7d3238ccc4fd44f3279fccc46ef64b74ab0f71e6 (patch)
tree36614417a959a5d4da61a3dfc7f1c58526460fa9 /t/utils.py
parent3cefc8b2ad4a15b62708e63f25cdd4c010bd9e1b (diff)
Trial the addition of some yappi-aergia comparison tests
Diffstat (limited to 't/utils.py')
-rw-r--r--t/utils.py36
1 files changed, 27 insertions, 9 deletions
diff --git a/t/utils.py b/t/utils.py
index 6a168bc..9d77665 100644
--- a/t/utils.py
+++ b/t/utils.py
@@ -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