diff --git a/qubesmgmt/tests/tools/__init__.py b/qubesmgmt/tests/tools/__init__.py
index 464a5e5..1143110 100644
--- a/qubesmgmt/tests/tools/__init__.py
+++ b/qubesmgmt/tests/tools/__init__.py
@@ -37,3 +37,19 @@ class StdoutBuffer(object):
def __exit__(self, exc_type, exc_val, exc_tb):
sys.stdout = sys.__stdout__
return False
+
+
+class StderrBuffer(object):
+ def __init__(self):
+ if sys.version_info[0] >= 3:
+ self.stderr = io.StringIO()
+ else:
+ self.stderr = io.BytesIO()
+
+ def __enter__(self):
+ sys.stderr = self.stderr
+ return self.stderr
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ sys.stderr = sys.__stderr__
+ return False
diff --git a/qubesmgmt/tests/tools/qubes_prefs.py b/qubesmgmt/tests/tools/qubes_prefs.py
index a37b4fd..cda5066 100644
--- a/qubesmgmt/tests/tools/qubes_prefs.py
+++ b/qubesmgmt/tests/tools/qubes_prefs.py
@@ -54,8 +54,11 @@ class TC_00_qubes_prefs(qubesmgmt.tests.QubesTestCase):
('dom0', 'mgmt.property.Get', 'no_such_property', None)] = \
b'2\x00AttributeError\x00\x00no_such_property\x00'
with self.assertRaises(SystemExit):
- qubesmgmt.tools.qubes_prefs.main([
- 'no_such_property'], app=self.app)
+ with qubesmgmt.tests.tools.StderrBuffer() as stderr:
+ qubesmgmt.tools.qubes_prefs.main([
+ 'no_such_property'], app=self.app)
+ self.assertIn('no such property: \'no_such_property\'',
+ stderr.getvalue())
self.assertAllCalled()
def test_004_set_invalid_property(self):
@@ -63,6 +66,9 @@ class TC_00_qubes_prefs(qubesmgmt.tests.QubesTestCase):
('dom0', 'mgmt.property.Set', 'no_such_property', b'value')]\
= b'2\x00AttributeError\x00\x00no_such_property\x00'
with self.assertRaises(SystemExit):
- qubesmgmt.tools.qubes_prefs.main([
- 'no_such_property', 'value'], app=self.app)
+ with qubesmgmt.tests.tools.StderrBuffer() as stderr:
+ qubesmgmt.tools.qubes_prefs.main([
+ 'no_such_property', 'value'], app=self.app)
+ self.assertIn('no such property: \'no_such_property\'',
+ stderr.getvalue())
self.assertAllCalled()
diff --git a/qubesmgmt/tests/tools/qvm_kill.py b/qubesmgmt/tests/tools/qvm_kill.py
index 8a16b89..5e03ecd 100644
--- a/qubesmgmt/tests/tools/qvm_kill.py
+++ b/qubesmgmt/tests/tools/qvm_kill.py
@@ -19,6 +19,7 @@
# with this program; if not, see .
import qubesmgmt.tests
+import qubesmgmt.tests.tools
import qubesmgmt.tools.qvm_kill
@@ -34,7 +35,10 @@ class TC_00_qvm_kill(qubesmgmt.tests.QubesTestCase):
def test_001_missing_vm(self):
with self.assertRaises(SystemExit):
- qubesmgmt.tools.qvm_kill.main([], app=self.app)
+ with qubesmgmt.tests.tools.StderrBuffer() as stderr:
+ qubesmgmt.tools.qvm_kill.main([], app=self.app)
+ self.assertIn('one of the arguments --all VMNAME is required',
+ stderr.getvalue())
self.assertAllCalled()
def test_002_invalid_vm(self):
@@ -42,7 +46,9 @@ class TC_00_qvm_kill(qubesmgmt.tests.QubesTestCase):
('dom0', 'mgmt.vm.List', None, None)] = \
b'0\x00some-vm class=AppVM state=Running\n'
with self.assertRaises(SystemExit):
- qubesmgmt.tools.qvm_kill.main(['no-such-vm'], app=self.app)
+ with qubesmgmt.tests.tools.StderrBuffer() as stderr:
+ qubesmgmt.tools.qvm_kill.main(['no-such-vm'], app=self.app)
+ self.assertIn('no such domain', stderr.getvalue())
self.assertAllCalled()
def test_003_not_running(self):
diff --git a/qubesmgmt/tests/tools/qvm_pause.py b/qubesmgmt/tests/tools/qvm_pause.py
index 6b8f505..25f3ec2 100644
--- a/qubesmgmt/tests/tools/qvm_pause.py
+++ b/qubesmgmt/tests/tools/qvm_pause.py
@@ -19,6 +19,7 @@
# with this program; if not, see .
import qubesmgmt.tests
+import qubesmgmt.tests.tools
import qubesmgmt.tools.qvm_pause
@@ -34,7 +35,10 @@ class TC_00_qvm_pause(qubesmgmt.tests.QubesTestCase):
def test_001_missing_vm(self):
with self.assertRaises(SystemExit):
- qubesmgmt.tools.qvm_pause.main([], app=self.app)
+ with qubesmgmt.tests.tools.StderrBuffer() as stderr:
+ qubesmgmt.tools.qvm_pause.main([], app=self.app)
+ self.assertIn('one of the arguments --all VMNAME is required',
+ stderr.getvalue())
self.assertAllCalled()
def test_002_invalid_vm(self):
@@ -42,7 +46,9 @@ class TC_00_qvm_pause(qubesmgmt.tests.QubesTestCase):
('dom0', 'mgmt.vm.List', None, None)] = \
b'0\x00some-vm class=AppVM state=Running\n'
with self.assertRaises(SystemExit):
- qubesmgmt.tools.qvm_pause.main(['no-such-vm'], app=self.app)
+ with qubesmgmt.tests.tools.StderrBuffer() as stderr:
+ qubesmgmt.tools.qvm_pause.main(['no-such-vm'], app=self.app)
+ self.assertIn('no such domain', stderr.getvalue())
self.assertAllCalled()
def test_003_not_running(self):
diff --git a/qubesmgmt/tests/tools/qvm_prefs.py b/qubesmgmt/tests/tools/qvm_prefs.py
index 92dcce7..cfcc919 100644
--- a/qubesmgmt/tests/tools/qvm_prefs.py
+++ b/qubesmgmt/tests/tools/qvm_prefs.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 sys
import qubesmgmt.tests
import qubesmgmt.tests.tools
@@ -47,7 +48,13 @@ class TC_00_qvm_prefs(qubesmgmt.tests.QubesTestCase):
def test_001_no_vm(self):
with self.assertRaises(SystemExit):
- qubesmgmt.tools.qvm_prefs.main([], app=self.app)
+ with qubesmgmt.tests.tools.StderrBuffer() as stderr:
+ qubesmgmt.tools.qvm_prefs.main([], app=self.app)
+ if sys.version_info[0] == 2:
+ self.assertIn('too few arguments', stderr.getvalue())
+ else:
+ self.assertIn('error: the following arguments are required: VMNAME',
+ stderr.getvalue())
self.assertAllCalled()
def test_002_set_property(self):
@@ -69,8 +76,11 @@ class TC_00_qvm_prefs(qubesmgmt.tests.QubesTestCase):
('dom0', 'mgmt.vm.property.Get', 'no_such_property', None)] = \
b'2\x00AttributeError\x00\x00no_such_property\x00'
with self.assertRaises(SystemExit):
- qubesmgmt.tools.qvm_prefs.main([
- 'dom0', 'no_such_property'], app=self.app)
+ with qubesmgmt.tests.tools.StderrBuffer() as stderr:
+ qubesmgmt.tools.qvm_prefs.main([
+ 'dom0', 'no_such_property'], app=self.app)
+ self.assertIn('no such property: \'no_such_property\'',
+ stderr.getvalue())
self.assertAllCalled()
def test_004_set_invalid_property(self):
@@ -81,6 +91,9 @@ class TC_00_qvm_prefs(qubesmgmt.tests.QubesTestCase):
('dom0', 'mgmt.vm.property.Set', 'no_such_property', b'value')] = \
b'2\x00AttributeError\x00\x00no_such_property\x00'
with self.assertRaises(SystemExit):
- qubesmgmt.tools.qvm_prefs.main([
- 'dom0', 'no_such_property', 'value'], app=self.app)
+ with qubesmgmt.tests.tools.StderrBuffer() as stderr:
+ qubesmgmt.tools.qvm_prefs.main([
+ 'dom0', 'no_such_property', 'value'], app=self.app)
+ self.assertIn('no such property: \'no_such_property\'',
+ stderr.getvalue())
self.assertAllCalled()
diff --git a/qubesmgmt/tests/tools/qvm_shutdown.py b/qubesmgmt/tests/tools/qvm_shutdown.py
index 2bd4212..b7ea306 100644
--- a/qubesmgmt/tests/tools/qvm_shutdown.py
+++ b/qubesmgmt/tests/tools/qvm_shutdown.py
@@ -34,7 +34,10 @@ class TC_00_qvm_shutdown(qubesmgmt.tests.QubesTestCase):
def test_001_missing_vm(self):
with self.assertRaises(SystemExit):
- qubesmgmt.tools.qvm_shutdown.main([], app=self.app)
+ with qubesmgmt.tests.tools.StderrBuffer() as stderr:
+ qubesmgmt.tools.qvm_shutdown.main([], app=self.app)
+ self.assertIn('one of the arguments --all VMNAME is required',
+ stderr.getvalue())
self.assertAllCalled()
def test_002_invalid_vm(self):
@@ -42,7 +45,9 @@ class TC_00_qvm_shutdown(qubesmgmt.tests.QubesTestCase):
('dom0', 'mgmt.vm.List', None, None)] = \
b'0\x00some-vm class=AppVM state=Running\n'
with self.assertRaises(SystemExit):
- qubesmgmt.tools.qvm_shutdown.main(['no-such-vm'], app=self.app)
+ with qubesmgmt.tests.tools.StderrBuffer() as stderr:
+ qubesmgmt.tools.qvm_shutdown.main(['no-such-vm'], app=self.app)
+ self.assertIn('no such domain', stderr.getvalue())
self.assertAllCalled()
def test_003_not_running(self):
diff --git a/qubesmgmt/tests/tools/qvm_unpause.py b/qubesmgmt/tests/tools/qvm_unpause.py
index da80f3d..463a3dc 100644
--- a/qubesmgmt/tests/tools/qvm_unpause.py
+++ b/qubesmgmt/tests/tools/qvm_unpause.py
@@ -34,7 +34,10 @@ class TC_00_qvm_unpause(qubesmgmt.tests.QubesTestCase):
def test_001_missing_vm(self):
with self.assertRaises(SystemExit):
- qubesmgmt.tools.qvm_unpause.main([], app=self.app)
+ with qubesmgmt.tests.tools.StderrBuffer() as stderr:
+ qubesmgmt.tools.qvm_unpause.main([], app=self.app)
+ self.assertIn('one of the arguments --all VMNAME is required',
+ stderr.getvalue())
self.assertAllCalled()
def test_002_invalid_vm(self):
@@ -42,7 +45,9 @@ class TC_00_qvm_unpause(qubesmgmt.tests.QubesTestCase):
('dom0', 'mgmt.vm.List', None, None)] = \
b'0\x00some-vm class=AppVM state=Running\n'
with self.assertRaises(SystemExit):
- qubesmgmt.tools.qvm_unpause.main(['no-such-vm'], app=self.app)
+ with qubesmgmt.tests.tools.StderrBuffer() as stderr:
+ qubesmgmt.tools.qvm_unpause.main(['no-such-vm'], app=self.app)
+ self.assertIn('no such domain', stderr.getvalue())
self.assertAllCalled()
def test_003_not_running(self):
diff --git a/qubesmgmt/tests/vm/properties.py b/qubesmgmt/tests/vm/properties.py
index 679960b..8856609 100644
--- a/qubesmgmt/tests/vm/properties.py
+++ b/qubesmgmt/tests/vm/properties.py
@@ -54,11 +54,11 @@ class TC_00_Properties(qubesmgmt.tests.vm.VMTestCase):
self.assertAllCalled()
def test_004_get_vm(self):
- self.skipTest('not specified')
self.app.expected_calls[
('test-vm', 'mgmt.vm.property.Get', 'prop1', None)] = \
b'0\x00default=False type=vm test-vm'
- self.assertEqual(self.vm.prop1, True)
+ self.assertIsInstance(self.vm.prop1, qubesmgmt.vm.QubesVM)
+ self.assertEqual(self.vm.prop1.name, 'test-vm')
self.assertAllCalled()
def test_005_get_none_vm(self):