From 8bd245721d9c79da9318e37d72658fe6de1cb2d7 Mon Sep 17 00:00:00 2001 From: Austin Cory Bart Date: Mon, 10 Aug 2020 10:15:15 -0400 Subject: [PATCH] Test for mocking input. --- test/test_io.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/test_io.py b/test/test_io.py index f6a9fe829b..dac09de43d 100644 --- a/test/test_io.py +++ b/test/test_io.py @@ -1 +1,20 @@ -import io \ No newline at end of file +import io +from unittest.mock import patch + +def haha(*args, **kwargs): + print("TEST") + return 'haha' + +overridden_modules = { + '__builtins__': { + 'input': haha + } +} + +s = patch.dict('sys.modules', overridden_modules) +s.start() +d = {'input': haha} +c = compile('print(input())', "test.py", 'exec') +exec(c, d) +s.stop() +print(d) \ No newline at end of file