From bd220d033355ed626647f419c8f63f0ab5fe47c6 Mon Sep 17 00:00:00 2001 From: Pavel Minaev Date: Tue, 16 Oct 2018 16:03:10 -0700 Subject: [PATCH] Fix #925: Make --host a required switch --- ptvsd/__main__.py | 2 +- tests/ptvsd/test___main__.py | 45 +++++++++++++-------------- tests/system_tests/test_connection.py | 1 + 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/ptvsd/__main__.py b/ptvsd/__main__.py index 25894278..f6dc445a 100644 --- a/ptvsd/__main__.py +++ b/ptvsd/__main__.py @@ -157,7 +157,7 @@ def _parse_args(prog, argv): parser.add_argument('--nodebug', action='store_true') parser.add_argument('--client', action='store_true') - parser.add_argument('--host') + parser.add_argument('--host', required=True) parser.add_argument('--port', type=int, required=True) target = parser.add_mutually_exclusive_group(required=True) diff --git a/tests/ptvsd/test___main__.py b/tests/ptvsd/test___main__.py index ec4c72e7..51a8aa3a 100644 --- a/tests/ptvsd/test___main__.py +++ b/tests/ptvsd/test___main__.py @@ -9,22 +9,13 @@ class ParseArgsTests(unittest.TestCase): EXPECTED_EXTRA = ['--'] - def test_module(self): - args, extra = parse_args([ - 'eggs', - '--port', '8888', - '-m', 'spam', - ]) - - self.assertEqual(vars(args), { - 'kind': 'module', - 'name': 'spam', - 'address': Address.as_server(None, 8888), - 'nodebug': False, - 'single_session': False, - 'wait': False, - }) - self.assertEqual(extra, self.EXPECTED_EXTRA) + def test_host_required(self): + with self.assertRaises(SystemExit): + parse_args([ + 'eggs', + '--port', '8888', + '-m', 'spam', + ]) def test_module_server(self): args, extra = parse_args([ @@ -49,6 +40,7 @@ class ParseArgsTests(unittest.TestCase): 'eggs', '--nodebug', '--client', + '--host', 'localhost', '--port', '8888', '-m', 'spam', ]) @@ -56,7 +48,7 @@ class ParseArgsTests(unittest.TestCase): self.assertEqual(vars(args), { 'kind': 'module', 'name': 'spam', - 'address': Address.as_client(None, 8888), + 'address': Address.as_client('localhost', 8888), 'nodebug': True, 'single_session': False, 'wait': False, @@ -66,6 +58,7 @@ class ParseArgsTests(unittest.TestCase): def test_script(self): args, extra = parse_args([ 'eggs', + '--host', 'localhost', '--port', '8888', 'spam.py', ]) @@ -73,7 +66,7 @@ class ParseArgsTests(unittest.TestCase): self.assertEqual(vars(args), { 'kind': 'script', 'name': 'spam.py', - 'address': Address.as_server(None, 8888), + 'address': Address.as_server('localhost', 8888), 'nodebug': False, 'single_session': False, 'wait': False, @@ -103,6 +96,7 @@ class ParseArgsTests(unittest.TestCase): 'eggs', '--nodebug', '--client', + '--host', 'localhost', '--port', '8888', 'spam.py', ]) @@ -110,7 +104,7 @@ class ParseArgsTests(unittest.TestCase): self.assertEqual(vars(args), { 'kind': 'script', 'name': 'spam.py', - 'address': Address.as_client(None, 8888), + 'address': Address.as_client('localhost', 8888), 'nodebug': True, 'single_session': False, 'wait': False, @@ -179,6 +173,7 @@ class ParseArgsTests(unittest.TestCase): args, extra = parse_args([ 'eggs', '--single-session', + '--host', 'localhost', '--port', '8888', 'spam.py', ]) @@ -236,6 +231,7 @@ class ParseArgsTests(unittest.TestCase): args, extra = parse_args([ 'eggs', '--DEBUG', + '--host', 'localhost', '--port', '8888', '--vm_type', '???', 'spam.py', @@ -251,7 +247,7 @@ class ParseArgsTests(unittest.TestCase): self.assertEqual(vars(args), { 'kind': 'script', 'name': 'spam.py', - 'address': Address.as_server(None, 8888), + 'address': Address.as_server('localhost', 8888), 'nodebug': False, 'single_session': False, 'wait': False, @@ -274,6 +270,7 @@ class ParseArgsTests(unittest.TestCase): '--DEBUG', '--nodebug', '--client', + '--host', 'localhost', '--port', '8888', '--vm_type', '???', 'spam.py', @@ -289,7 +286,7 @@ class ParseArgsTests(unittest.TestCase): self.assertEqual(vars(args), { 'kind': 'script', 'name': 'spam.py', - 'address': Address.as_client(None, 8888), + 'address': Address.as_client('localhost', 8888), 'nodebug': True, 'single_session': False, 'wait': False, @@ -337,6 +334,7 @@ class ParseArgsTests(unittest.TestCase): def test_pseudo_backward_compatibility(self): args, extra = parse_args([ 'eggs', + '--host', 'localhost', '--port', '8888', '--module', '--file', 'spam', @@ -345,7 +343,7 @@ class ParseArgsTests(unittest.TestCase): self.assertEqual(vars(args), { 'kind': 'script', 'name': 'spam', - 'address': Address.as_server(None, 8888), + 'address': Address.as_server('localhost', 8888), 'nodebug': False, 'single_session': False, 'wait': False, @@ -357,6 +355,7 @@ class ParseArgsTests(unittest.TestCase): 'eggs', '--nodebug', '--client', + '--host', 'localhost', '--port', '8888', '--module', '--file', 'spam', @@ -365,7 +364,7 @@ class ParseArgsTests(unittest.TestCase): self.assertEqual(vars(args), { 'kind': 'script', 'name': 'spam', - 'address': Address.as_client(None, 8888), + 'address': Address.as_client('localhost', 8888), 'nodebug': True, 'single_session': False, 'wait': False, diff --git a/tests/system_tests/test_connection.py b/tests/system_tests/test_connection.py index 73096494..b65a31ad 100644 --- a/tests/system_tests/test_connection.py +++ b/tests/system_tests/test_connection.py @@ -115,6 +115,7 @@ class RawConnectionTests(unittest.TestCase): proc = Proc.start_python_module('ptvsd', [ '--server', '--wait', + '--host', 'localhost', '--port', '5678', '--file', filename, ], env={