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

Commit

Permalink
add tests for remote source ref and change test folders
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne committed Jul 10, 2018
1 parent ba414ac commit b2cd7b4
Show file tree
Hide file tree
Showing 33 changed files with 250 additions and 44 deletions.
7 changes: 7 additions & 0 deletions tests/helpers/debugadapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
]


try:
ConnectionRefusedError
except Exception:
class ConnectionRefusedError(Exception):
pass


def _copy_env(verbose=False, env=None):
variables = {k: v for k, v in os.environ.items() if k in COPIED_ENV}
# TODO: Be smarter about the seed?
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import mypkg_bar.bar


def do_foo():
mypkg_bar.bar.do_bar()


do_foo()
11 changes: 11 additions & 0 deletions tests/resources/system_tests/test_forever/attach_forever.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ptvsd
import sys
import time

ptvsd.enable_attach((sys.argv[1], sys.argv[2]))

i = 0
while True:
time.sleep(0.1)
print(i)
i += 1
38 changes: 31 additions & 7 deletions tests/system_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import os
import ptvsd
import signal
import sys
import time
import traceback
import unittest

from collections import namedtuple
Expand Down Expand Up @@ -232,24 +234,46 @@ def _kill_proc(pid):
import time
time.sleep(1) # wait for socket connections to die out. # noqa

def _wrap_and_reraise(ex, session):
def _wrap_and_reraise(session, ex, exc_type, exc_value, exc_traceback):
"""If we have connetion errors, then re-raised wrapped in
ConnectionTimeoutError. If using py3, then chain exceptions so
we do not loose the original exception, else try hack approach
for py27."""
messages = []
formatted_ex = ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback)) # noqa
try:
messages = [str(msg) for msg in
_strip_newline_output_events(session.received)]
except Exception:
pass

fmt = {
"sep": os.linesep,
"messages": os.linesep.join(messages),
"error": ''.join(traceback.format_exception_only(exc_type, exc_value)) # noqa
}
message = """
Session Messages:
-----------------
%(messages)s
Original Error:
---------------
%(error)s""" % fmt

messages = os.linesep.join(messages)
try:
raise Exception(messages) from ex
except Exception:
print(messages)
raise ex
# Chain the original exception for py3.
exec('raise Exception(message) from ex', globals(), locals())
except SyntaxError:
# This happens when using py27.
message = message + os.linesep + formatted_ex
exec("raise Exception(message)", globals(), locals())

def _handle_exception(ex, adapter, session):
exc_type, exc_value, exc_traceback = sys.exc_info()
_kill_proc(adapter.pid)
_wrap_and_reraise(ex, session)
_wrap_and_reraise(session, ex, exc_type, exc_value, exc_traceback)

if debug_info.attachtype == 'import' and \
debug_info.modulename is not None:
Expand Down
22 changes: 11 additions & 11 deletions tests/system_tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,24 @@ def test_without_output(self):
self.run_test_without_output(DebugInfo(filename=filename, cwd=cwd))


class LaunchModuleTests(BasicTests):
class LaunchPackageTests(BasicTests):
def test_with_output(self):
module_name = 'mymod_launch1'
module_name = 'mypkg_launch1'
cwd = os.path.join(TEST_FILES_DIR, 'test_output')
env = {"PYTHONPATH": cwd}
self.run_test_output(
DebugInfo(modulename=module_name, env=env, cwd=cwd))

def test_without_output(self):
module_name = 'mymod_launch1'
module_name = 'mypkg_launch1'
cwd = os.path.join(TEST_FILES_DIR, 'test_without_output')
env = {"PYTHONPATH": cwd}
self.run_test_without_output(
DebugInfo(modulename=module_name, env=env, cwd=cwd))

@unittest.skip('Broken')
def test_termination(self):
module_name = 'mymod_launch1'
module_name = 'mypkg_launch1'
cwd = TEST_TERMINATION_FILES_DIR
env = {"PYTHONPATH": cwd}
self.run_test_output(
Expand All @@ -135,7 +135,7 @@ def test_termination(self):

@unittest.skip('Broken')
def test_arguments(self):
module_name = 'mymod_launch1'
module_name = 'mypkg_launch1'
cwd = os.path.join(TEST_FILES_DIR, 'test_args')
env = {"PYTHONPATH": cwd}
argv = ['arg1', 'arg2']
Expand Down Expand Up @@ -191,9 +191,9 @@ def test_without_output(self):
argv=argv))


class ServerAttachModuleTests(BasicTests): # noqa
class ServerAttachPackageTests(BasicTests): # noqa
def test_with_output(self):
module_name = 'mymod_launch1'
module_name = 'mypkg_launch1'
cwd = os.path.join(TEST_FILES_DIR, 'test_output')
env = {"PYTHONPATH": cwd}
argv = ['localhost', str(PORT)]
Expand All @@ -206,7 +206,7 @@ def test_with_output(self):
starttype='attach'))

def test_without_output(self):
module_name = 'mymod_launch1'
module_name = 'mypkg_launch1'
cwd = os.path.join(TEST_FILES_DIR, 'test_without_output')
env = {"PYTHONPATH": cwd}
argv = ['localhost', str(PORT)]
Expand All @@ -220,9 +220,9 @@ def test_without_output(self):


@unittest.skip('Needs fixing #545')
class PTVSDAttachModuleTests(BasicTests): # noqa
class PTVSDAttachPackageTests(BasicTests): # noqa
def test_with_output(self):
module_name = 'mymod_attach1'
module_name = 'mypkg_attach1'
cwd = os.path.join(TEST_FILES_DIR, 'test_output')
env = {"PYTHONPATH": cwd}
argv = ['localhost', str(PORT)]
Expand All @@ -236,7 +236,7 @@ def test_with_output(self):
starttype='attach'))

def test_without_output(self):
module_name = 'mymod_attach1'
module_name = 'mypkg_attach1'
cwd = os.path.join(TEST_FILES_DIR, 'test_without_output')
env = {"PYTHONPATH": cwd}
argv = ['localhost', str(PORT)]
Expand Down
20 changes: 10 additions & 10 deletions tests/system_tests/test_breakpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,9 @@ def test_hit_conditional_break_points_mod(self):
expected=[3, 7])


class LaunchModuleTests(BreakpointTests):
class LaunchPackageTests(BreakpointTests):
def test_with_break_points(self):
module_name = 'mymod_launch1'
module_name = 'mypkg_launch1'
cwd = os.path.join(TEST_FILES_DIR)
env = {"PYTHONPATH": cwd}
bp_filename = os.path.join(cwd, module_name, '__init__.py')
Expand All @@ -425,17 +425,17 @@ def test_with_break_points(self):
bp_line=3)

def test_with_break_points_across_files(self):
module_name = 'mymod_foo'
module_name = 'mypkg_foo'
first_file = os.path.join(TEST_FILES_DIR, module_name, '__init__.py')
second_file = os.path.join(TEST_FILES_DIR, 'mymod_bar', 'bar.py')
second_file = os.path.join(TEST_FILES_DIR, 'mypkg_bar', 'bar.py')
cwd = os.path.join(TEST_FILES_DIR)
env = {"PYTHONPATH": cwd}
expected_modules = [{
"reason": "new",
"module": {
"package": "mymod_bar",
"package": "mypkg_bar",
"path": second_file,
"name": "mymod_bar.bar"
"name": "mypkg_bar.bar"
}
}, {
"reason": "new",
Expand Down Expand Up @@ -505,9 +505,9 @@ def test_with_break_points(self):
bp_line=6)


class ServerAttachModuleTests(BreakpointTests): # noqa
class ServerAttachPackageTests(BreakpointTests): # noqa
def test_with_break_points(self):
module_name = 'mymod_launch1'
module_name = 'mypkg_launch1'
cwd = os.path.join(TEST_FILES_DIR)
env = {"PYTHONPATH": cwd}
argv = ['localhost', str(PORT)]
Expand All @@ -524,9 +524,9 @@ def test_with_break_points(self):


@unittest.skip('Needs fixing')
class PTVSDAttachModuleTests(BreakpointTests): # noqa
class PTVSDAttachPackageTests(BreakpointTests): # noqa
def test_with_break_points(self):
module_name = 'mymod_attach1'
module_name = 'mypkg_attach1'
cwd = os.path.join(TEST_FILES_DIR)
env = {"PYTHONPATH": cwd}
argv = ['localhost', str(PORT)]
Expand Down
12 changes: 6 additions & 6 deletions tests/system_tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ def test_breaking_into_handled_exceptions(self):

class LaunchModuleExceptionLifecycleTests(ExceptionTests):
def test_breaking_into_handled_exceptions(self):
module_name = 'mymod_launch1'
module_name = 'mypkg_launch1'
env = {"PYTHONPATH": TEST_FILES_DIR}
cwd = os.path.dirname(TEST_FILES_DIR)
self.run_test_breaking_into_handled_exceptions(
DebugInfo(modulename=module_name, env=env, cwd=cwd))

def test_not_breaking_into_handled_exceptions(self):
module_name = 'mymod_launch1'
module_name = 'mypkg_launch1'
env = {"PYTHONPATH": TEST_FILES_DIR}
cwd = os.path.dirname(TEST_FILES_DIR)
self.run_test_not_breaking_into_handled_exceptions(
Expand Down Expand Up @@ -162,7 +162,7 @@ def test_not_breaking_into_handled_exceptions(self):

class ServerAttachModuleExceptionLifecycleTests(ExceptionTests): # noqa
def test_breaking_into_handled_exceptions(self):
module_name = 'mymod_launch1'
module_name = 'mypkg_launch1'
env = {"PYTHONPATH": TEST_FILES_DIR}
cwd = TEST_FILES_DIR
argv = ['localhost', str(PORT)]
Expand All @@ -175,7 +175,7 @@ def test_breaking_into_handled_exceptions(self):
starttype='attach'))

def test_not_breaking_into_handled_exceptions(self):
module_name = 'mymod_launch1'
module_name = 'mypkg_launch1'
env = {"PYTHONPATH": TEST_FILES_DIR}
cwd = TEST_FILES_DIR
argv = ['localhost', str(PORT)]
Expand All @@ -191,7 +191,7 @@ def test_not_breaking_into_handled_exceptions(self):
@unittest.skip('Needs fixing')
class PTVSDAttachModuleExceptionLifecycleTests(ExceptionTests): # noqa
def test_breaking_into_handled_exceptions(self):
module_name = 'mymod_attach1'
module_name = 'mypkg_attach1'
env = {"PYTHONPATH": TEST_FILES_DIR}
cwd = TEST_FILES_DIR
argv = ['localhost', str(PORT)]
Expand All @@ -205,7 +205,7 @@ def test_breaking_into_handled_exceptions(self):
starttype='attach'))

def test_not_breaking_into_handled_exceptions(self):
module_name = 'mymod_attach1'
module_name = 'mypkg_attach1'
env = {"PYTHONPATH": TEST_FILES_DIR}
cwd = TEST_FILES_DIR
argv = ['localhost', str(PORT)]
Expand Down
Loading

0 comments on commit b2cd7b4

Please sign in to comment.