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
diff --git a/checkbox_support/snap_utils/tests/__init__.py b/checkbox_support/snap_utils/tests/__init__.py
0new file mode 1006440new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/checkbox_support/snap_utils/tests/__init__.py
diff --git a/checkbox_support/snap_utils/tests/test_config.py b/checkbox_support/snap_utils/tests/test_config.py
index 74064c4..49cb4f8 100644
--- a/checkbox_support/snap_utils/tests/test_config.py
+++ b/checkbox_support/snap_utils/tests/test_config.py
@@ -21,16 +21,21 @@ class TestSnapctlConfig(unittest.TestCase):
21 self.assertEqual(get_snapctl_config([]), dict())21 self.assertEqual(get_snapctl_config([]), dict())
2222
23 def test_one_key(self):23 def test_one_key(self):
24 with patch('subprocess.check_output', return_value=b'bar\n') as p:24 SNAPCTL_OUT = dedent("""
25 {
26 \t"foo": "bar"
27 }
28 """).lstrip().encode(sys.stdout.encoding)
29 with patch('subprocess.check_output', return_value=SNAPCTL_OUT) as p:
25 expected = {'foo': 'bar'}30 expected = {'foo': 'bar'}
26 self.assertEqual(get_snapctl_config(['foo']), expected)31 self.assertEqual(get_snapctl_config(['foo']), expected)
27 p.assert_called_with(['snapctl', 'get', 'foo'])32 p.assert_called_with(['snapctl', 'get', '-d', 'foo'])
2833
29 def test_not_set_key(self):34 def test_not_set_key(self):
30 with patch('subprocess.check_output', return_value=b'\n') as p:35 with patch('subprocess.check_output', return_value=b'{}\n') as p:
31 expected = {'foo': ''}36 expected = {}
32 self.assertEqual(get_snapctl_config(['foo']), expected)37 self.assertEqual(get_snapctl_config(['foo']), expected)
33 p.assert_called_with(['snapctl', 'get', 'foo'])38 p.assert_called_with(['snapctl', 'get', '-d', 'foo'])
3439
35 def test_two_keys(self):40 def test_two_keys(self):
36 SNAPCTL_OUT = dedent("""41 SNAPCTL_OUT = dedent("""
@@ -42,7 +47,7 @@ class TestSnapctlConfig(unittest.TestCase):
42 with patch('subprocess.check_output', return_value=SNAPCTL_OUT) as p:47 with patch('subprocess.check_output', return_value=SNAPCTL_OUT) as p:
43 expected = {'foo': 'bar', 'biz': 'baz'}48 expected = {'foo': 'bar', 'biz': 'baz'}
44 self.assertEqual(get_snapctl_config(['foo', 'biz']), expected)49 self.assertEqual(get_snapctl_config(['foo', 'biz']), expected)
45 p.assert_called_with(['snapctl', 'get', 'foo', 'biz'])50 p.assert_called_with(['snapctl', 'get', '-d', 'foo', 'biz'])
4651
47 def test_two_keys_one_missing(self):52 def test_two_keys_one_missing(self):
48 SNAPCTL_OUT = dedent("""53 SNAPCTL_OUT = dedent("""
@@ -53,12 +58,12 @@ class TestSnapctlConfig(unittest.TestCase):
53 with patch('subprocess.check_output', return_value=SNAPCTL_OUT) as p:58 with patch('subprocess.check_output', return_value=SNAPCTL_OUT) as p:
54 expected = {'foo': 'bar'}59 expected = {'foo': 'bar'}
55 self.assertEqual(get_snapctl_config(['foo', 'biz']), expected)60 self.assertEqual(get_snapctl_config(['foo', 'biz']), expected)
56 p.assert_called_with(['snapctl', 'get', 'foo', 'biz'])61 p.assert_called_with(['snapctl', 'get', '-d', 'foo', 'biz'])
5762
58 def test_two_keys_both_missing(self):63 def test_two_keys_both_missing(self):
59 with patch('subprocess.check_output', return_value=b'{}\n') as p:64 with patch('subprocess.check_output', return_value=b'{}\n') as p:
60 self.assertEqual(get_snapctl_config(['foo', 'biz']), dict())65 self.assertEqual(get_snapctl_config(['foo', 'biz']), dict())
61 p.assert_called_with(['snapctl', 'get', 'foo', 'biz'])66 p.assert_called_with(['snapctl', 'get', '-d', 'foo', 'biz'])
6267
6368
64class TestConfigSet(unittest.TestCase):69class TestConfigSet(unittest.TestCase):
@@ -149,7 +154,7 @@ class ConfigIntegrationTests(unittest.TestCase):
149 self.assertFalse(mock_run.called)154 self.assertFalse(mock_run.called)
150155
151 @patch('checkbox_support.snap_utils.config.get_configuration_set')156 @patch('checkbox_support.snap_utils.config.get_configuration_set')
152 @patch('subprocess.check_output', return_value=b'\n')157 @patch('subprocess.check_output', return_value=b'{}\n')
153 @patch('subprocess.run')158 @patch('subprocess.run')
154 def test_one_value(self, mock_run, mock_subproc, mock_conf_set):159 def test_one_value(self, mock_run, mock_subproc, mock_conf_set):
155 """ FOO=bar in config_vars,160 """ FOO=bar in config_vars,
@@ -181,7 +186,11 @@ class ConfigIntegrationTests(unittest.TestCase):
181 "FOO=bar"186 "FOO=bar"
182 """187 """
183 mock_conf_set.return_value = {'foo': 'default'}188 mock_conf_set.return_value = {'foo': 'default'}
184 mock_subproc.return_value = b'bar\n'189 mock_subproc.return_value = dedent("""
190 {
191 \t"foo": "bar"
192 }
193 """).lstrip().encode(sys.stdout.encoding)
185 m = mock_open()194 m = mock_open()
186 with patch('builtins.open', m):195 with patch('builtins.open', m):
187 refresh_configuration()196 refresh_configuration()

Subscribers

People subscribed via source and target branches