示例#1
0
    def test_monkey_patch_args_module(self):
        original = SetupHolder.setup

        try:
            SetupHolder.setup = {
                'client': '127.0.0.1',
                'port': '0',
                'multiprocess': True
            }
            check = ['C:\\bin\\python.exe', '-m', 'test']
            from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file
            self.assertEqual(pydev_monkey.patch_args(check), [
                'C:\\bin\\python.exe',
                get_pydevd_file(),
                '--module',
                '--port',
                '0',
                '--client',
                '127.0.0.1',
                '--multiprocess',
                '--file',
                'test',
            ])
        finally:
            SetupHolder.setup = original
示例#2
0
    def test_monkey_patch_args_no_indc_without_pydevd(self):
        original = SetupHolder.setup
        from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file

        try:
            SetupHolder.setup = {'client': '127.0.0.1', 'port': '0'}
            check = [
                'C:\\bin\\python.exe', 'target.py', 'connect(\\"127.0.0.1\\")',
                'bar'
            ]

            self.assertEqual(pydev_monkey.patch_args(check), [
                'C:\\bin\\python.exe',
                get_pydevd_file(),
                '--port',
                '0',
                '--client',
                '127.0.0.1',
                '--file',
                'target.py',
                'connect(\\"127.0.0.1\\")',
                'bar',
            ])
        finally:
            SetupHolder.setup = original
    def test_monkey_patch_args_no_indc(self):
        original = SetupHolder.setup

        try:
            SetupHolder.setup = {'client': '127.0.0.1', 'port': '0'}
            check = [
                'C:\\bin\\python.exe', 'connect(\\"127.0.0.1\\")',
                'with spaces'
            ]
            from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file
            self.assertEqual(pydev_monkey.patch_args(check), [
                'C:\\bin\\python.exe',
                get_pydevd_file(),
                '--port',
                '0',
                '--client',
                '127.0.0.1',
                '--protocol-quoted-line',
                '--file',
                '"connect(\\\\\\"127.0.0.1\\\\\\")"'
                if sys.platform == 'win32' else 'connect(\\"127.0.0.1\\")',
                '"with spaces"' if sys.platform == 'win32' else 'with spaces',
            ])
        finally:
            SetupHolder.setup = original
示例#4
0
def test_monkey_patch_args_module_single_arg():
    original = SetupHolder.setup

    try:
        SetupHolder.setup = {'client': '127.0.0.1', 'port': '0', 'multiprocess': True}
        check = ['C:\\bin\\python.exe', '-mtest', 'bar']
        from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file
        assert pydev_monkey.patch_args(check) == [
            'C:\\bin\\python.exe',
            get_pydevd_file(),
            '--module',
            '--port',
            '0',
            '--ppid',
            str(os.getpid()),
            '--client',
            '127.0.0.1',
            '--multiprocess',
            '--protocol-quoted-line',
            '--file',
            'test',
            'bar',
        ]
    finally:
        SetupHolder.setup = original
示例#5
0
def test_monkey_patch_c_program_arg(use_bytes):
    original = SetupHolder.setup
    from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file

    try:
        SetupHolder.setup = {'client': '127.0.0.1', 'port': '0'}
        check = ['C:\\bin\\python.exe', '-u', 'target.py', '-c', '-áéíóú']

        encode = lambda s: s
        if use_bytes:
            if not IS_PY2:
                check = [c.encode('utf-8') for c in check]
                encode = lambda s: s.encode('utf-8')
        else:
            if IS_PY2:
                check = [c.decode('utf-8') for c in check]
                encode = lambda s: s.decode('utf-8')

        assert pydev_monkey.patch_args(check) == [
            encode('C:\\bin\\python.exe'),
            encode('-u'),
            get_pydevd_file(), '--port', '0', '--ppid',
            str(os.getpid()), '--client', '127.0.0.1',
            '--protocol-quoted-line', '--file',
            encode('target.py'),
            encode('-c'),
            encode('-áéíóú')
        ]
    finally:
        SetupHolder.setup = original
示例#6
0
    def test_monkey_patch_args_module(self):
        original = SetupHolder.setup

        try:
            SetupHolder.setup = {"client": "127.0.0.1", "port": "0", "multiprocess": True}
            check = ["C:\\bin\\python.exe", "-m", "test"]
            from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file

            self.assertEqual(
                pydev_monkey.patch_args(check),
                [
                    "C:\\bin\\python.exe",
                    get_pydevd_file(),
                    "--module",
                    "--port",
                    "0",
                    "--client",
                    "127.0.0.1",
                    "--multiprocess",
                    "--file",
                    "test",
                ],
            )
        finally:
            SetupHolder.setup = original
示例#7
0
def test_monkey_patch_args_no_indc_without_pydevd():
    original = SetupHolder.setup
    from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file

    try:
        SetupHolder.setup = {'client': '127.0.0.1', 'port': '0'}
        check = [
            'C:\\bin\\python.exe', 'target.py', 'connect(\\"127.0.0.1\\")',
            'bar'
        ]
        assert pydev_monkey.patch_args(check) == [
            'C:\\bin\\python.exe',
            get_pydevd_file(),
            '--port',
            '0',
            '--ppid',
            str(os.getpid()),
            '--client',
            '127.0.0.1',
            '--protocol-quoted-line',
            '--file',
            'target.py',
            '"connect(\\\\\\"127.0.0.1\\\\\\")"'
            if sys.platform == 'win32' else 'connect(\\"127.0.0.1\\")',
            'bar',
        ]
    finally:
        SetupHolder.setup = original
示例#8
0
    def test_monkey_patch_args_no_indc_without_pydevd(self):
        original = SetupHolder.setup
        from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file

        try:
            SetupHolder.setup = {"client": "127.0.0.1", "port": "0"}
            check = ["C:\\bin\\python.exe", "target.py", 'connect(\\"127.0.0.1\\")', "bar"]

            self.assertEqual(
                pydev_monkey.patch_args(check),
                [
                    "C:\\bin\\python.exe",
                    get_pydevd_file(),
                    "--port",
                    "0",
                    "--client",
                    "127.0.0.1",
                    "--file",
                    "target.py",
                    'connect(\\"127.0.0.1\\")',
                    "bar",
                ],
            )
        finally:
            SetupHolder.setup = original
示例#9
0
    def test_monkey_patch_c_program_arg(self):
        original = SetupHolder.setup
        from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file

        try:
            SetupHolder.setup = {'client': '127.0.0.1', 'port': '0'}
            check = [
                'C:\\bin\\python.exe', '-u', 'target.py', '-c', '-another_arg'
            ]

            self.assertEqual(pydev_monkey.patch_args(check), [
                'C:\\bin\\python.exe', '-u',
                get_pydevd_file(), '--port', '0', '--client', '127.0.0.1',
                '--file', 'target.py', '-c', '-another_arg'
            ])
        finally:
            SetupHolder.setup = original
    def test_monkey_patch_args_no_indc(self):
        original = SetupHolder.setup

        try:
            SetupHolder.setup = {'client': '127.0.0.1', 'port': '0'}
            check = ['C:\\bin\\python.exe', 'connect(\\"127.0.0.1\\")']
            from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file
            self.assertEqual(pydev_monkey.patch_args(check), [
                'C:\\bin\\python.exe',
                get_pydevd_file(),
                '--port',
                '0',
                '--client',
                '127.0.0.1',
                '--file',
                'connect(\\"127.0.0.1\\")'])
        finally:
            SetupHolder.setup = original
示例#11
0
    def test_monkey_patch_args_module(self):
        original = SetupHolder.setup

        try:
            SetupHolder.setup = {'client': '127.0.0.1', 'port': '0', 'multiprocess': True}
            check = ['C:\\bin\\python.exe', '-m', 'test']
            from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file
            self.assertEqual(pydev_monkey.patch_args(check), [
                'C:\\bin\\python.exe',
                get_pydevd_file(),
                '--module',
                '--port',
                '0',
                '--client',
                '127.0.0.1',
                '--multiprocess',
                '--file',
                'test',
            ])
        finally:
            SetupHolder.setup = original
示例#12
0
    def test_monkey_patch_args_no_indc_without_pydevd(self):
        original = SetupHolder.setup
        from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file

        try:
            SetupHolder.setup = {'client': '127.0.0.1', 'port': '0'}
            check = ['C:\\bin\\python.exe', 'target.py', 'connect(\\"127.0.0.1\\")', 'bar']
            self.assertEqual(pydev_monkey.patch_args(check), [
                'C:\\bin\\python.exe',
                get_pydevd_file(),
                '--port',
                '0',
                '--client',
                '127.0.0.1',
                '--file',
                'target.py',
                '"connect(\\\\\\"127.0.0.1\\\\\\")"' if sys.platform == 'win32' else 'connect(\\"127.0.0.1\\")',
                'bar',
            ])
        finally:
            SetupHolder.setup = original
示例#13
0
def test_monkey_patch_args_module_subprocess_pathlib():
    try:
        import pathlib
    except ImportError:
        pytest.skip('pathlib not available.')

    original = SetupHolder.setup

    try:
        SetupHolder.setup = {
            'client': '127.0.0.1',
            'port': '0',
            'multiprocess': True
        }
        if sys.platform == 'win32':
            python_path = 'C:\\bin\\python.exe'
        else:
            python_path = '/bin/python'
        check = [pathlib.Path(python_path), '-mtest', pathlib.Path('bar')]
        from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file
        assert pydev_monkey.patch_args(check) == [
            python_path,
            get_pydevd_file(),
            '--module',
            '--port',
            '0',
            '--ppid',
            str(os.getpid()),
            '--client',
            '127.0.0.1',
            '--multiprocess',
            '--protocol-quoted-line',
            '--file',
            'test',
            'bar',
        ]
    finally:
        SetupHolder.setup = original
示例#14
0
    def test_monkey_patch_c_program_arg(self):
        original = SetupHolder.setup
        from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file

        try:
            SetupHolder.setup = {'client': '127.0.0.1', 'port': '0'}
            check = ['C:\\bin\\python.exe', '-u', 'target.py', '-c', '-another_arg']

            self.assertEqual(pydev_monkey.patch_args(check), [
                'C:\\bin\\python.exe',
                '-u',
                get_pydevd_file(),
                '--port',
                '0',
                '--client',
                '127.0.0.1',
                '--file',
                'target.py',
                '-c',
                '-another_arg'
            ])
        finally:
            SetupHolder.setup = original