@@ -478,6 +478,28 @@ def test_aligned_windows(self):
478478 )
479479
480480
481+ def test_count (self ):
482+ """
483+ Test that stream count method uses aligned windows
484+ """
485+ uu = uuid .UUID ('0d22a53b-e2ef-4e0a-ab89-b2d48fb2592a' )
486+ endpoint = Mock (Endpoint )
487+ windows = [
488+ [(StatPointProto (time = 1 ,min = 2 ,mean = 3 ,max = 4 ,count = 5 ,stddev = 6 ), StatPointProto (time = 2 ,min = 3 ,mean = 4 ,max = 5 ,count = 6 ,stddev = 7 )), 42 ],
489+ [(StatPointProto (time = 3 ,min = 4 ,mean = 5 ,max = 6 ,count = 7 ,stddev = 8 ), StatPointProto (time = 4 ,min = 5 ,mean = 6 ,max = 7 ,count = 8 ,stddev = 9 )), 42 ],
490+ ]
491+ endpoint .alignedWindows = Mock (return_value = windows )
492+ stream = Stream (btrdb = BTrDB (endpoint ), uuid = uu )
493+
494+ assert stream .count () == 26
495+ stream ._btrdb .ep .alignedWindows .assert_called_once_with (
496+ uu , MINIMUM_TIME , MAXIMUM_TIME , 62 , 0
497+ )
498+
499+ stream .count (10 , 1000 , 48 , 1200 )
500+ stream ._btrdb .ep .alignedWindows .assert_called_with (uu , 10 , 1000 , 48 , 1200 )
501+
502+
481503 ##########################################################################
482504 ## earliest/latest tests
483505 ##########################################################################
@@ -1083,6 +1105,50 @@ def test_currently_out_of_range(self, mocked):
10831105 with pytest .raises (ValueError , match = "current time is not included in filtered stream range" ):
10841106 streams .filter (start = 0 , end = 10 ).current ()
10851107
1108+ def test_count (self ):
1109+ """
1110+ Test the stream set count method
1111+ """
1112+ uu1 = uuid .UUID ('0d22a53b-e2ef-4e0a-ab89-b2d48fb2592a' )
1113+ uu2 = uuid .UUID ('4dadf38d-52a5-4b7a-ada9-a5d563f9538c' )
1114+ endpoint = Mock (Endpoint )
1115+ windows = [
1116+ [(StatPointProto (time = 1 ,min = 2 ,mean = 3 ,max = 4 ,count = 5 ,stddev = 6 ), StatPointProto (time = 2 ,min = 3 ,mean = 4 ,max = 5 ,count = 6 ,stddev = 7 )), 42 ],
1117+ [(StatPointProto (time = 3 ,min = 4 ,mean = 5 ,max = 6 ,count = 7 ,stddev = 8 ), StatPointProto (time = 4 ,min = 5 ,mean = 6 ,max = 7 ,count = 8 ,stddev = 9 )), 42 ],
1118+ ]
1119+ endpoint .alignedWindows = Mock (return_value = windows )
1120+ streams = StreamSet ([
1121+ Stream (btrdb = BTrDB (endpoint ), uuid = uu1 ),
1122+ Stream (btrdb = BTrDB (endpoint ), uuid = uu2 ),
1123+ ])
1124+
1125+ assert streams .count () == 52
1126+ endpoint .alignedWindows .assert_any_call (uu1 , MINIMUM_TIME , MAXIMUM_TIME , 62 , 0 )
1127+ endpoint .alignedWindows .assert_any_call (uu2 , MINIMUM_TIME , MAXIMUM_TIME , 62 , 0 )
1128+
1129+
1130+ def test_count_filtered (self ):
1131+ """
1132+ Test the stream set count method with filters
1133+ """
1134+ uu1 = uuid .UUID ('0d22a53b-e2ef-4e0a-ab89-b2d48fb2592a' )
1135+ uu2 = uuid .UUID ('4dadf38d-52a5-4b7a-ada9-a5d563f9538c' )
1136+ endpoint = Mock (Endpoint )
1137+ endpoint .alignedWindows = Mock (return_value = [])
1138+ streams = StreamSet ([
1139+ Stream (btrdb = BTrDB (endpoint ), uuid = uu1 ),
1140+ Stream (btrdb = BTrDB (endpoint ), uuid = uu2 ),
1141+ ])
1142+
1143+ streams = streams .filter (start = 10 , end = 1000 )
1144+ streams .pin_versions ({uu1 : 42 , uu2 : 99 })
1145+ streams .pointwidth = 48
1146+
1147+ streams .count ()
1148+ endpoint .alignedWindows .assert_any_call (uu1 , 10 , 1000 , 48 , 42 )
1149+ endpoint .alignedWindows .assert_any_call (uu2 , 10 , 1000 , 48 , 99 )
1150+
1151+
10861152
10871153 ##########################################################################
10881154 ## filter tests
0 commit comments