Skip to content

Commit

Permalink
Update tests for Python 3.12
Browse files Browse the repository at this point in the history
- do not use assertDictContainsSubset (replace with either assertIn on
  items(), or assertEqual on dict union)
- replace assertRaisesRegexp with assertRaisesRegex
  • Loading branch information
marmarek committed Jan 5, 2024
1 parent fc85e8c commit 8f1210e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
42 changes: 21 additions & 21 deletions qubesadmin/tests/tools/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ def test_000_default(self):
parser.set_defaults(properties={'defaultprop': 'defaultvalue'})

args = parser.parse_args([])
self.assertDictContainsSubset(
{'defaultprop': 'defaultvalue'}, args.properties)
self.assertIn(
('defaultprop', 'defaultvalue'), args.properties.items())

def test_001_set_prop(self):
parser = argparse.ArgumentParser()
parser.add_argument('--property', '-p',
action=qubesadmin.tools.PropertyAction)

args = parser.parse_args(['-p', 'testprop=testvalue'])
self.assertDictContainsSubset(
{'testprop': 'testvalue'}, args.properties)
self.assertIn(
('testprop', 'testvalue'), args.properties.items())

def test_002_set_prop_2(self):
parser = argparse.ArgumentParser()
Expand All @@ -52,8 +52,8 @@ def test_002_set_prop_2(self):

args = parser.parse_args(
['-p', 'testprop=testvalue', '-p', 'testprop2=testvalue2'])
self.assertDictContainsSubset(
{'testprop': 'testvalue', 'testprop2': 'testvalue2'},
self.assertEqual(
{'testprop': 'testvalue', 'testprop2': 'testvalue2'} | args.properties,
args.properties)

def test_003_set_prop_with_default(self):
Expand All @@ -63,8 +63,8 @@ def test_003_set_prop_with_default(self):
parser.set_defaults(properties={'defaultprop': 'defaultvalue'})

args = parser.parse_args(['-p', 'testprop=testvalue'])
self.assertDictContainsSubset(
{'testprop': 'testvalue', 'defaultprop': 'defaultvalue'},
self.assertEqual(
{'testprop': 'testvalue', 'defaultprop': 'defaultvalue'} | args.properties,
args.properties)

def test_003_set_prop_override_default(self):
Expand All @@ -75,9 +75,9 @@ def test_003_set_prop_override_default(self):
parser.set_defaults(properties={'testprop': 'defaultvalue'})

args = parser.parse_args(['-p', 'testprop=testvalue'])
self.assertDictContainsSubset(
{'testprop': 'testvalue'},
args.properties)
self.assertIn(
('testprop', 'testvalue'),
args.properties.items())


class TC_01_SinglePropertyAction(qubesadmin.tests.QubesTestCase):
Expand All @@ -101,38 +101,38 @@ def test_100_default(self):
parser.set_defaults(properties={'testprop': 'defaultvalue'})

args = parser.parse_args([])
self.assertDictContainsSubset(
{'testprop': 'defaultvalue'}, args.properties)
self.assertIn(
('testprop', 'defaultvalue'), args.properties.items())

def test_101_set_prop(self):
parser = argparse.ArgumentParser()
parser.add_argument('--testprop', '-T',
action=qubesadmin.tools.SinglePropertyAction)
args = parser.parse_args(['-T', 'testvalue'])
self.assertDictContainsSubset(
{'testprop': 'testvalue'}, args.properties)
self.assertIn(
('testprop', 'testvalue'), args.properties.items())

def test_102_set_prop_dest(self):
parser = argparse.ArgumentParser()
parser.add_argument('--testprop', '-T', dest='otherprop',
action=qubesadmin.tools.SinglePropertyAction)
args = parser.parse_args(['-T', 'testvalue'])
self.assertDictContainsSubset(
{'otherprop': 'testvalue'}, args.properties)
self.assertIn(
('otherprop', 'testvalue'), args.properties.items())

def test_103_set_prop_const(self):
parser = argparse.ArgumentParser()
parser.add_argument('--testprop', '-T',
action=qubesadmin.tools.SinglePropertyAction,
const='testvalue')
args = parser.parse_args(['-T'])
self.assertDictContainsSubset(
{'testprop': 'testvalue'}, args.properties)
self.assertIn(
('testprop', 'testvalue'), args.properties.items())

def test_104_set_prop_positional(self):
parser = argparse.ArgumentParser()
parser.add_argument('testprop',
action=qubesadmin.tools.SinglePropertyAction)
args = parser.parse_args(['testvalue'])
self.assertDictContainsSubset(
{'testprop': 'testvalue'}, args.properties)
self.assertIn(
('testprop', 'testvalue'), args.properties.items())
2 changes: 1 addition & 1 deletion qubesadmin/tests/tools/qvm_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def test_015_wait_all_kill_timeout(self):
self.app.expected_calls[
('sys-net', 'admin.vm.CurrentState', None, None)] = \
b'0\x00power_state=Halted'
with self.assertRaisesRegexp(SystemExit, '2'):
with self.assertRaisesRegex(SystemExit, '2'):
qubesadmin.tools.qvm_shutdown.main(
['--wait', '--all', '--timeout=1'], app=self.app)
self.assertAllCalled()

0 comments on commit 8f1210e

Please sign in to comment.