Merge ~jocave/checkbox-support:fix-snaputils-unittests into checkbox-support:master

Proposed by Jonathan Cave
Status: Merged
Approved by: Jonathan Cave
Approved revision: 006ea57fdc732991f4b84af764767386f36d715f
Merged at revision: 821ffebd08d128f8660c814d2461a6b0cbe66fc3
Proposed branch: ~jocave/checkbox-support:fix-snaputils-unittests
Merge into: checkbox-support:master
Diff against target: 82 lines (+19/-10)
2 files modified
checkbox_support/snap_utils/tests/__init__.py (+0/-0)
checkbox_support/snap_utils/tests/test_config.py (+19/-10)
Reviewer Review Type Date Requested Status
Maciej Kisielewski Approve
Review via email: mp+391042@code.launchpad.net

Description of the change

Fix the existing unit tests in snap_utils and then ensure they are run.

Tested that the unit tests pass on focal dev machine.

To post a comment you must log in.
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

Makes sense. +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/checkbox_support/snap_utils/tests/__init__.py b/checkbox_support/snap_utils/tests/__init__.py
2new file mode 100644
3index 0000000..e69de29
4--- /dev/null
5+++ b/checkbox_support/snap_utils/tests/__init__.py
6diff --git a/checkbox_support/snap_utils/tests/test_config.py b/checkbox_support/snap_utils/tests/test_config.py
7index 74064c4..49cb4f8 100644
8--- a/checkbox_support/snap_utils/tests/test_config.py
9+++ b/checkbox_support/snap_utils/tests/test_config.py
10@@ -21,16 +21,21 @@ class TestSnapctlConfig(unittest.TestCase):
11 self.assertEqual(get_snapctl_config([]), dict())
12
13 def test_one_key(self):
14- with patch('subprocess.check_output', return_value=b'bar\n') as p:
15+ SNAPCTL_OUT = dedent("""
16+ {
17+ \t"foo": "bar"
18+ }
19+ """).lstrip().encode(sys.stdout.encoding)
20+ with patch('subprocess.check_output', return_value=SNAPCTL_OUT) as p:
21 expected = {'foo': 'bar'}
22 self.assertEqual(get_snapctl_config(['foo']), expected)
23- p.assert_called_with(['snapctl', 'get', 'foo'])
24+ p.assert_called_with(['snapctl', 'get', '-d', 'foo'])
25
26 def test_not_set_key(self):
27- with patch('subprocess.check_output', return_value=b'\n') as p:
28- expected = {'foo': ''}
29+ with patch('subprocess.check_output', return_value=b'{}\n') as p:
30+ expected = {}
31 self.assertEqual(get_snapctl_config(['foo']), expected)
32- p.assert_called_with(['snapctl', 'get', 'foo'])
33+ p.assert_called_with(['snapctl', 'get', '-d', 'foo'])
34
35 def test_two_keys(self):
36 SNAPCTL_OUT = dedent("""
37@@ -42,7 +47,7 @@ class TestSnapctlConfig(unittest.TestCase):
38 with patch('subprocess.check_output', return_value=SNAPCTL_OUT) as p:
39 expected = {'foo': 'bar', 'biz': 'baz'}
40 self.assertEqual(get_snapctl_config(['foo', 'biz']), expected)
41- p.assert_called_with(['snapctl', 'get', 'foo', 'biz'])
42+ p.assert_called_with(['snapctl', 'get', '-d', 'foo', 'biz'])
43
44 def test_two_keys_one_missing(self):
45 SNAPCTL_OUT = dedent("""
46@@ -53,12 +58,12 @@ class TestSnapctlConfig(unittest.TestCase):
47 with patch('subprocess.check_output', return_value=SNAPCTL_OUT) as p:
48 expected = {'foo': 'bar'}
49 self.assertEqual(get_snapctl_config(['foo', 'biz']), expected)
50- p.assert_called_with(['snapctl', 'get', 'foo', 'biz'])
51+ p.assert_called_with(['snapctl', 'get', '-d', 'foo', 'biz'])
52
53 def test_two_keys_both_missing(self):
54 with patch('subprocess.check_output', return_value=b'{}\n') as p:
55 self.assertEqual(get_snapctl_config(['foo', 'biz']), dict())
56- p.assert_called_with(['snapctl', 'get', 'foo', 'biz'])
57+ p.assert_called_with(['snapctl', 'get', '-d', 'foo', 'biz'])
58
59
60 class TestConfigSet(unittest.TestCase):
61@@ -149,7 +154,7 @@ class ConfigIntegrationTests(unittest.TestCase):
62 self.assertFalse(mock_run.called)
63
64 @patch('checkbox_support.snap_utils.config.get_configuration_set')
65- @patch('subprocess.check_output', return_value=b'\n')
66+ @patch('subprocess.check_output', return_value=b'{}\n')
67 @patch('subprocess.run')
68 def test_one_value(self, mock_run, mock_subproc, mock_conf_set):
69 """ FOO=bar in config_vars,
70@@ -181,7 +186,11 @@ class ConfigIntegrationTests(unittest.TestCase):
71 "FOO=bar"
72 """
73 mock_conf_set.return_value = {'foo': 'default'}
74- mock_subproc.return_value = b'bar\n'
75+ mock_subproc.return_value = dedent("""
76+ {
77+ \t"foo": "bar"
78+ }
79+ """).lstrip().encode(sys.stdout.encoding)
80 m = mock_open()
81 with patch('builtins.open', m):
82 refresh_configuration()

Subscribers

People subscribed via source and target branches