Skip to content

Commit e5d5cda

Browse files
MrMinogotcha
authored andcommitted
Add opts tests
1 parent b2e1468 commit e5d5cda

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/test_opts.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright (c) 2012-2016 Marc Abramowitz and ipdb development team
2+
#
3+
# This file is part of ipdb.
4+
# Redistributable under the revised BSD license
5+
# https://opensource.org/licenses/BSD-3-Clause
6+
7+
import unittest
8+
from unittest.mock import patch
9+
from getopt import GetoptError
10+
from ipdb.__main__ import main
11+
12+
13+
@patch('ipdb.__main__.debugger_cls')
14+
class OptsTest(unittest.TestCase):
15+
def set_argv(self, *argv):
16+
argv_patch = patch('ipdb.__main__.sys.argv', argv)
17+
argv_patch.start()
18+
self.addCleanup(argv_patch.stop)
19+
20+
@patch('ipdb.__main__.sys.version_info', (3, 7))
21+
def test_debug_module_script(self, debugger_cls):
22+
module_name = 'my_buggy_module'
23+
self.set_argv('ipdb', '-m', module_name)
24+
25+
main()
26+
27+
debugger = debugger_cls.return_value
28+
debugger._runmodule.assert_called_once_with(module_name)
29+
30+
@patch('ipdb.__main__.os.path.exists')
31+
def test_debug_script(self, exists, debugger_cls):
32+
script_name = 'my_buggy_script'
33+
self.set_argv('ipdb', script_name)
34+
35+
main()
36+
37+
debugger = debugger_cls.return_value
38+
debugger._runscript.assert_called_once_with(script_name)
39+
40+
def test_option_m_fallback_on_py36(self, debugger_cls):
41+
self.set_argv('ipdb', '-m', 'my.module')
42+
with patch('ipdb.__main__.sys.version_info', (3, 6)):
43+
with self.assertRaises(GetoptError):
44+
main()
45+
46+
with patch('ipdb.__main__.sys.version_info', (3, 7)):
47+
self.set_argv('ipdb', '-m', 'my.module')
48+
try:
49+
main()
50+
except GetoptError:
51+
self.fail("GetoptError raised unexpectedly.")

0 commit comments

Comments
 (0)