summaryrefslogtreecommitdiff
path: root/t/utils.py
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-07-22 02:17:17 -0600
committerbd <bdunahu@operationnull.com>2025-07-22 02:17:17 -0600
commit3cefc8b2ad4a15b62708e63f25cdd4c010bd9e1b (patch)
treeaa733bc8a315806acbec05c00ee6687e87b31d59 /t/utils.py
parent487c77a96504c0178581a7a4bb7e9cd66783548f (diff)
Refactor test suite, add comments
Diffstat (limited to 't/utils.py')
-rw-r--r--t/utils.py43
1 files changed, 26 insertions, 17 deletions
diff --git a/t/utils.py b/t/utils.py
index da9a9c1..6a168bc 100644
--- a/t/utils.py
+++ b/t/utils.py
@@ -10,26 +10,35 @@ class AergiaUnitTestCase(unittest.TestCase):
def setUp(self):
self.Aergia.clear()
- def assertFuncContains(self, func_name, samples_expected, samples):
- samples_actual = self.extract_values_by_func(samples,
- func_name)
- self.assertTrue(len(samples_expected) == len(samples_actual),
- f'{samples_expected} (expected) not length of '
- f'{samples_actual} (actual)')
- s1 = sorted(samples_expected)
- s2 = sorted(samples_actual)
- for v1, v2 in zip(s1, s2):
- self.assertRoughlyEqual(v1, v2)
-
- def assertRoughlyEqual(self, v1, v2):
+ 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)
+
+ def assert_roughly_equal(self, v1, v2):
+ '''Throws an exception if values V1 and V2 are not within 2.5
+ samples of each other.'''
a = abs(v1 - v2)
- self.assertTrue(a <= 2, f'{v1} (expected) not roughly {v2} (actual)')
+ self.assertTrue(a <= 2.5, f'{v1} (expected) not roughly {v2} (actual)')
- def expected_samples(self, total_seconds):
+ 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 extract_values_by_func(self, samples, func_name):
- return [
+ def aergia_extract_values_by_func(self, samples, func_name):
+ '''Returns the total number of samples for function name, given an
+ Aergia SAMPLES object.'''
+ return sum(
value for key, value in samples.items()
if key.func == func_name
- ]
+ )
+
+ def yappi_extract_values_by_func(self, stats, func_name):
+ '''Returns the total number of samples for function name, given a
+ yappi stats object.'''
+ for s in stats:
+ if s.name == func_name:
+ return s.ttot