Skip to content

Commit

Permalink
tests: improve TestProcess behavior
Browse files Browse the repository at this point in the history
- Have it actually write to the given stdout handle.
- Return the return code for `poll` instead of returning `None`, so that
the process is observed to terminate.
  • Loading branch information
WillyPillow committed Mar 2, 2021
1 parent 4083b74 commit 64e9c24
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions qubesadmin/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __iter__(self):


class TestProcess(object):
def __init__(self, input_callback=None, stdout=None, stderr=None):
def __init__(self, input_callback=None, stdout=None, stderr=None, stdout_data=None):
self.input_callback = input_callback
self.got_any_input = False
self.stdin = io.BytesIO()
Expand All @@ -70,6 +70,10 @@ def __init__(self, input_callback=None, stdout=None, stderr=None):
self.stderr = io.BytesIO()
else:
self.stderr = stderr
if stdout_data:
self.stdout.write(stdout_data)
# Seek to head so that it can be read later
self.stdout.seek(0)
self.returncode = 0

def store_input(self):
Expand All @@ -91,7 +95,7 @@ def wait(self):
return 0

def poll(self):
return None
return self.returncode


class _AssertNotRaisesContext(object):
Expand Down Expand Up @@ -167,11 +171,12 @@ def run_service(self, dest, service, **kwargs):
# raise AssertionError('Unexpected service call {!r}'.format(call_key))
if call_key in self.expected_service_calls:
kwargs = kwargs.copy()
kwargs['stdout'] = io.BytesIO(self.expected_service_calls[call_key])
kwargs['stdout_data'] = self.expected_service_calls[call_key]
return TestProcess(lambda input: self.service_calls.append((dest,
service, input)),
stdout=kwargs.get('stdout', None),
stderr=kwargs.get('stderr', None),
stdout_data=kwargs.get('stdout_data', None),
)


Expand Down

0 comments on commit 64e9c24

Please sign in to comment.