mirror of
https://github.com/beetbox/beets.git
synced 2026-02-09 08:52:30 +01:00
Patch sys.stdin and sys.stdout in tests
This commit is contained in:
parent
6c2c46091b
commit
cc4dd688b8
3 changed files with 6 additions and 15 deletions
|
|
@ -190,14 +190,6 @@ class DummyIO:
|
|||
def readcount(self):
|
||||
return self.stdin.reads
|
||||
|
||||
def install(self):
|
||||
sys.stdin = self.stdin
|
||||
sys.stdout = self.stdout
|
||||
|
||||
def restore(self):
|
||||
sys.stdin = sys.__stdin__
|
||||
sys.stdout = sys.__stdout__
|
||||
|
||||
|
||||
# Utility.
|
||||
|
||||
|
|
|
|||
|
|
@ -168,13 +168,14 @@ class IOMixin:
|
|||
def io(self) -> _common.DummyIO:
|
||||
return _common.DummyIO()
|
||||
|
||||
def setUp(self):
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
self.io.install()
|
||||
|
||||
def tearDown(self):
|
||||
super().tearDown()
|
||||
self.io.restore()
|
||||
patcher = patch.multiple(
|
||||
"sys", stdin=self.io.stdin, stdout=self.io.stdout
|
||||
)
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
|
||||
|
||||
class TestHelper(ConfigMixin):
|
||||
|
|
@ -759,7 +760,6 @@ class TerminalImportMixin(IOMixin, ImportHelper):
|
|||
io: _common.DummyIO
|
||||
|
||||
def _get_import_session(self, import_dir: bytes) -> importer.ImportSession:
|
||||
self.io.install()
|
||||
return TerminalImportSessionFixture(
|
||||
self.lib,
|
||||
loghandler=None,
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ class CompletionTest(IOMixin, TestPluginTestCase):
|
|||
# Load completion script.
|
||||
self.run_command("completion", lib=None)
|
||||
completion_script = self.io.getoutput().encode("utf-8")
|
||||
self.io.restore()
|
||||
tester.stdin.writelines(completion_script.splitlines(True))
|
||||
|
||||
# Load test suite.
|
||||
|
|
|
|||
Loading…
Reference in a new issue