aboutsummaryrefslogtreecommitdiffstats
path: root/test/mitmproxy/utils/test_sliding_window.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/mitmproxy/utils/test_sliding_window.py')
-rw-r--r--test/mitmproxy/utils/test_sliding_window.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/mitmproxy/utils/test_sliding_window.py b/test/mitmproxy/utils/test_sliding_window.py
new file mode 100644
index 00000000..23c76032
--- /dev/null
+++ b/test/mitmproxy/utils/test_sliding_window.py
@@ -0,0 +1,27 @@
+from mitmproxy.utils import sliding_window
+
+
+def test_simple():
+ y = list(sliding_window.window(range(1000, 1005), 1, 2))
+ assert y == [
+ # prev this next next2
+ (None, 1000, 1001, 1002),
+ (1000, 1001, 1002, 1003),
+ (1001, 1002, 1003, 1004),
+ (1002, 1003, 1004, None),
+ (1003, 1004, None, None)
+ ]
+
+
+def test_is_lazy():
+ done = False
+
+ def gen():
+ nonlocal done
+ done = True
+ yield 42
+
+ x = sliding_window.window(gen(), 1, 1)
+ assert not done
+ assert list(x)
+ assert done