-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_stream_delay.py
35 lines (31 loc) · 926 Bytes
/
test_stream_delay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from stream_delay import main
import pytest
import time
@pytest.mark.parametrize("option", ("-h", "--help"))
def test_help(capsys, option):
try:
main([option])
except SystemExit:
pass
output = capsys.readouterr().out
assert "Stream one or more files with a delay" in output
@pytest.mark.parametrize("delay", (None, "-d", "--delay-in-ms"))
def test_with_delay(tmpdir, capsys, delay):
three_lines = str(tmpdir / "three_lines.txt")
open(three_lines, "w").write("one\ntwo\nthree")
start = time.time()
args = [three_lines]
if delay:
args += [delay, "500"]
try:
main(args)
except SystemExit:
pass
end = time.time()
duration = (end - start) * 1000
output = capsys.readouterr().out
assert output == "one\ntwo\nthree"
expected = 300
if delay:
expected = 1500
assert (expected - 50) < duration < (expected + 50)