From 081efcceb1a2c067e90ce6274dd07704352c0b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Sat, 25 Apr 2020 15:37:09 +0200 Subject: [PATCH] fix tests --- satella/coding/sequences/iterators.py | 21 +++++++++++-------- .../test_metrics/test_metrics.py | 1 - 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/satella/coding/sequences/iterators.py b/satella/coding/sequences/iterators.py index ab87833d..322c3464 100644 --- a/satella/coding/sequences/iterators.py +++ b/satella/coding/sequences/iterators.py @@ -12,29 +12,32 @@ IteratorOrIterable = tp.Union[tp.Iterator[T], tp.Iterable[T]] @for_argument(iter) -@silence_excs(StopIteration) def even(sq: IteratorOrIterable) -> tp.Iterator[T]: """ Return only elements with even indices in this iterable (first element will be returned, as indices are counted from 0) """ - while True: - yield next(sq) - next(sq) + try: + while True: + yield next(sq) + next(sq) + except StopIteration: + return @for_argument(iter) -@silence_excs(StopIteration) def odd(sq: IteratorOrIterable) -> tp.Iterator[T]: """ Return only elements with odd indices in this iterable. """ - while True: - next(sq) - yield next(sq) + try: + while True: + next(sq) + yield next(sq) + except StopIteration: + return -@silence_excs(StopIteration) def count(sq: IteratorOrIterable, start: tp.Optional[int] = None, step: int = 1) -> tp.Iterator[int]: """ Return a sequence of integers, for each entry in the sequence with provided step. diff --git a/tests/test_instrumentation/test_metrics/test_metrics.py b/tests/test_instrumentation/test_metrics/test_metrics.py index b2f5c89a..d02ea89a 100644 --- a/tests/test_instrumentation/test_metrics/test_metrics.py +++ b/tests/test_instrumentation/test_metrics/test_metrics.py @@ -138,7 +138,6 @@ class TestMetric(unittest.TestCase): self.assertTrue(inspect.isgeneratorfunction(generator)) self.assertGreaterEqual(next(iter(my_metric.to_metric_data().values)).value, 1) - def test_quantile_context_manager(self): metric = getMetric('test_metric', 'summary', quantiles=[0.5]) with metric.measure(): -- GitLab