Skip to content

Commit fc5f7c4

Browse files
committed
improved performance of collection, and skipping tests that don't need to run locally
1 parent 6c5baa7 commit fc5f7c4

File tree

9 files changed

+588
-46
lines changed

9 files changed

+588
-46
lines changed
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
from osbot_utils.type_safe.Type_Safe import Type_Safe
1+
from dataclasses import dataclass
22

3-
4-
class Schema__Method_Timing(Type_Safe): # Aggregated timing for a method
3+
@dataclass(slots=True)
4+
class Schema__Method_Timing(): # Aggregated timing for a method
55
name : str = ''
66
call_count : int = 0
77
total_ns : int = 0
88
min_ns : int = 0
99
max_ns : int = 0
10-
self_ns : int = 0 # Exclusive time (minus children)
10+
self_ns : int = 0 # Exclusive time (minus children)
11+
12+
def __enter__(self):
13+
return self
14+
15+
def __exit__(self, exc_type, exc_val, exc_tb):
16+
return False
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
from dataclasses import dataclass
12
from typing import Dict, Any
2-
from osbot_utils.type_safe.Type_Safe import Type_Safe
33

4-
5-
class Schema__Timestamp_Entry(Type_Safe): # Single timestamp capture entry
4+
@dataclass(slots=True)
5+
class Schema__Timestamp_Entry:
66
name : str = ''
77
event : str = '' # 'enter' | 'exit'
88
timestamp_ns : int = 0 # perf_counter_ns (monotonic)
99
clock_ns : int = 0 # time_ns (wall clock)
1010
thread_id : int = 0
1111
depth : int = 0
12-
extra : Dict[str, Any] = None
12+
extra : Dict[str, Any] = None
13+
14+
def __enter__(self):
15+
return self
16+
17+
def __exit__(self, exc_type, exc_val, exc_tb):
18+
return False

tests/unit/helpers/timestamp_capture/decorators/test_timestamp.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import time
22
from unittest import TestCase
3+
4+
from osbot_fast_api_serverless.utils.testing.skip_tests import skip__if_not__in_github_actions
5+
36
from osbot_utils.helpers.timestamp_capture.Timestamp_Collector import Timestamp_Collector
47
from osbot_utils.helpers.timestamp_capture.decorators.timestamp import timestamp
58
from osbot_utils.type_safe.Type_Safe import Type_Safe
@@ -146,6 +149,7 @@ def repeated():
146149
assert _timestamp_collector_.method_count() == 1 # Still just one unique method
147150

148151
def test_timestamp__timing_accuracy(self): # Test timing is reasonably accurate
152+
skip__if_not__in_github_actions()
149153
@timestamp
150154
def sleep_function():
151155
time.sleep(0.01) # 10ms

tests/unit/helpers/timestamp_capture/decorators/test_timestamp_block.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import time
22
from unittest import TestCase
3+
4+
from osbot_fast_api_serverless.utils.testing.skip_tests import skip__if_not__in_github_actions
5+
36
from osbot_utils.helpers.timestamp_capture.Timestamp_Collector import Timestamp_Collector
47
from osbot_utils.helpers.timestamp_capture.context_managers.timestamp_block import timestamp_block
58

@@ -66,6 +69,7 @@ def test_timestamp_block__with_exception(self):
6669
assert _timestamp_collector_.entries[1].event == 'exit'
6770

6871
def test_timestamp_block__timing_accuracy(self): # Test timing is reasonably accurate
72+
skip__if_not__in_github_actions()
6973
_timestamp_collector_ = Timestamp_Collector()
7074

7175
with _timestamp_collector_:

tests/unit/helpers/timestamp_capture/schemas/test_Schema__Method_Timing.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class test_Schema__Method_Timing(TestCase):
99
def test__init__(self): # Test auto-initialization of schema
1010
with Schema__Method_Timing() as _:
1111
assert type(_) is Schema__Method_Timing
12-
assert base_classes(_) == [Type_Safe, object]
12+
assert base_classes(_) == [object]
1313
assert _.name == ''
1414
assert _.call_count == 0
1515
assert _.total_ns == 0
@@ -29,21 +29,4 @@ def test__init____with_values(self): # T
2929
assert _.total_ns == 50_000_000
3030
assert _.min_ns == 3_000_000
3131
assert _.max_ns == 8_000_000
32-
assert _.self_ns == 30_000_000
33-
34-
def test__json_round_trip(self): # Test serialization round-trip
35-
with Schema__Method_Timing(name = 'convert' ,
36-
call_count = 5 ,
37-
total_ns = 100_000_000 ,
38-
min_ns = 15_000_000 ,
39-
max_ns = 25_000_000 ,
40-
self_ns = 60_000_000 ) as _:
41-
json_data = _.json()
42-
recreated = Schema__Method_Timing.from_json(json_data)
43-
44-
assert recreated.name == _.name
45-
assert recreated.call_count == _.call_count
46-
assert recreated.total_ns == _.total_ns
47-
assert recreated.min_ns == _.min_ns
48-
assert recreated.max_ns == _.max_ns
49-
assert recreated.self_ns == _.self_ns
32+
assert _.self_ns == 30_000_000

tests/unit/helpers/timestamp_capture/schemas/test_Schema__Timestamp_Entry.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class test_Schema__Timestamp_Entry(TestCase):
99
def test__init__(self): # Test auto-initialization of schema
1010
with Schema__Timestamp_Entry() as _:
1111
assert type(_) is Schema__Timestamp_Entry
12-
assert base_classes(_) == [Type_Safe, object]
12+
assert base_classes(_) == [object]
1313
assert _.name == ''
1414
assert _.event == ''
1515
assert _.timestamp_ns == 0
@@ -32,21 +32,4 @@ def test__init____with_values(self): #
3232
assert _.clock_ns == 987654321
3333
assert _.thread_id == 12345
3434
assert _.depth == 3
35-
assert _.extra == {'key': 'val'}
36-
37-
def test__json_round_trip(self): # Test serialization round-trip
38-
with Schema__Timestamp_Entry(name = 'method_a' ,
39-
event = 'exit' ,
40-
timestamp_ns = 111111111 ,
41-
clock_ns = 222222222 ,
42-
thread_id = 999 ,
43-
depth = 2 ) as _:
44-
json_data = _.json()
45-
recreated = Schema__Timestamp_Entry.from_json(json_data)
46-
47-
assert recreated.name == _.name
48-
assert recreated.event == _.event
49-
assert recreated.timestamp_ns == _.timestamp_ns
50-
assert recreated.clock_ns == _.clock_ns
51-
assert recreated.thread_id == _.thread_id
52-
assert recreated.depth == _.depth
35+
assert _.extra == {'key': 'val'}

0 commit comments

Comments
 (0)