From af017d027dd0385222bae069bbf22c9317becb16 Mon Sep 17 00:00:00 2001 From: ulif <uli@gnufix.de> Date: Fri, 24 Feb 2017 02:48:52 +0100 Subject: [PATCH] Add a new fake input test helper. This one is supposed to replace the existing classmethod and should become a regular fixture. --- tests/test_random_sources.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test_random_sources.py b/tests/test_random_sources.py index 926321c..1d566de 100644 --- a/tests/test_random_sources.py +++ b/tests/test_random_sources.py @@ -68,6 +68,13 @@ class TestSystemRandomSource(object): assert num > 0 +def fake_input_values(values, patch): + input_mock = InputMock(values) + patch.setattr( + "diceware.random_sources.input_func", input_mock) + return input_mock + + class TestRealDiceRandomSource(object): @classmethod @@ -83,7 +90,7 @@ class TestRealDiceRandomSource(object): # 'bar') and make sure that output is captured. # This test is just a hint, how input could be faked in real tests. # It can (and should) be removed if not needed any more. - self.fake_input_values(["foo", "bar"], monkeypatch) + fake_input_values(["foo", "bar"], monkeypatch) # late import, because we need the patched version from diceware.random_sources import input_func result1 = input_func("Enter some values: ") -- GitLab