From 1d877742aee273a4c1955c456902f223c9a92be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 7 Dec 2018 04:20:46 +0100 Subject: [PATCH] tests/tools: extend vm.run_service() mockup Handle stdout/stderr arguments and provide file-like objects when requested. --- qubesadmin/tests/__init__.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/qubesadmin/tests/__init__.py b/qubesadmin/tests/__init__.py index d6a2309..d663f95 100644 --- a/qubesadmin/tests/__init__.py +++ b/qubesadmin/tests/__init__.py @@ -17,6 +17,7 @@ # # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . +import subprocess import traceback import unittest @@ -61,8 +62,14 @@ class TestProcess(object): lambda: self.input_callback(self.stdin.getvalue())) else: self.stdin.close = lambda: None - self.stdout = stdout - self.stderr = stderr + if stdout == subprocess.PIPE: + self.stdout = io.BytesIO() + else: + self.stdout = stdout + if stderr == subprocess.PIPE: + self.stderr = io.BytesIO() + else: + self.stderr = stderr self.returncode = 0 def communicate(self, input=None): @@ -146,7 +153,10 @@ class QubesTest(qubesadmin.app.QubesBase): def run_service(self, dest, service, **kwargs): self.service_calls.append((dest, service, kwargs)) return TestProcess(lambda input: self.service_calls.append((dest, - service, input))) + service, input)), + stdout=kwargs.get('stdout', None), + stderr=kwargs.get('stderr', None), + ) class QubesTestCase(unittest.TestCase):