Skip to content

Commit

Permalink
tests: very naive mockup of app.run_service
Browse files Browse the repository at this point in the history
Currently it doesn't check passed arguments, does not allow specify
expected stdout/stderr or even return code.
It's only enough to not crash tests on NotImplementedError.
  • Loading branch information
marmarek committed Apr 28, 2017
1 parent 3559ec0 commit e76af93
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions qubesmgmt/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
# with this program; if not, see <http://www.gnu.org/licenses/>.
import unittest

import io

import qubesmgmt
import qubesmgmt.app

Expand All @@ -40,21 +42,50 @@ def __lt__(self, other):
return self.name < other.name
return NotImplemented


class TestVMCollection(dict):
def __iter__(self):
return iter(self.values())


class TestProcess(object):
def __init__(self, input_callback=None, stdout=None, stderr=None):
self.input_callback = input_callback
self.stdin = io.BytesIO()
# don't let anyone close it, before we get the value
self.stdin_close = self.stdin.close
if self.input_callback:
self.stdin.close = (
lambda: self.input_callback(self.stdin.getvalue()))
else:
self.stdin.close = lambda: None
self.stdout = stdout
self.stderr = stderr
self.returncode = 0

def communicate(self, input=None):
self.stdin.write(input)
self.stdin.close()
self.stdin_close()
return self.stdout, self.stderr

def wait(self):
self.stdin_close()
return 0

class QubesTest(qubesmgmt.app.QubesBase):
expected_calls = None
actual_calls = None
service_calls = None

def __init__(self):
super(QubesTest, self).__init__()
#: expected calls and saved replies for them
self.expected_calls = {}
#: actual calls made
self.actual_calls = []
#: rpc service calls
self.service_calls = []

def qubesd_call(self, dest, method, arg=None, payload=None):
call_key = (dest, method, arg, payload)
Expand All @@ -64,6 +95,11 @@ def qubesd_call(self, dest, method, arg=None, payload=None):
return_data = self.expected_calls[call_key]
return self._parse_qubesd_response(return_data)

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)))


class QubesTestCase(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit e76af93

Please sign in to comment.