Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In test I/O utility, restore the old stdin/stdout instead of the "true" I/O streams #5049

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions test/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ class DummyIO:
def __init__(self):
self.stdout = DummyOut()
self.stdin = DummyIn(self.stdout)
self.installed = False

def addinput(self, s):
self.stdin.add(s)
Expand All @@ -345,12 +346,19 @@ def readcount(self):
return self.stdin.reads

def install(self):
assert not self.installed, "DummyIO already installed"
self.installed = True

self.orig_stdin = sys.stdin
self.orig_stdout = sys.stdout

sys.stdin = self.stdin
sys.stdout = self.stdout

def restore(self):
sys.stdin = sys.__stdin__
sys.stdout = sys.__stdout__
if self.installed:
sys.stdin = self.orig_stdin
sys.stdout = self.orig_stdout


# Utility.
Expand Down
3 changes: 2 additions & 1 deletion test/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,8 @@ def test_nonexistant_db(self):
config.write("library: /xxx/yyy/not/a/real/path")

with self.assertRaises(ui.UserError):
self.run_command("test", lib=None)
with control_stdin("n"):
self.run_command("test", lib=None)

def test_user_config_file(self):
with self.write_config_file() as file:
Expand Down
Loading