Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Couple of bug fixes #495

Merged
merged 3 commits into from
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions ptvsd/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,28 @@
'--save-threading',
'--save-asyncio',
'--server',
'--qt-support=auto',
}

USAGE = """
{0} [-h] [--nodebug] [--host HOST | --server-host HOST] --port PORT -m MODULE [arg ...]
{0} [-h] [--nodebug] [--host HOST | --server-host HOST] --port PORT FILENAME [arg ...]
{0} [-h] [-V] [--nodebug] [--host HOST | --server-host HOST] --port PORT -m MODULE [arg ...]
{0} [-h] [-V] [--nodebug] [--host HOST | --server-host HOST] --port PORT FILENAME [arg ...]
""" # noqa


PYDEVD_DEFAULTS = {
'--qt-support=auto',
}


def _set_pydevd_defaults(pydevd_args):
args_to_append = []
for arg in PYDEVD_DEFAULTS:
if arg not in pydevd_args:
args_to_append.append(arg)
return pydevd_args + args_to_append


def parse_args(argv=None):
"""Return the parsed args to use in main()."""
if argv is None:
Expand All @@ -61,7 +75,8 @@ def parse_args(argv=None):

supported, pydevd, script = _group_args(argv)
args = _parse_args(prog, supported)
extra = pydevd
pydevd = _set_pydevd_defaults(pydevd)
extra = pydevd + ['--']
if script:
extra += script
return args, extra
Expand Down Expand Up @@ -164,6 +179,8 @@ def _parse_args(prog, argv):
target.add_argument('filename', nargs='?')

parser.add_argument('--single-session', action='store_true')
parser.add_argument('-V', '--version', action='version')
parser.version = __version__

args = parser.parse_args(argv)
ns = vars(args)
Expand Down
44 changes: 24 additions & 20 deletions tests/ptvsd/test___main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

class ParseArgsTests(unittest.TestCase):

EXPECTED_EXTRA = ['--qt-support=auto', '--']

def test_module(self):
args, extra = parse_args([
'eggs',
Expand All @@ -21,7 +23,7 @@ def test_module(self):
'nodebug': False,
'single_session': False,
})
self.assertEqual(extra, [])
self.assertEqual(extra, self.EXPECTED_EXTRA)

def test_module_server(self):
args, extra = parse_args([
Expand All @@ -38,7 +40,7 @@ def test_module_server(self):
'nodebug': False,
'single_session': False,
})
self.assertEqual(extra, [])
self.assertEqual(extra, self.EXPECTED_EXTRA)

def test_module_nodebug(self):
args, extra = parse_args([
Expand All @@ -55,7 +57,7 @@ def test_module_nodebug(self):
'nodebug': True,
'single_session': False,
})
self.assertEqual(extra, [])
self.assertEqual(extra, self.EXPECTED_EXTRA)

def test_script(self):
args, extra = parse_args([
Expand All @@ -71,7 +73,7 @@ def test_script(self):
'nodebug': False,
'single_session': False,
})
self.assertEqual(extra, [])
self.assertEqual(extra, self.EXPECTED_EXTRA)

def test_script_server(self):
args, extra = parse_args([
Expand All @@ -88,7 +90,7 @@ def test_script_server(self):
'nodebug': False,
'single_session': False,
})
self.assertEqual(extra, [])
self.assertEqual(extra, self.EXPECTED_EXTRA)

def test_script_nodebug(self):
args, extra = parse_args([
Expand All @@ -105,7 +107,7 @@ def test_script_nodebug(self):
'nodebug': True,
'single_session': False,
})
self.assertEqual(extra, [])
self.assertEqual(extra, self.EXPECTED_EXTRA)

def test_remote(self):
args, extra = parse_args([
Expand All @@ -122,7 +124,7 @@ def test_remote(self):
'nodebug': False,
'single_session': False,
})
self.assertEqual(extra, [])
self.assertEqual(extra, self.EXPECTED_EXTRA)

def test_remote_localhost(self):
args, extra = parse_args([
Expand All @@ -139,7 +141,7 @@ def test_remote_localhost(self):
'nodebug': False,
'single_session': False,
})
self.assertEqual(extra, [])
self.assertEqual(extra, self.EXPECTED_EXTRA)

def test_remote_nodebug(self):
args, extra = parse_args([
Expand All @@ -157,7 +159,7 @@ def test_remote_nodebug(self):
'nodebug': True,
'single_session': False,
})
self.assertEqual(extra, [])
self.assertEqual(extra, self.EXPECTED_EXTRA)

def test_remote_single_session(self):
args, extra = parse_args([
Expand All @@ -174,7 +176,7 @@ def test_remote_single_session(self):
'nodebug': False,
'single_session': True,
})
self.assertEqual(extra, [])
self.assertEqual(extra, self.EXPECTED_EXTRA)

def test_local_single_session(self):
args, extra = parse_args([
Expand All @@ -192,7 +194,7 @@ def test_local_single_session(self):
'nodebug': False,
'single_session': True,
})
self.assertEqual(extra, [])
self.assertEqual(extra, self.EXPECTED_EXTRA)

def test_extra(self):
args, extra = parse_args([
Expand Down Expand Up @@ -220,6 +222,7 @@ def test_extra(self):
self.assertEqual(extra, [
'--DEBUG',
'--vm_type', '???',
'--qt-support=auto', '--', # Expected pydevd defaults
'--xyz', '123',
'abc',
'--cmd-line',
Expand Down Expand Up @@ -255,6 +258,7 @@ def test_extra_nodebug(self):
self.assertEqual(extra, [
'--DEBUG',
'--vm_type', '???',
'--qt-support=auto', '--', # Expected pydevd defaults
'--xyz', '123',
'abc',
'--cmd-line',
Expand All @@ -278,7 +282,7 @@ def test_empty_host(self):
'nodebug': False,
'single_session': False,
})
self.assertEqual(extra, [])
self.assertEqual(extra, self.EXPECTED_EXTRA)

def test_unsupported_arg(self):
with self.assertRaises(SystemExit):
Expand All @@ -305,7 +309,7 @@ def test_backward_compatibility_host(self):
'nodebug': False,
'single_session': False,
})
self.assertEqual(extra, [])
self.assertEqual(extra, self.EXPECTED_EXTRA)

def test_backward_compatibility_host_nodebug(self):
args, extra = parse_args([
Expand All @@ -323,7 +327,7 @@ def test_backward_compatibility_host_nodebug(self):
'nodebug': True,
'single_session': False,
})
self.assertEqual(extra, [])
self.assertEqual(extra, self.EXPECTED_EXTRA)

def test_backward_compatibility_module(self):
args, extra = parse_args([
Expand All @@ -340,7 +344,7 @@ def test_backward_compatibility_module(self):
'nodebug': False,
'single_session': False,
})
self.assertEqual(extra, [])
self.assertEqual(extra, self.EXPECTED_EXTRA)

def test_backward_compatibility_module_nodebug(self):
args, extra = parse_args([
Expand All @@ -358,7 +362,7 @@ def test_backward_compatibility_module_nodebug(self):
'nodebug': True,
'single_session': False,
})
self.assertEqual(extra, [])
self.assertEqual(extra, self.EXPECTED_EXTRA)

def test_backward_compatibility_script(self):
args, extra = parse_args([
Expand All @@ -374,7 +378,7 @@ def test_backward_compatibility_script(self):
'nodebug': False,
'single_session': False,
})
self.assertEqual(extra, [])
self.assertEqual(extra, self.EXPECTED_EXTRA)

def test_backward_compatibility_script_nodebug(self):
args, extra = parse_args([
Expand All @@ -391,7 +395,7 @@ def test_backward_compatibility_script_nodebug(self):
'nodebug': True,
'single_session': False,
})
self.assertEqual(extra, [])
self.assertEqual(extra, self.EXPECTED_EXTRA)

def test_pseudo_backward_compatibility(self):
args, extra = parse_args([
Expand All @@ -408,7 +412,7 @@ def test_pseudo_backward_compatibility(self):
'nodebug': False,
'single_session': False,
})
self.assertEqual(extra, ['--module'])
self.assertEqual(extra, ['--module'] + self.EXPECTED_EXTRA)

def test_pseudo_backward_compatibility_nodebug(self):
args, extra = parse_args([
Expand All @@ -426,4 +430,4 @@ def test_pseudo_backward_compatibility_nodebug(self):
'nodebug': True,
'single_session': False,
})
self.assertEqual(extra, ['--module'])
self.assertEqual(extra, ['--module'] + self.EXPECTED_EXTRA)