Skip to content

Commit

Permalink
Test for mocking input.
Browse files Browse the repository at this point in the history
  • Loading branch information
acbart committed Aug 10, 2020
1 parent 8986e56 commit 8bd2457
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion test/test_io.py
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
import io
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)

0 comments on commit 8bd2457

Please sign in to comment.