-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathtest_opts.py
More file actions
52 lines (40 loc) · 1.68 KB
/
test_opts.py
File metadata and controls
52 lines (40 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Copyright (c) 2012-2016 Marc Abramowitz and ipdb development team
#
# This file is part of ipdb.
# Redistributable under the revised BSD license
# https://opensource.org/licenses/BSD-3-Clause
import unittest
from unittest.mock import patch
from getopt import GetoptError
from ipdb.__main__ import main
@patch('ipdb.__main__._get_debugger_cls')
class OptsTest(unittest.TestCase):
def set_argv(self, *argv):
argv_patch = patch('ipdb.__main__.sys.argv', argv)
argv_patch.start()
self.addCleanup(argv_patch.stop)
@patch('ipdb.__main__.sys.version_info', (3, 7))
def test_debug_module_script(self, get_debugger_cls):
module_name = 'my_buggy_module'
self.set_argv('ipdb', '-m', module_name)
main()
debugger = get_debugger_cls.return_value.return_value
debugger._runmodule.assert_called_once_with(module_name)
@patch('ipdb.__main__.os.path.exists')
def test_debug_script(self, exists, get_debugger_cls):
script_name = 'my_buggy_script'
self.set_argv('ipdb', script_name)
main()
debugger = get_debugger_cls.return_value.return_value
debugger._runscript.assert_called_once_with(script_name)
def test_option_m_fallback_on_py36(self, get_debugger_cls):
self.set_argv('ipdb', '-m', 'my.module')
with patch('ipdb.__main__.sys.version_info', (3, 6)):
with self.assertRaises(GetoptError):
main()
with patch('ipdb.__main__.sys.version_info', (3, 7)):
self.set_argv('ipdb', '-m', 'my.module')
try:
main()
except GetoptError:
self.fail("GetoptError raised unexpectedly.")