Skip to content

Commit b698b34

Browse files
authored
CiTestCase: stop using and remove sys_exit helper (canonical#283)
This shim was required to support Python 2.6, so we no longer need it.
1 parent c478d0b commit b698b34

File tree

4 files changed

+8
-24
lines changed

4 files changed

+8
-24
lines changed

cloudinit/cmd/tests/test_clean.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ def test_status_main(self):
167167
wrap_and_call(
168168
'cloudinit.cmd.clean',
169169
{'Init': {'side_effect': self.init_class},
170-
'sys.exit': {'side_effect': self.sys_exit},
171170
'sys.argv': {'new': ['clean', '--logs']}},
172171
clean.main)
173172

cloudinit/cmd/tests/test_status.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ def test_status_main(self):
382382
wrap_and_call(
383383
'cloudinit.cmd.status',
384384
{'sys.argv': {'new': ['status']},
385-
'sys.exit': {'side_effect': self.sys_exit},
386385
'_is_cloudinit_disabled': (False, ''),
387386
'Init': {'side_effect': self.init_class}},
388387
status.main)

cloudinit/tests/helpers.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,6 @@ def tmp_path(self, path, dir=None):
197197
dir = self.tmp_dir()
198198
return os.path.normpath(os.path.abspath(os.path.join(dir, path)))
199199

200-
def sys_exit(self, code):
201-
"""Provide a wrapper around sys.exit for python 2.6
202-
203-
In 2.6, this code would produce 'cm.exception' with value int(2)
204-
rather than the SystemExit that was raised by sys.exit(2).
205-
with assertRaises(SystemExit) as cm:
206-
sys.exit(2)
207-
"""
208-
raise SystemExit(code)
209-
210200
def tmp_cloud(self, distro, sys_cfg=None, metadata=None):
211201
"""Create a cloud with tmp working directory paths.
212202

tests/unittests/test_handler/test_schema.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,10 @@ class MainTest(CiTestCase):
345345

346346
def test_main_missing_args(self):
347347
"""Main exits non-zero and reports an error on missing parameters."""
348-
with mock.patch('sys.exit', side_effect=self.sys_exit):
349-
with mock.patch('sys.argv', ['mycmd']):
350-
with mock.patch('sys.stderr', new_callable=StringIO) as \
351-
m_stderr:
352-
with self.assertRaises(SystemExit) as context_manager:
353-
main()
348+
with mock.patch('sys.argv', ['mycmd']):
349+
with mock.patch('sys.stderr', new_callable=StringIO) as m_stderr:
350+
with self.assertRaises(SystemExit) as context_manager:
351+
main()
354352
self.assertEqual(1, context_manager.exception.code)
355353
self.assertEqual(
356354
'Expected either --config-file argument or --doc\n',
@@ -359,12 +357,10 @@ def test_main_missing_args(self):
359357
def test_main_absent_config_file(self):
360358
"""Main exits non-zero when config file is absent."""
361359
myargs = ['mycmd', '--annotate', '--config-file', 'NOT_A_FILE']
362-
with mock.patch('sys.exit', side_effect=self.sys_exit):
363-
with mock.patch('sys.argv', myargs):
364-
with mock.patch('sys.stderr', new_callable=StringIO) as \
365-
m_stderr:
366-
with self.assertRaises(SystemExit) as context_manager:
367-
main()
360+
with mock.patch('sys.argv', myargs):
361+
with mock.patch('sys.stderr', new_callable=StringIO) as m_stderr:
362+
with self.assertRaises(SystemExit) as context_manager:
363+
main()
368364
self.assertEqual(1, context_manager.exception.code)
369365
self.assertEqual(
370366
'Configfile NOT_A_FILE does not exist\n',

0 commit comments

Comments
 (0)