Skip to content

Commit f11a030

Browse files
llucaxjack-herrmann
authored andcommitted
Rename receiver/sender variables to make more sense
Signed-off-by: Leandro Lucarella <[email protected]>
1 parent cc4a21f commit f11a030

File tree

1 file changed

+54
-54
lines changed

1 file changed

+54
-54
lines changed

tests/timeseries/test_resampling.py

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -605,13 +605,13 @@ async def test_resampling_with_one_window(
605605
)
606606
resampler = Resampler(config)
607607

608-
source_recvr = source_chan.new_receiver()
609-
source_sendr = source_chan.new_sender()
608+
source_receiver = source_chan.new_receiver()
609+
source_sender = source_chan.new_sender()
610610

611611
sink_mock = AsyncMock(spec=Sink, return_value=True)
612612

613-
resampler.add_timeseries("test", source_recvr, sink_mock)
614-
source_props = resampler.get_source_properties(source_recvr)
613+
resampler.add_timeseries("test", source_receiver, sink_mock)
614+
source_props = resampler.get_source_properties(source_receiver)
615615

616616
# Test timeline
617617
#
@@ -624,8 +624,8 @@ async def test_resampling_with_one_window(
624624
# Send a few samples and run a resample tick, advancing the fake time by one period
625625
sample0s = Sample(timestamp, value=Quantity(5.0))
626626
sample1s = Sample(timestamp + timedelta(seconds=1), value=Quantity(12.0))
627-
await source_sendr.send(sample0s)
628-
await source_sendr.send(sample1s)
627+
await source_sender.send(sample0s)
628+
await source_sender.send(sample1s)
629629
await _advance_time(fake_time, resampling_period_s)
630630
await resampler.resample(one_shot=True)
631631

@@ -642,17 +642,17 @@ async def test_resampling_with_one_window(
642642
assert source_props == SourceProperties(
643643
sampling_start=timestamp, received_samples=2, sampling_period=None
644644
)
645-
assert _get_buffer_len(resampler, source_recvr) == config.initial_buffer_len
645+
assert _get_buffer_len(resampler, source_receiver) == config.initial_buffer_len
646646
sink_mock.reset_mock()
647647
resampling_fun_mock.reset_mock()
648648

649649
# Second resampling run
650650
sample2_5s = Sample(timestamp + timedelta(seconds=2.5), value=Quantity(2.0))
651651
sample3s = Sample(timestamp + timedelta(seconds=3), value=Quantity(4.0))
652652
sample4s = Sample(timestamp + timedelta(seconds=4), value=Quantity(5.0))
653-
await source_sendr.send(sample2_5s)
654-
await source_sendr.send(sample3s)
655-
await source_sendr.send(sample4s)
653+
await source_sender.send(sample2_5s)
654+
await source_sender.send(sample3s)
655+
await source_sender.send(sample4s)
656656
await _advance_time(fake_time, resampling_period_s)
657657
await resampler.resample(one_shot=True)
658658

@@ -675,7 +675,7 @@ async def test_resampling_with_one_window(
675675
)
676676
# The buffer should be able to hold 2 seconds of data, and data is coming
677677
# every 0.8 seconds, so we should be able to store 3 samples.
678-
assert _get_buffer_len(resampler, source_recvr) == 3
678+
assert _get_buffer_len(resampler, source_receiver) == 3
679679
sink_mock.reset_mock()
680680
resampling_fun_mock.reset_mock()
681681

@@ -693,7 +693,7 @@ async def test_resampling_with_one_window(
693693
received_samples=5,
694694
sampling_period=timedelta(seconds=0.8),
695695
)
696-
assert _get_buffer_len(resampler, source_recvr) == 3
696+
assert _get_buffer_len(resampler, source_receiver) == 3
697697

698698

699699
# Even when a lot could be refactored to use smaller functions, I'm allowing
@@ -719,13 +719,13 @@ async def test_resampling_with_one_and_a_half_windows( # pylint: disable=too-ma
719719
)
720720
resampler = Resampler(config)
721721

722-
source_recvr = source_chan.new_receiver()
723-
source_sendr = source_chan.new_sender()
722+
source_receiver = source_chan.new_receiver()
723+
source_sender = source_chan.new_sender()
724724

725725
sink_mock = AsyncMock(spec=Sink, return_value=True)
726726

727-
resampler.add_timeseries("test", source_recvr, sink_mock)
728-
source_props = resampler.get_source_properties(source_recvr)
727+
resampler.add_timeseries("test", source_receiver, sink_mock)
728+
source_props = resampler.get_source_properties(source_receiver)
729729

730730
# Test timeline
731731
#
@@ -738,8 +738,8 @@ async def test_resampling_with_one_and_a_half_windows( # pylint: disable=too-ma
738738
# Send a few samples and run a resample tick, advancing the fake time by one period
739739
sample0s = Sample(timestamp, value=Quantity(5.0))
740740
sample1s = Sample(timestamp + timedelta(seconds=1), value=Quantity(12.0))
741-
await source_sendr.send(sample0s)
742-
await source_sendr.send(sample1s)
741+
await source_sender.send(sample0s)
742+
await source_sender.send(sample1s)
743743
await _advance_time(fake_time, resampling_period_s)
744744
await resampler.resample(one_shot=True)
745745

@@ -756,17 +756,17 @@ async def test_resampling_with_one_and_a_half_windows( # pylint: disable=too-ma
756756
assert source_props == SourceProperties(
757757
sampling_start=timestamp, received_samples=2, sampling_period=None
758758
)
759-
assert _get_buffer_len(resampler, source_recvr) == config.initial_buffer_len
759+
assert _get_buffer_len(resampler, source_receiver) == config.initial_buffer_len
760760
sink_mock.reset_mock()
761761
resampling_fun_mock.reset_mock()
762762

763763
# Second resampling run
764764
sample2_5s = Sample(timestamp + timedelta(seconds=2.5), value=Quantity(2.0))
765765
sample3s = Sample(timestamp + timedelta(seconds=3), value=Quantity(4.0))
766766
sample4s = Sample(timestamp + timedelta(seconds=4), value=Quantity(5.0))
767-
await source_sendr.send(sample2_5s)
768-
await source_sendr.send(sample3s)
769-
await source_sendr.send(sample4s)
767+
await source_sender.send(sample2_5s)
768+
await source_sender.send(sample3s)
769+
await source_sender.send(sample4s)
770770
await _advance_time(fake_time, resampling_period_s)
771771
await resampler.resample(one_shot=True)
772772

@@ -784,15 +784,15 @@ async def test_resampling_with_one_and_a_half_windows( # pylint: disable=too-ma
784784
assert source_props == SourceProperties(
785785
sampling_start=timestamp, received_samples=5, sampling_period=None
786786
)
787-
assert _get_buffer_len(resampler, source_recvr) == config.initial_buffer_len
787+
assert _get_buffer_len(resampler, source_receiver) == config.initial_buffer_len
788788
sink_mock.reset_mock()
789789
resampling_fun_mock.reset_mock()
790790

791791
# Third resampling run
792792
sample5s = Sample(timestamp + timedelta(seconds=5), value=Quantity(1.0))
793793
sample6s = Sample(timestamp + timedelta(seconds=6), value=Quantity(3.0))
794-
await source_sendr.send(sample5s)
795-
await source_sendr.send(sample6s)
794+
await source_sender.send(sample5s)
795+
await source_sender.send(sample6s)
796796
await _advance_time(fake_time, resampling_period_s)
797797
await resampler.resample(one_shot=True)
798798

@@ -817,7 +817,7 @@ async def test_resampling_with_one_and_a_half_windows( # pylint: disable=too-ma
817817
# The buffer should be able to hold 2 * 1.5 (3) seconds of data, and data
818818
# is coming every 6/7 seconds (~0.857s), so we should be able to store
819819
# 4 samples.
820-
assert _get_buffer_len(resampler, source_recvr) == 4
820+
assert _get_buffer_len(resampler, source_receiver) == 4
821821
sink_mock.reset_mock()
822822
resampling_fun_mock.reset_mock()
823823

@@ -855,7 +855,7 @@ async def test_resampling_with_one_and_a_half_windows( # pylint: disable=too-ma
855855
received_samples=7,
856856
sampling_period=timedelta(seconds=6 / 7),
857857
)
858-
assert _get_buffer_len(resampler, source_recvr) == 4
858+
assert _get_buffer_len(resampler, source_receiver) == 4
859859

860860

861861
# Even when a lot could be refactored to use smaller functions, I'm allowing
@@ -881,13 +881,13 @@ async def test_resampling_with_two_windows( # pylint: disable=too-many-statemen
881881
)
882882
resampler = Resampler(config)
883883

884-
source_recvr = source_chan.new_receiver()
885-
source_sendr = source_chan.new_sender()
884+
source_receiver = source_chan.new_receiver()
885+
source_sender = source_chan.new_sender()
886886

887887
sink_mock = AsyncMock(spec=Sink, return_value=True)
888888

889-
resampler.add_timeseries("test", source_recvr, sink_mock)
890-
source_props = resampler.get_source_properties(source_recvr)
889+
resampler.add_timeseries("test", source_receiver, sink_mock)
890+
source_props = resampler.get_source_properties(source_receiver)
891891

892892
# Test timeline
893893
#
@@ -900,8 +900,8 @@ async def test_resampling_with_two_windows( # pylint: disable=too-many-statemen
900900
# Send a few samples and run a resample tick, advancing the fake time by one period
901901
sample0s = Sample(timestamp, value=Quantity(5.0))
902902
sample1s = Sample(timestamp + timedelta(seconds=1), value=Quantity(12.0))
903-
await source_sendr.send(sample0s)
904-
await source_sendr.send(sample1s)
903+
await source_sender.send(sample0s)
904+
await source_sender.send(sample1s)
905905
await _advance_time(fake_time, resampling_period_s)
906906
await resampler.resample(one_shot=True)
907907

@@ -918,17 +918,17 @@ async def test_resampling_with_two_windows( # pylint: disable=too-many-statemen
918918
assert source_props == SourceProperties(
919919
sampling_start=timestamp, received_samples=2, sampling_period=None
920920
)
921-
assert _get_buffer_len(resampler, source_recvr) == config.initial_buffer_len
921+
assert _get_buffer_len(resampler, source_receiver) == config.initial_buffer_len
922922
sink_mock.reset_mock()
923923
resampling_fun_mock.reset_mock()
924924

925925
# Second resampling run
926926
sample2_5s = Sample(timestamp + timedelta(seconds=2.5), value=Quantity(2.0))
927927
sample3s = Sample(timestamp + timedelta(seconds=3), value=Quantity(4.0))
928928
sample4s = Sample(timestamp + timedelta(seconds=4), value=Quantity(5.0))
929-
await source_sendr.send(sample2_5s)
930-
await source_sendr.send(sample3s)
931-
await source_sendr.send(sample4s)
929+
await source_sender.send(sample2_5s)
930+
await source_sender.send(sample3s)
931+
await source_sender.send(sample4s)
932932
await _advance_time(fake_time, resampling_period_s)
933933
await resampler.resample(one_shot=True)
934934

@@ -946,15 +946,15 @@ async def test_resampling_with_two_windows( # pylint: disable=too-many-statemen
946946
assert source_props == SourceProperties(
947947
sampling_start=timestamp, received_samples=5, sampling_period=None
948948
)
949-
assert _get_buffer_len(resampler, source_recvr) == config.initial_buffer_len
949+
assert _get_buffer_len(resampler, source_receiver) == config.initial_buffer_len
950950
sink_mock.reset_mock()
951951
resampling_fun_mock.reset_mock()
952952

953953
# Third resampling run
954954
sample5s = Sample(timestamp + timedelta(seconds=5), value=Quantity(1.0))
955955
sample6s = Sample(timestamp + timedelta(seconds=6), value=Quantity(3.0))
956-
await source_sendr.send(sample5s)
957-
await source_sendr.send(sample6s)
956+
await source_sender.send(sample5s)
957+
await source_sender.send(sample6s)
958958
await _advance_time(fake_time, resampling_period_s)
959959
await resampler.resample(one_shot=True)
960960

@@ -974,7 +974,7 @@ async def test_resampling_with_two_windows( # pylint: disable=too-many-statemen
974974
assert source_props == SourceProperties(
975975
sampling_start=timestamp, received_samples=7, sampling_period=None
976976
)
977-
assert _get_buffer_len(resampler, source_recvr) == config.initial_buffer_len
977+
assert _get_buffer_len(resampler, source_receiver) == config.initial_buffer_len
978978
sink_mock.reset_mock()
979979
resampling_fun_mock.reset_mock()
980980

@@ -996,7 +996,7 @@ async def test_resampling_with_two_windows( # pylint: disable=too-many-statemen
996996
assert source_props == SourceProperties(
997997
sampling_start=timestamp, received_samples=7, sampling_period=None
998998
)
999-
assert _get_buffer_len(resampler, source_recvr) == config.initial_buffer_len
999+
assert _get_buffer_len(resampler, source_receiver) == config.initial_buffer_len
10001000
sink_mock.reset_mock()
10011001
resampling_fun_mock.reset_mock()
10021002

@@ -1012,7 +1012,7 @@ async def test_resampling_with_two_windows( # pylint: disable=too-many-statemen
10121012
assert source_props == SourceProperties(
10131013
sampling_start=timestamp, received_samples=7, sampling_period=None
10141014
)
1015-
assert _get_buffer_len(resampler, source_recvr) == config.initial_buffer_len
1015+
assert _get_buffer_len(resampler, source_receiver) == config.initial_buffer_len
10161016

10171017

10181018
async def test_receiving_stopped_resampling_error(
@@ -1034,17 +1034,17 @@ async def test_receiving_stopped_resampling_error(
10341034
)
10351035
resampler = Resampler(config)
10361036

1037-
source_recvr = source_chan.new_receiver()
1038-
source_sendr = source_chan.new_sender()
1037+
source_receiver = source_chan.new_receiver()
1038+
source_sender = source_chan.new_sender()
10391039

10401040
sink_mock = AsyncMock(spec=Sink, return_value=True)
10411041

1042-
resampler.add_timeseries("test", source_recvr, sink_mock)
1043-
source_props = resampler.get_source_properties(source_recvr)
1042+
resampler.add_timeseries("test", source_receiver, sink_mock)
1043+
source_props = resampler.get_source_properties(source_receiver)
10441044

10451045
# Send a sample and run a resample tick, advancing the fake time by one period
10461046
sample0s = Sample(timestamp, value=Quantity(5.0))
1047-
await source_sendr.send(sample0s)
1047+
await source_sender.send(sample0s)
10481048
await _advance_time(fake_time, resampling_period_s)
10491049
await resampler.resample(one_shot=True)
10501050

@@ -1064,18 +1064,18 @@ async def test_receiving_stopped_resampling_error(
10641064
# Close channel, try to resample again
10651065
await source_chan.close()
10661066
with pytest.raises(SenderError):
1067-
await source_sendr.send(sample0s)
1067+
await source_sender.send(sample0s)
10681068
await _advance_time(fake_time, resampling_period_s)
10691069
with pytest.raises(ResamplingError) as excinfo:
10701070
await resampler.resample(one_shot=True)
10711071

10721072
assert datetime.now(timezone.utc).timestamp() == 4
10731073
exceptions = excinfo.value.exceptions
10741074
assert len(exceptions) == 1
1075-
assert source_recvr in exceptions
1076-
timeseries_error = exceptions[source_recvr]
1075+
assert source_receiver in exceptions
1076+
timeseries_error = exceptions[source_receiver]
10771077
assert isinstance(timeseries_error, SourceStoppedError)
1078-
assert timeseries_error.source is source_recvr
1078+
assert timeseries_error.source is source_receiver
10791079

10801080

10811081
async def test_receiving_resampling_error(fake_time: time_machine.Coordinates) -> None:
@@ -1205,9 +1205,9 @@ async def test_timer_is_aligned(
12051205
resampling_fun_mock.reset_mock()
12061206

12071207

1208-
def _get_buffer_len(resampler: Resampler, source_recvr: Source) -> int:
1208+
def _get_buffer_len(resampler: Resampler, source_receiver: Source) -> int:
12091209
# pylint: disable=protected-access
1210-
blen = resampler._resamplers[source_recvr]._helper._buffer.maxlen
1210+
blen = resampler._resamplers[source_receiver]._helper._buffer.maxlen
12111211
assert blen is not None
12121212
return blen
12131213

0 commit comments

Comments
 (0)