diff --git a/tests/__init__.py b/tests/__init__.py index 47d51399..5fc3eb8d 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -36,11 +36,13 @@ import pytest_timeout # noqa # code used by the tests, and in all the test helpers. This does not affect ptvsd # inside debugged processes. + def _register_assert_rewrite(modname): modname = str(modname) # print("pytest.register_assert_rewrite({0!r})".format(modname)) pytest.register_assert_rewrite(modname) + _register_assert_rewrite("ptvsd.common") tests_submodules = pkgutil.iter_modules([str(root)]) for _, submodule, _ in tests_submodules: @@ -61,10 +63,12 @@ log.to_file(prefix="tests") # Enable JSON serialization for py.path.local. + def json_default(self, obj): if isinstance(obj, py.path.local): return obj.strpath return self.original_default(obj) + json.JsonEncoder.original_default = json.JsonEncoder.default json.JsonEncoder.default = json_default diff --git a/tests/conftest.py b/tests/conftest.py index fd9743c9..d219813b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,4 +7,4 @@ from __future__ import absolute_import, print_function, unicode_literals """pytest configuration. """ -pytest_plugins = ["tests.pytest_fixtures", "tests.pytest_hooks"] +pytest_plugins = ["tests.pytest_fixtures", "tests.pytest_hooks"] diff --git a/tests/debug/runners.py b/tests/debug/runners.py index 2e02b672..c0fed66a 100644 --- a/tests/debug/runners.py +++ b/tests/debug/runners.py @@ -197,7 +197,7 @@ def attach_by_socket( assert method in ("api", "cli") assert listener in ("server") # TODO: ("adapter", "server") - config = _attach_common_config(session, target, cwd) + config = _attach_common_config(session, target, cwd) host = config["host"] = attach_by_socket.host port = config["port"] = attach_by_socket.port diff --git a/tests/net.py b/tests/net.py index e7bb3b4a..c1f495c9 100644 --- a/tests/net.py +++ b/tests/net.py @@ -134,10 +134,7 @@ class WebRequest(object): self.exception = exc else: log.info( - "{0} --> {1} {2}", - self, - self.request.status_code, - self.request.reason + "{0} --> {1} {2}", self, self.request.status_code, self.request.reason ) def wait_for_response(self, timeout=None): diff --git a/tests/patterns/_impl.py b/tests/patterns/_impl.py index 9ab71b6b..936a8e76 100644 --- a/tests/patterns/_impl.py +++ b/tests/patterns/_impl.py @@ -146,9 +146,8 @@ class InstanceOf(Some): def __init__(self, classinfo, name=None): if isinstance(classinfo, type): classinfo = (classinfo,) - assert ( - len(classinfo) > 0 and - all((isinstance(cls, type) for cls in classinfo)) + assert len(classinfo) > 0 and all( + (isinstance(cls, type) for cls in classinfo) ), "classinfo must be a type or a tuple of types" self.name = name @@ -231,7 +230,6 @@ class ListContaining(Some): items[1:1] = self.items return items - def matches(self, other): if not isinstance(other, list): return NotImplemented diff --git a/tests/patterns/dap.py b/tests/patterns/dap.py index 5ca4a654..92e4cf54 100644 --- a/tests/patterns/dap.py +++ b/tests/patterns/dap.py @@ -49,9 +49,9 @@ def frame(source, line, **kwargs): path = source.items["path"] else: path = None - assert isinstance(path, _impl.Path), ( - "source must be some.dap.source() to use line markers in some.dap.frame()" - ) + assert isinstance( + path, _impl.Path + ), "source must be some.dap.source() to use line markers in some.dap.frame()" line = code.get_marked_line_numbers(path.path)[line] d = {"id": some.dap.id, "source": source, "line": line, "column": 1} diff --git a/tests/patterns/some.py b/tests/patterns/some.py index 9d0979ed..d1b1ca46 100644 --- a/tests/patterns/some.py +++ b/tests/patterns/some.py @@ -68,7 +68,7 @@ Usage:: }) """ -__all__ = [ +__all__ = [ "bool", "bytes", "dap", @@ -106,7 +106,9 @@ error = instanceof(Exception) bytes = instanceof(builtins.bytes) -bytes.starting_with = lambda prefix: bytes.matching(re.escape(prefix) + b".*", re.DOTALL) +bytes.starting_with = lambda prefix: bytes.matching( + re.escape(prefix) + b".*", re.DOTALL +) bytes.ending_with = lambda suffix: bytes.matching(b".*" + re.escape(suffix), re.DOTALL) bytes.containing = lambda sub: bytes.matching(b".*" + re.escape(sub) + b".*", re.DOTALL) diff --git a/tests/ptvsd/server/test_django.py b/tests/ptvsd/server/test_django.py index a485961e..b1237e07 100644 --- a/tests/ptvsd/server/test_django.py +++ b/tests/ptvsd/server/test_django.py @@ -88,7 +88,9 @@ def test_django_breakpoint_no_multiproc(start_django, bp_target): def test_django_template_exception_no_multiproc(start_django): with debug.Session() as session: with start_django(session): - session.request("setExceptionBreakpoints", {"filters": ["raised", "uncaught"]}) + session.request( + "setExceptionBreakpoints", {"filters": ["raised", "uncaught"]} + ) with django_server: django_server.get("/badtemplate", log_errors=False) @@ -134,7 +136,9 @@ def test_django_exception_no_multiproc(start_django, exc_type): with debug.Session() as session: with start_django(session): - session.request("setExceptionBreakpoints", {"filters": ["raised", "uncaught"]}) + session.request( + "setExceptionBreakpoints", {"filters": ["raised", "uncaught"]} + ) with django_server: django_server.get("/" + exc_type) diff --git a/tests/ptvsd/server/test_exception.py b/tests/ptvsd/server/test_exception.py index 5e934e7e..f7d132d9 100644 --- a/tests/ptvsd/server/test_exception.py +++ b/tests/ptvsd/server/test_exception.py @@ -15,9 +15,7 @@ str_matching_ArithmeticError = some.str.matching(r"(.+\.)?ArithmeticError") @pytest.mark.parametrize("raised", ["raised", ""]) @pytest.mark.parametrize("uncaught", ["uncaught", ""]) -def test_vsc_exception_options_raise_with_except( - pyfile, target, run, raised, uncaught -): +def test_vsc_exception_options_raise_with_except(pyfile, target, run, raised, uncaught): @pyfile def code_to_debug(): import debug_me # noqa @@ -85,10 +83,12 @@ def test_vsc_exception_options_raise_without_except( with debug.Session() as session: session.ignore_unobserved.append(Event("stopped")) session.expected_exit_code = some.int + with run(session, target(code_to_debug)): session.request( "setExceptionBreakpoints", {"filters": list({raised, uncaught} - {""})} ) + expected_exc_info = some.dict.containing( { "exceptionId": str_matching_ArithmeticError, @@ -253,11 +253,11 @@ def test_raise_exception_options(pyfile, target, run, exceptions, break_mode): with debug.Session() as session: session.ignore_unobserved.append(Event("stopped")) session.expected_exit_code = some.int - path = [{"names": ["Python Exceptions"]}] - if exceptions: - path.append({"names": exceptions}) with run(session, target(code_to_debug)): + path = [{"names": ["Python Exceptions"]}] + if exceptions: + path.append({"names": exceptions}) session.request( "setExceptionBreakpoints", { @@ -329,9 +329,9 @@ def test_exception_stack(pyfile, target, run, max_frames): do_something(100) - with debug.Session() as session: session.expected_exit_code = some.int + max_frames, (min_expected_lines, max_expected_lines) = { "all": (0, (100, 221)), "default": (None, (100, 221)), diff --git a/tests/ptvsd/server/test_exclude_rules.py b/tests/ptvsd/server/test_exclude_rules.py index c7f06976..02218cf0 100644 --- a/tests/ptvsd/server/test_exclude_rules.py +++ b/tests/ptvsd/server/test_exclude_rules.py @@ -12,9 +12,7 @@ from tests.patterns import some @pytest.mark.parametrize("scenario", ["exclude_by_name", "exclude_by_dir"]) @pytest.mark.parametrize("exc_type", ["RuntimeError", "SystemExit"]) -def test_exceptions_and_exclude_rules( - pyfile, target, run, scenario, exc_type -): +def test_exceptions_and_exclude_rules(pyfile, target, run, scenario, exc_type): if exc_type == "RuntimeError": @pyfile @@ -109,12 +107,12 @@ def test_exceptions_and_partial_exclude_rules(pyfile, target, run, scenario): some.dap.frame( some.dap.source(call_me_back_py), line=call_me_back_py.lines["callback"], - ), + ) ], ) - assert stop.frames != some.list.containing([ - some.dap.frame(some.dap.source(code_to_debug), line=some.int), - ]) + assert stop.frames != some.list.containing( + [some.dap.frame(some.dap.source(code_to_debug), line=some.int)] + ) # As exception unwinds the stack, we shouldn't stop at @call_me_back, # since that line is in the excluded file. Furthermore, although the @@ -143,9 +141,9 @@ def test_exceptions_and_partial_exclude_rules(pyfile, target, run, scenario): ), ], ) - assert stop.frames != some.list.containing([ - some.dap.frame(some.dap.source(call_me_back_py), line=some.int), - ]) + assert stop.frames != some.list.containing( + [some.dap.frame(some.dap.source(call_me_back_py), line=some.int)] + ) session.request_continue() @@ -158,12 +156,12 @@ def test_exceptions_and_partial_exclude_rules(pyfile, target, run, scenario): some.dap.source(code_to_debug), name="", line=code_to_debug.lines["call_me_back"], - ), + ) ], ) - assert stop.frames != some.list.containing([ - some.dap.frame(some.dap.source(call_me_back_py), line=some.int), - ]) + assert stop.frames != some.list.containing( + [some.dap.frame(some.dap.source(call_me_back_py), line=some.int)] + ) session.request_continue() @@ -183,9 +181,9 @@ def test_exceptions_and_partial_exclude_rules(pyfile, target, run, scenario): ), ], ) - assert stop.frames != some.list.containing([ - some.dap.frame(some.dap.source(call_me_back_py), line=some.int), - ]) + assert stop.frames != some.list.containing( + [some.dap.frame(some.dap.source(call_me_back_py), line=some.int)] + ) # Let the process crash due to unhandled exception. session.request_continue() diff --git a/tests/ptvsd/server/test_flask.py b/tests/ptvsd/server/test_flask.py index 883a9be9..83152d01 100644 --- a/tests/ptvsd/server/test_flask.py +++ b/tests/ptvsd/server/test_flask.py @@ -38,19 +38,18 @@ def start_flask(run): # No clean way to kill Flask server, expect non-zero exit code session.expected_exit_code = some.int - session.config.env.update({ - "FLASK_APP": paths.app_py, - "FLASK_ENV": "development", - "FLASK_DEBUG": "1" if multiprocess else "0", - }) + session.config.env.update( + { + "FLASK_APP": paths.app_py, + "FLASK_ENV": "development", + "FLASK_DEBUG": "1" if multiprocess else "0", + } + ) if platform.system() != "Windows": locale = "en_US.utf8" if platform.system() == "Linux" else "en_US.UTF-8" session.config.env.update({"LC_ALL": locale, "LANG": locale}) - session.config.update({ - "jinja": True, - "subProcess": bool(multiprocess), - }) + session.config.update({"jinja": True, "subProcess": bool(multiprocess)}) args = ["run"] if not multiprocess: @@ -102,7 +101,9 @@ def test_flask_breakpoint_no_multiproc(start_flask, bp_target): def test_flask_template_exception_no_multiproc(start_flask): with debug.Session() as session: with start_flask(session): - session.request("setExceptionBreakpoints", {"filters": ["raised", "uncaught"]}) + session.request( + "setExceptionBreakpoints", {"filters": ["raised", "uncaught"]} + ) with flask_server: flask_server.get("/badtemplate") @@ -155,7 +156,9 @@ def test_flask_exception_no_multiproc(start_flask, exc_type): with debug.Session() as session: with start_flask(session): - session.request("setExceptionBreakpoints", {"filters": ["raised", "uncaught"]}) + session.request( + "setExceptionBreakpoints", {"filters": ["raised", "uncaught"]} + ) with flask_server: flask_server.get("/" + exc_type) diff --git a/tests/ptvsd/server/test_justmycode.py b/tests/ptvsd/server/test_justmycode.py index ff86a84e..7427c989 100644 --- a/tests/ptvsd/server/test_justmycode.py +++ b/tests/ptvsd/server/test_justmycode.py @@ -20,14 +20,12 @@ def test_justmycode_frames(pyfile, target, run, jmc): with debug.Session() as session: session.config["justMyCode"] = bool(jmc) + with run(session, target(code_to_debug)): session.set_breakpoints(code_to_debug, all) stop = session.wait_for_stop( - "breakpoint", - expected_frames=[ - some.dap.frame(code_to_debug, "bp") - ], + "breakpoint", expected_frames=[some.dap.frame(code_to_debug, "bp")] ) if jmc: assert len(stop.frames) == 1 diff --git a/tests/ptvsd/server/test_log.py b/tests/ptvsd/server/test_log.py index c8a5863c..2340e83e 100644 --- a/tests/ptvsd/server/test_log.py +++ b/tests/ptvsd/server/test_log.py @@ -43,6 +43,7 @@ def test_log_dir(pyfile, tmpdir, target, method): with check_logs(tmpdir, run): with debug.Session() as session: session.log_dir = None + with run(session, target(code_to_debug)): pass diff --git a/tests/ptvsd/server/test_multiproc.py b/tests/ptvsd/server/test_multiproc.py index 6bd3579c..222db585 100644 --- a/tests/ptvsd/server/test_multiproc.py +++ b/tests/ptvsd/server/test_multiproc.py @@ -23,7 +23,9 @@ pytestmark = pytest.mark.skip("https://github.com/microsoft/ptvsd/issues/1706") platform.system() != "Windows", reason="Debugging multiprocessing module only works on Windows", ) -@pytest.mark.parametrize("start_method", [runners.launch, runners.attach_by_socket["cli"]]) +@pytest.mark.parametrize( + "start_method", [runners.launch, runners.attach_by_socket["cli"]] +) def test_multiprocessing(pyfile, start_method, run_as): @pyfile def code_to_debug(): @@ -143,7 +145,9 @@ def test_multiprocessing(pyfile, start_method, run_as): @pytest.mark.skipif( sys.version_info < (3, 0) and (platform.system() != "Windows"), reason="Bug #935" ) -@pytest.mark.parametrize("start_method", [runners.launch, runners.attach_by_socket["cli"]]) +@pytest.mark.parametrize( + "start_method", [runners.launch, runners.attach_by_socket["cli"]] +) def test_subprocess(pyfile, start_method, run_as): @pyfile def child(): @@ -210,7 +214,9 @@ def test_subprocess(pyfile, start_method, run_as): @pytest.mark.skipif( sys.version_info < (3, 0) and (platform.system() != "Windows"), reason="Bug #935" ) -@pytest.mark.parametrize("start_method", [runners.launch, runners.attach_by_socket["cli"]]) +@pytest.mark.parametrize( + "start_method", [runners.launch, runners.attach_by_socket["cli"]] +) def test_autokill(pyfile, start_method, run_as): @pyfile def child(): @@ -239,17 +245,13 @@ def test_autokill(pyfile, start_method, run_as): with debug.Session(start_method, backchannel=True) as parent_session: parent_backchannel = parent_session.backchannel - expected_exit_code = some.int if parent_session.start_method.method == "launch" else 0 - parent_session.expected_exit_code = expected_exit_code - parent_session.configure( - run_as, - parent, - subProcess=True, - args=[child], + expected_exit_code = ( + some.int if parent_session.start_method.method == "launch" else 0 ) + parent_session.expected_exit_code = expected_exit_code + parent_session.configure(run_as, parent, subProcess=True, args=[child]) parent_session.start_debugging() - with parent_session.attach_to_next_subprocess() as child_session: child_session.start_debugging() @@ -312,10 +314,7 @@ def test_argv_quoting(pyfile, start_method, run_as): with debug.Session(start_method, backchannel=True) as session: backchannel = session.backchannel - session.configure( - run_as, parent, - args=[child], - ) + session.configure(run_as, parent, args=[child]) session.start_debugging() @@ -325,22 +324,22 @@ def test_argv_quoting(pyfile, start_method, run_as): def test_echo_and_shell(pyfile, run_as, start_method): - ''' + """ Checks https://github.com/microsoft/ptvsd/issues/1548 - ''' + """ @pyfile def code_to_run(): - import debug_me # noqa + import debug_me # noqa import sys import subprocess import os - if sys.platform == 'win32': - args = ['dir', '-c', '.'] + if sys.platform == "win32": + args = ["dir", "-c", "."] else: - args = ['ls', '-c', '-la'] + args = ["ls", "-c", "-la"] p = subprocess.Popen( args, @@ -351,12 +350,12 @@ def test_echo_and_shell(pyfile, run_as, start_method): ) stdout, _stderr = p.communicate() if sys.version_info[0] >= 3: - stdout = stdout.decode('utf-8') + stdout = stdout.decode("utf-8") if "code_to_run.py" not in stdout: raise AssertionError( - 'Did not find "code_to_run.py" when listing this dir with subprocess. Contents: %s' % ( - stdout,) + 'Did not find "code_to_run.py" when listing this dir with subprocess. Contents: %s' + % (stdout,) ) with debug.Session(start_method) as session: diff --git a/tests/ptvsd/server/test_output.py b/tests/ptvsd/server/test_output.py index 086e0254..9fa0e833 100644 --- a/tests/ptvsd/server/test_output.py +++ b/tests/ptvsd/server/test_output.py @@ -19,6 +19,7 @@ def test_with_no_output(pyfile, target, run): @pyfile def code_to_debug(): import debug_me # noqa + () # @wait_for_output with debug.Session() as session: @@ -46,6 +47,7 @@ def test_with_tab_in_output(pyfile, target, run): with debug.Session() as session: with run(session, target(code_to_debug)): session.set_breakpoints(code_to_debug, all) + session.wait_for_stop() session.request_continue() @@ -64,9 +66,11 @@ def test_redirect_output(pyfile, target, run, redirect): () # @wait_for_output with debug.Session() as session: - session.config["redirectOutput"] = (redirect == "enabled") + session.config["redirectOutput"] = redirect == "enabled" + with run(session, target(code_to_debug)): session.set_breakpoints(code_to_debug, all) + session.wait_for_stop() session.request_continue() diff --git a/tests/ptvsd/server/test_path_mapping.py b/tests/ptvsd/server/test_path_mapping.py index a540cf56..edf6ba50 100644 --- a/tests/ptvsd/server/test_path_mapping.py +++ b/tests/ptvsd/server/test_path_mapping.py @@ -29,13 +29,12 @@ def test_with_dot_remote_root(pyfile, long_tmpdir, target, run): code_to_debug.copy(path_remote) with debug.Session() as session: - backchannel = session.open_backchannel() session.config["pathMappings"] = [{"localRoot": dir_local, "remoteRoot": "."}] - # Run using remote path + backchannel = session.open_backchannel() with run(session, target(path_remote), cwd=dir_remote): - # Set breakpoints using local path. This ensures that - # local paths are mapped to remote paths. + # Set breakpoints using local path. This tests that local paths are + # mapped to remote paths. session.set_breakpoints(path_local, all) actual_path_remote = backchannel.receive() @@ -81,15 +80,14 @@ def test_with_path_mappings(pyfile, long_tmpdir, target, run): call_me_back_py = call_me_back_dir / "call_me_back.py" with debug.Session() as session: - backchannel = session.open_backchannel() session.config["pathMappings"] = [ {"localRoot": dir_local, "remoteRoot": dir_remote} ] - # Run using remote path + backchannel = session.open_backchannel() with run(session, target(path_remote)): - # Set breakpoints using local path. This ensures that - # local paths are mapped to remote paths. + # Set breakpoints using local path. This tests that local paths are + # mapped to remote paths. session.set_breakpoints(path_local, ["bp"]) actual_path_remote = backchannel.receive() diff --git a/tests/ptvsd/server/test_stop_on_entry.py b/tests/ptvsd/server/test_stop_on_entry.py index 7a7e0122..2b8bd988 100644 --- a/tests/ptvsd/server/test_stop_on_entry.py +++ b/tests/ptvsd/server/test_stop_on_entry.py @@ -30,18 +30,15 @@ def test_stop_on_entry(pyfile, run, target, breakpoint): if breakpoint: stop = session.wait_for_stop( - "breakpoint", - expected_frames=[some.dap.frame(code_to_debug, 1)] + "breakpoint", expected_frames=[some.dap.frame(code_to_debug, 1)] ) session.request("next", {"threadId": stop.thread_id}) stop = session.wait_for_stop( - "step", - expected_frames=[some.dap.frame(code_to_debug, 3)] + "step", expected_frames=[some.dap.frame(code_to_debug, 3)] ) else: session.wait_for_stop( - "entry", - expected_frames=[some.dap.frame(code_to_debug, 1)] + "entry", expected_frames=[some.dap.frame(code_to_debug, 1)] ) session.request_continue() diff --git a/tests/ptvsd/server/test_tracing.py b/tests/ptvsd/server/test_tracing.py index b911d746..bc56c3de 100644 --- a/tests/ptvsd/server/test_tracing.py +++ b/tests/ptvsd/server/test_tracing.py @@ -11,12 +11,12 @@ from tests.patterns import some def test_tracing(pyfile, target, run): @pyfile def code_to_debug(): - import debug_me # noqa + import debug_me # noqa import ptvsd def func(expected_tracing): - assert ptvsd.tracing() == expected_tracing, ( - "inside func({0!r})".format(expected_tracing) + assert ptvsd.tracing() == expected_tracing, "inside func({0!r})".format( + expected_tracing ) print(1) # @inner1 @@ -53,22 +53,14 @@ def test_tracing(pyfile, target, run): with run(session, target(code_to_debug)): session.set_breakpoints(code_to_debug, all) - session.wait_for_stop( - expected_frames=[some.dap.frame(code_to_debug, "inner2")] - ) + session.wait_for_stop(expected_frames=[some.dap.frame(code_to_debug, "inner2")]) session.request_continue() - session.wait_for_stop( - expected_frames=[some.dap.frame(code_to_debug, "outer2")] - ) + session.wait_for_stop(expected_frames=[some.dap.frame(code_to_debug, "outer2")]) session.request_continue() - session.wait_for_stop( - expected_frames=[some.dap.frame(code_to_debug, "inner1")] - ) + session.wait_for_stop(expected_frames=[some.dap.frame(code_to_debug, "inner1")]) session.request_continue() - session.wait_for_stop( - expected_frames=[some.dap.frame(code_to_debug, "inner3")] - ) + session.wait_for_stop(expected_frames=[some.dap.frame(code_to_debug, "inner3")]) session.request_continue() diff --git a/tests/pydevd_log.py b/tests/pydevd_log.py index 6606b11f..f254cbe3 100644 --- a/tests/pydevd_log.py +++ b/tests/pydevd_log.py @@ -12,20 +12,20 @@ from ptvsd.common import log @contextlib.contextmanager def enabled(filename): - os.environ['PYDEVD_DEBUG'] = 'True' - os.environ['PYDEVD_DEBUG_FILE'] = filename + os.environ["PYDEVD_DEBUG"] = "True" + os.environ["PYDEVD_DEBUG_FILE"] = filename log.debug("pydevd log will be at {0}", filename) try: yield finally: - del os.environ['PYDEVD_DEBUG'] - del os.environ['PYDEVD_DEBUG_FILE'] + del os.environ["PYDEVD_DEBUG"] + del os.environ["PYDEVD_DEBUG_FILE"] def dump(why): assert why - pydevd_debug_file = os.environ.get('PYDEVD_DEBUG_FILE') + pydevd_debug_file = os.environ.get("PYDEVD_DEBUG_FILE") if not pydevd_debug_file: return @@ -34,7 +34,11 @@ def dump(why): with f: pydevd_log = f.read() except Exception: - log.exception("Test {0}, but pydevd log {1} could not be retrieved.", why, pydevd_debug_file) + log.exception( + "Test {0}, but pydevd log {1} could not be retrieved.", + why, + pydevd_debug_file, + ) return log.info("Test {0}; pydevd log:\n\n{1}", why, pydevd_log) diff --git a/tests/test_data/bp/a&b/test.py b/tests/test_data/bp/a&b/test.py index 556d2e07..65263105 100644 --- a/tests/test_data/bp/a&b/test.py +++ b/tests/test_data/bp/a&b/test.py @@ -1,4 +1,5 @@ import debug_me # noqa -print('one') # @one -print('two') # @two -print('three') # @three + +print("one") # @one +print("two") # @two +print("three") # @three diff --git a/tests/test_data/django1/app.py b/tests/test_data/django1/app.py index 5a5c30e3..fb0cee49 100644 --- a/tests/test_data/django1/app.py +++ b/tests/test_data/django1/app.py @@ -12,8 +12,9 @@ from django.template import loader def sigint_handler(signal, frame): import django.dispatch + djshutdown = django.dispatch.Signal() - djshutdown.send('system') + djshutdown.send("system") sys.exit(0) @@ -21,96 +22,84 @@ signal.signal(signal.SIGINT, sigint_handler) settings.configure( DEBUG=True, - SECRET_KEY='CD8FF4C1-7E6C-4E45-922D-C796271F2345', + SECRET_KEY="CD8FF4C1-7E6C-4E45-922D-C796271F2345", ROOT_URLCONF=sys.modules[__name__], - SETTINGS_MODULE='', # Added to avoid a KeyError during shutdown on the bad template test. + SETTINGS_MODULE="", # Added to avoid a KeyError during shutdown on the bad template test. TEMPLATES=[ { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'APP_DIRS': True, - 'DIRS': [ - os.path.join(os.path.dirname(__file__), 'templates'), - ] - }, - ] + "BACKEND": "django.template.backends.django.DjangoTemplates", + "APP_DIRS": True, + "DIRS": [os.path.join(os.path.dirname(__file__), "templates")], + } + ], ) def home(request): - title = 'hello' - content = 'Django-Django-Test' - template = loader.get_template('hello.html') # @bphome - context = { - 'title': title, - 'content': content, - } + title = "hello" + content = "Django-Django-Test" + template = loader.get_template("hello.html") # @bphome + context = {"title": title, "content": content} return HttpResponse(template.render(context, request)) def bad_route_handled(request): try: - raise ArithmeticError('Hello') # @exc_handled + raise ArithmeticError("Hello") # @exc_handled except Exception: pass - title = 'hello' - content = 'Django-Django-Test' - template = loader.get_template('hello.html') - context = { - 'title': title, - 'content': content, - } + title = "hello" + content = "Django-Django-Test" + template = loader.get_template("hello.html") + context = {"title": title, "content": content} return HttpResponse(template.render(context, request)) def bad_route_unhandled(request): - raise ArithmeticError('Hello') # @exc_unhandled - title = 'hello' - content = 'Django-Django-Test' - template = loader.get_template('hello.html') - context = { - 'title': title, - 'content': content, - } + raise ArithmeticError("Hello") # @exc_unhandled + title = "hello" + content = "Django-Django-Test" + template = loader.get_template("hello.html") + context = {"title": title, "content": content} return HttpResponse(template.render(context, request)) def bad_template(request): - title = 'hello' - content = 'Django-Django-Test' - context = { - 'title': title, - 'content': content, - } - template = loader.get_template('bad.html') + title = "hello" + content = "Django-Django-Test" + context = {"title": title, "content": content} + template = loader.get_template("bad.html") return HttpResponse(template.render(context, request)) def exit_app(request): - if hasattr(signal, 'SIGBREAK'): + if hasattr(signal, "SIGBREAK"): os.kill(os.getpid(), signal.SIGBREAK) else: os.kill(os.getpid(), signal.SIGTERM) - return HttpResponse('Done') + return HttpResponse("Done") if sys.version_info < (3, 0): from django.conf.urls import url + urlpatterns = [ - url(r'home', home, name='home'), - url(r'^handled$', bad_route_handled, name='bad_route_handled'), - url(r'^unhandled$', bad_route_unhandled, name='bad_route_unhandled'), - url(r'badtemplate', bad_template, name='bad_template'), - url(r'exit', exit_app, name='exit_app'), + url(r"home", home, name="home"), + url(r"^handled$", bad_route_handled, name="bad_route_handled"), + url(r"^unhandled$", bad_route_unhandled, name="bad_route_unhandled"), + url(r"badtemplate", bad_template, name="bad_template"), + url(r"exit", exit_app, name="exit_app"), ] else: from django.urls import path + urlpatterns = [ - path('home', home, name='home'), - path('handled', bad_route_handled, name='bad_route_handled'), - path('unhandled', bad_route_unhandled, name='bad_route_unhandled'), - path('badtemplate', bad_template, name='bad_template'), - path('exit', exit_app, name='exit_app'), + path("home", home, name="home"), + path("handled", bad_route_handled, name="bad_route_handled"), + path("unhandled", bad_route_unhandled, name="bad_route_unhandled"), + path("badtemplate", bad_template, name="bad_template"), + path("exit", exit_app, name="exit_app"), ] -if __name__ == '__main__': +if __name__ == "__main__": execute_from_command_line(sys.argv) diff --git a/tests/test_data/flask1/app.py b/tests/test_data/flask1/app.py index 3036b770..b0934e38 100644 --- a/tests/test_data/flask1/app.py +++ b/tests/test_data/flask1/app.py @@ -7,52 +7,37 @@ app = Flask(__name__) @app.route("/") def home(): - content = 'Flask-Jinja-Test' - print('break here') # @bphome - return render_template( - "hello.html", - title='Hello', - content=content - ) + content = "Flask-Jinja-Test" + print("break here") # @bphome + return render_template("hello.html", title="Hello", content=content) @app.route("/handled") def bad_route_handled(): try: - raise ArithmeticError('Hello') # @exc_handled + raise ArithmeticError("Hello") # @exc_handled except Exception: pass - return render_template( - "hello.html", - title='Hello', - content='Flask-Jinja-Test' - ) + return render_template("hello.html", title="Hello", content="Flask-Jinja-Test") @app.route("/unhandled") def bad_route_unhandled(): - raise ArithmeticError('Hello') # @exc_unhandled - return render_template( - "hello.html", - title='Hello', - content='Flask-Jinja-Test' - ) + raise ArithmeticError("Hello") # @exc_unhandled + return render_template("hello.html", title="Hello", content="Flask-Jinja-Test") @app.route("/badtemplate") def bad_template(): - return render_template( - "bad.html", - title='Hello', - content='Flask-Jinja-Test' - ) + return render_template("bad.html", title="Hello", content="Flask-Jinja-Test") @app.route("/exit") def exit_app(): from flask import request - func = request.environ.get('werkzeug.server.shutdown') + + func = request.environ.get("werkzeug.server.shutdown") if func is None: - raise RuntimeError('No shutdown') + raise RuntimeError("No shutdown") func() - return 'Done' + return "Done" diff --git a/tests/test_data/testpkgs/pkg1/__main__.py b/tests/test_data/testpkgs/pkg1/__main__.py index 9426f13e..98290064 100644 --- a/tests/test_data/testpkgs/pkg1/__main__.py +++ b/tests/test_data/testpkgs/pkg1/__main__.py @@ -1,5 +1,6 @@ import sys -print('one') # @one -print('two') # @two -print('three') # @three -sys.exit(42) \ No newline at end of file + +print("one") # @one +print("two") # @two +print("three") # @three +sys.exit(42) diff --git a/tests/test_data/testpkgs/pkg1/sub/__main__.py b/tests/test_data/testpkgs/pkg1/sub/__main__.py index f59a0385..a3dc875d 100644 --- a/tests/test_data/testpkgs/pkg1/sub/__main__.py +++ b/tests/test_data/testpkgs/pkg1/sub/__main__.py @@ -1,2 +1,3 @@ from debug_me import backchannel + backchannel.send("ok") diff --git a/tests/tests/test_patterns.py b/tests/tests/test_patterns.py index b4441cdc..fd6c4794 100644 --- a/tests/tests/test_patterns.py +++ b/tests/tests/test_patterns.py @@ -22,16 +22,26 @@ def log_repr(x): VALUES = [ object(), - True, False, - 0, -1, -1.0, 1.23, - b'abc', b'abcd', - u'abc', u'abcd', - (), (1, 2, 3), - [], [1, 2, 3], - {}, {'a': 1, 'b': 2}, + True, + False, + 0, + -1, + -1.0, + 1.23, + b"abc", + b"abcd", + "abc", + "abcd", + (), + (1, 2, 3), + [], + [1, 2, 3], + {}, + {"a": 1, "b": 2}, ] -@pytest.mark.parametrize('x', VALUES) + +@pytest.mark.parametrize("x", VALUES) def test_value(x): log_repr(some.object) assert x == some.object @@ -113,7 +123,7 @@ def test_in_range(): def test_str(): log_repr(some.str) - assert some.str == u"abc" + assert some.str == "abc" if sys.version_info < (3,): assert b"abc" == some.str @@ -213,13 +223,13 @@ def test_list(): def test_dict(): - pattern = {'a': some.thing, 'b': 2} + pattern = {"a": some.thing, "b": 2} log_repr(pattern) - assert pattern == {'a': 1, 'b': 2} + assert pattern == {"a": 1, "b": 2} - pattern = some.dict.containing({'a': 1}) + pattern = some.dict.containing({"a": 1}) log_repr(pattern) - assert pattern == {'a': 1, 'b': 2} + assert pattern == {"a": 1, "b": 2} def test_such_that(): @@ -233,25 +243,22 @@ def test_such_that(): def test_error(): log_repr(some.error) - assert some.error == Exception('error!') + assert some.error == Exception("error!") assert some.error != {} def test_recursive(): - pattern = some.dict.containing({ - "dict": some.dict.containing({ - "int": some.int.in_range(100, 200), - }), - "list": [None, ~some.error, some.number | some.str], - }) + pattern = some.dict.containing( + { + "dict": some.dict.containing({"int": some.int.in_range(100, 200)}), + "list": [None, ~some.error, some.number | some.str], + } + ) log_repr(pattern) assert pattern == { "list": [None, False, 123], "bool": True, - "dict": { - "int": 123, - "str": "abc", - }, + "dict": {"int": 123, "str": "abc"}, } diff --git a/tests/tests/test_timeline.py b/tests/tests/test_timeline.py index e7354e34..b5494867 100644 --- a/tests/tests/test_timeline.py +++ b/tests/tests/test_timeline.py @@ -65,7 +65,7 @@ def make_timeline(request): history = timeline.history() history.sort(key=lambda occ: occ.timestamp) assert history == timeline.history() - assert history[-1] == Mark('FINISH') + assert history[-1] == Mark("FINISH") timeline.close() @@ -73,47 +73,64 @@ def make_timeline(request): def test_occurrences(make_timeline): timeline, initial_history = make_timeline() - mark1 = timeline.mark('dum') - mark2 = timeline.mark('dee') - mark3 = timeline.mark('dum') + mark1 = timeline.mark("dum") + mark2 = timeline.mark("dee") + mark3 = timeline.mark("dum") - assert mark1 == Mark('dum') - assert mark1.id == 'dum' - assert mark2 == Mark('dee') - assert mark2.id == 'dee' - assert mark3 == Mark('dum') - assert mark3.id == 'dum' + assert mark1 == Mark("dum") + assert mark1.id == "dum" + assert mark2 == Mark("dee") + assert mark2.id == "dee" + assert mark3 == Mark("dum") + assert mark3.id == "dum" with timeline.frozen(): - assert timeline.history() == initial_history + [some.object.same_as(mark1), some.object.same_as(mark2), some.object.same_as(mark3)] + assert timeline.history() == initial_history + [ + some.object.same_as(mark1), + some.object.same_as(mark2), + some.object.same_as(mark3), + ] timeline.finalize() - assert timeline.all_occurrences_of(Mark('dum')) == (some.object.same_as(mark1), some.object.same_as(mark3)) - assert timeline.all_occurrences_of(Mark('dee')) == (some.object.same_as(mark2),) + assert timeline.all_occurrences_of(Mark("dum")) == ( + some.object.same_as(mark1), + some.object.same_as(mark3), + ) + assert timeline.all_occurrences_of(Mark("dee")) == (some.object.same_as(mark2),) - assert timeline[:].all_occurrences_of(Mark('dum')) == (some.object.same_as(mark1), some.object.same_as(mark3)) + assert timeline[:].all_occurrences_of(Mark("dum")) == ( + some.object.same_as(mark1), + some.object.same_as(mark3), + ) # Lower boundary is inclusive. - assert timeline[mark1:].all_occurrences_of(Mark('dum')) == (some.object.same_as(mark1), some.object.same_as(mark3)) - assert timeline[mark2:].all_occurrences_of(Mark('dum')) == (some.object.same_as(mark3),) - assert timeline[mark3:].all_occurrences_of(Mark('dum')) == (some.object.same_as(mark3),) + assert timeline[mark1:].all_occurrences_of(Mark("dum")) == ( + some.object.same_as(mark1), + some.object.same_as(mark3), + ) + assert timeline[mark2:].all_occurrences_of(Mark("dum")) == ( + some.object.same_as(mark3), + ) + assert timeline[mark3:].all_occurrences_of(Mark("dum")) == ( + some.object.same_as(mark3), + ) # Upper boundary is exclusive. - assert timeline[:mark1].all_occurrences_of(Mark('dum')) == () - assert timeline[:mark2].all_occurrences_of(Mark('dum')) == (some.object.same_as(mark1),) - assert timeline[:mark3].all_occurrences_of(Mark('dum')) == (some.object.same_as(mark1),) + assert timeline[:mark1].all_occurrences_of(Mark("dum")) == () + assert timeline[:mark2].all_occurrences_of(Mark("dum")) == ( + some.object.same_as(mark1), + ) + assert timeline[:mark3].all_occurrences_of(Mark("dum")) == ( + some.object.same_as(mark1), + ) def expectation_of(message): if isinstance(message, messaging.Event): - return Event( - some.str.equal_to(message.event), - some.dict.equal_to(message.body), - ) + return Event(some.str.equal_to(message.event), some.dict.equal_to(message.body)) elif isinstance(message, messaging.Request): return Request( - some.str.equal_to(message.command), - some.dict.equal_to(message.arguments), + some.str.equal_to(message.command), some.dict.equal_to(message.arguments) ) else: raise AssertionError("Unsupported message type") @@ -123,17 +140,13 @@ def test_event(make_timeline): timeline, initial_history = make_timeline() messages = MessageFactory() - event_msg = messages.event("stopped", {'reason': 'pause'}) + event_msg = messages.event("stopped", {"reason": "pause"}) event_exp = expectation_of(event_msg) event = timeline.record_event(event_msg) assert event == event_exp assert event.message is event_msg - assert event.circumstances == ( - "event", - event_msg.event, - event_msg.body, - ) + assert event.circumstances == ("event", event_msg.event, event_msg.body) with timeline.frozen(): assert timeline.last is event @@ -141,12 +154,12 @@ def test_event(make_timeline): timeline.expect_realized(event_exp) -@pytest.mark.parametrize('outcome', ['success', 'failure']) +@pytest.mark.parametrize("outcome", ["success", "failure"]) def test_request_response(make_timeline, outcome): timeline, initial_history = make_timeline() messages = MessageFactory() - request_msg = messages.request('next', {'threadId': 3}) + request_msg = messages.request("next", {"threadId": 3}) request_exp = expectation_of(request_msg) request = timeline.record_request(request_msg) @@ -154,7 +167,7 @@ def test_request_response(make_timeline, outcome): assert request.command == request_msg.command assert request.arguments == request_msg.arguments assert request.circumstances == ( - 'request', + "request", request_msg.command, request_msg.arguments, ) @@ -163,26 +176,25 @@ def test_request_response(make_timeline, outcome): assert timeline.last is request assert timeline.history() == initial_history + [some.object.same_as(request)] timeline.expect_realized(request_exp) - timeline.expect_realized(Request('next')) + timeline.expect_realized(Request("next")) response_msg = messages.response( - request_msg, - {} if outcome == 'success' else Exception('error!'), + request_msg, {} if outcome == "success" else Exception("error!") ) response = timeline.record_response(request, response_msg) assert response.request is request assert response.body == response_msg.body - if outcome == 'success': + if outcome == "success": assert response.success else: assert not response.success - assert response.circumstances == ('response', request, response_msg.body) + assert response.circumstances == ("response", request, response_msg.body) assert response == Response(request, response_msg.body) assert response == Response(request, some.object) assert response == Response(request) - if outcome == 'success': + if outcome == "success": assert response == Response(request, some.dict) assert response != Response(request, some.error) else: @@ -193,7 +205,7 @@ def test_request_response(make_timeline, outcome): assert response == Response(request_exp, some.object) assert response == Response(request_exp) - if outcome == 'success': + if outcome == "success": assert response == Response(request_exp, some.dict) assert response != Response(request_exp, some.error) else: @@ -202,13 +214,16 @@ def test_request_response(make_timeline, outcome): with timeline.frozen(): assert timeline.last is response - assert timeline.history() == initial_history + [some.object.same_as(request), some.object.same_as(response)] + assert timeline.history() == initial_history + [ + some.object.same_as(request), + some.object.same_as(response), + ] timeline.expect_realized(Response(request)) timeline.expect_realized(Response(request, response_msg.body)) timeline.expect_realized(Response(request, some.object)) - if outcome == 'success': + if outcome == "success": timeline.expect_realized(Response(request, some.dict)) timeline.expect_not_realized(Response(request, some.error)) else: @@ -219,7 +234,7 @@ def test_request_response(make_timeline, outcome): timeline.expect_realized(Response(request_exp, response_msg.body)) timeline.expect_realized(Response(request_exp, some.object)) - if outcome == 'success': + if outcome == "success": timeline.expect_realized(Response(request_exp, some.dict)) timeline.expect_not_realized(Response(request_exp, some.error)) else: @@ -229,45 +244,45 @@ def test_request_response(make_timeline, outcome): def test_after(make_timeline): timeline, _ = make_timeline() - first = timeline.mark('first') + first = timeline.mark("first") - second_exp = first >> Mark('second') + second_exp = first >> Mark("second") with timeline.frozen(): assert second_exp not in timeline - timeline.mark('second') + timeline.mark("second") with timeline.frozen(): assert second_exp in timeline - timeline.mark('first') + timeline.mark("first") with timeline.frozen(): - assert Mark('second') >> Mark('first') in timeline + assert Mark("second") >> Mark("first") in timeline def test_before(make_timeline): timeline, _ = make_timeline() t = timeline.beginning - first = timeline.mark('first') - timeline.mark('second') + first = timeline.mark("first") + timeline.mark("second") with timeline.frozen(): - assert t >> Mark('second') >> Mark('first') not in timeline - assert Mark('second') >> first not in timeline + assert t >> Mark("second") >> Mark("first") not in timeline + assert Mark("second") >> first not in timeline - third = timeline.mark('third') + third = timeline.mark("third") with timeline.frozen(): - assert t >> Mark('second') >> Mark('first') not in timeline - assert Mark('second') >> first not in timeline - assert t >> Mark('second') >> Mark('third') in timeline - assert Mark('second') >> third in timeline + assert t >> Mark("second") >> Mark("first") not in timeline + assert Mark("second") >> first not in timeline + assert t >> Mark("second") >> Mark("third") in timeline + assert Mark("second") >> third in timeline def test_and(make_timeline): - eggs_exp = Mark('eggs') - ham_exp = Mark('ham') - cheese_exp = Mark('cheese') + eggs_exp = Mark("eggs") + ham_exp = Mark("ham") + cheese_exp = Mark("cheese") timeline, _ = make_timeline() t = timeline.beginning @@ -277,19 +292,19 @@ def test_and(make_timeline): assert t >> (ham_exp & eggs_exp) not in timeline assert t >> (cheese_exp & ham_exp & eggs_exp) not in timeline - timeline.mark('eggs') + timeline.mark("eggs") with timeline.frozen(): assert t >> (eggs_exp & ham_exp) not in timeline assert t >> (ham_exp & eggs_exp) not in timeline assert t >> (cheese_exp & ham_exp & eggs_exp) not in timeline - timeline.mark('ham') + timeline.mark("ham") with timeline.frozen(): assert t >> (eggs_exp & ham_exp) in timeline assert t >> (ham_exp & eggs_exp) in timeline assert t >> (cheese_exp & ham_exp & eggs_exp) not in timeline - timeline.mark('cheese') + timeline.mark("cheese") with timeline.frozen(): assert t >> (eggs_exp & ham_exp) in timeline assert t >> (ham_exp & eggs_exp) in timeline @@ -297,9 +312,9 @@ def test_and(make_timeline): def test_or(make_timeline): - eggs_exp = Mark('eggs') - ham_exp = Mark('ham') - cheese_exp = Mark('cheese') + eggs_exp = Mark("eggs") + ham_exp = Mark("ham") + cheese_exp = Mark("cheese") timeline, _ = make_timeline() t = timeline.beginning @@ -309,26 +324,26 @@ def test_or(make_timeline): assert t >> (ham_exp | eggs_exp) not in timeline assert t >> (cheese_exp | ham_exp | eggs_exp) not in timeline - timeline.mark('eggs') + timeline.mark("eggs") with timeline.frozen(): assert t >> (eggs_exp | ham_exp) in timeline assert t >> (ham_exp | eggs_exp) in timeline assert t >> (cheese_exp | ham_exp | eggs_exp) in timeline - timeline.mark('cheese') + timeline.mark("cheese") with timeline.frozen(): assert t >> (eggs_exp | ham_exp) in timeline assert t >> (ham_exp | eggs_exp) in timeline assert t >> (cheese_exp | ham_exp | eggs_exp) in timeline - timeline.mark('ham') + timeline.mark("ham") with timeline.frozen(): assert t >> (eggs_exp | ham_exp) in timeline assert t >> (ham_exp | eggs_exp) in timeline assert t >> (cheese_exp | ham_exp | eggs_exp) in timeline t = timeline.last - timeline.mark('cheese') + timeline.mark("cheese") with timeline.frozen(): assert t >> (eggs_exp | ham_exp) not in timeline assert t >> (ham_exp | eggs_exp) not in timeline @@ -336,9 +351,9 @@ def test_or(make_timeline): def test_xor(make_timeline): - eggs_exp = Mark('eggs') - ham_exp = Mark('ham') - cheese_exp = Mark('cheese') + eggs_exp = Mark("eggs") + ham_exp = Mark("ham") + cheese_exp = Mark("cheese") timeline, _ = make_timeline() t1 = timeline.beginning @@ -348,14 +363,14 @@ def test_xor(make_timeline): assert t1 >> (ham_exp ^ eggs_exp) not in timeline assert t1 >> (cheese_exp ^ ham_exp ^ eggs_exp) not in timeline - timeline.mark('eggs') + timeline.mark("eggs") with timeline.frozen(): assert t1 >> (eggs_exp ^ ham_exp) in timeline assert t1 >> (ham_exp ^ eggs_exp) in timeline assert t1 >> (cheese_exp ^ ham_exp ^ eggs_exp) in timeline t2 = timeline.last - timeline.mark('ham') + timeline.mark("ham") with timeline.frozen(): assert t1 >> (eggs_exp ^ ham_exp) not in timeline assert t2 >> (eggs_exp ^ ham_exp) in timeline @@ -367,35 +382,35 @@ def test_xor(make_timeline): def test_conditional(make_timeline): def is_exciting(occ): - return occ == Event(some.str, 'exciting') + return occ == Event(some.str, "exciting") messages = MessageFactory() - something = Event('something', some.object) + something = Event("something", some.object) something_exciting = something.when(is_exciting) timeline, _ = make_timeline() t = timeline.beginning - timeline.record_event(messages.event('something', 'boring')) + timeline.record_event(messages.event("something", "boring")) with timeline.frozen(): timeline.expect_realized(t >> something) timeline.expect_not_realized(t >> something_exciting) - timeline.record_event(messages.event('something', 'exciting')) + timeline.record_event(messages.event("something", "exciting")) with timeline.frozen(): timeline.expect_realized(t >> something_exciting) def test_lower_bound(make_timeline): timeline, _ = make_timeline() - timeline.mark('1') - timeline.mark('2') - timeline.mark('3') + timeline.mark("1") + timeline.mark("2") + timeline.mark("3") timeline.freeze() - assert (Mark('2') >> (Mark('1') >> Mark('3'))) not in timeline - assert (Mark('2') >> (Mark('1') & Mark('3'))) not in timeline - assert (Mark('2') >> (Mark('1') ^ Mark('3'))) in timeline + assert (Mark("2") >> (Mark("1") >> Mark("3"))) not in timeline + assert (Mark("2") >> (Mark("1") & Mark("3"))) not in timeline + assert (Mark("2") >> (Mark("1") ^ Mark("3"))) in timeline @pytest.mark.timeout(3) @@ -413,7 +428,7 @@ def test_frozen(make_timeline, daemon): assert timeline.is_frozen assert not timeline.is_frozen - timeline.mark('dum') + timeline.mark("dum") timeline.freeze() assert timeline.is_frozen @@ -425,18 +440,18 @@ def test_frozen(make_timeline, daemon): def worker(): worker_started.set() worker_can_proceed.wait() - timeline.mark('dee') + timeline.mark("dee") worker_started.wait() - assert Mark('dum') in timeline - assert Mark('dee') not in timeline + assert Mark("dum") in timeline + assert Mark("dee") not in timeline with timeline.unfrozen(): worker_can_proceed.set() worker.join() - assert Mark('dee') in timeline + assert Mark("dee") in timeline @pytest.mark.timeout(3) @@ -451,15 +466,15 @@ def test_unobserved(make_timeline, daemon): worker_can_proceed.wait() worker_can_proceed.clear() - timeline.record_event(messages.event('dum', {})) - log.debug('dum') + timeline.record_event(messages.event("dum", {})) + log.debug("dum") worker_can_proceed.wait() - timeline.record_event(messages.event('dee', {})) - log.debug('dee') + timeline.record_event(messages.event("dee", {})) + log.debug("dee") - timeline.record_event(messages.event('dum', {})) - log.debug('dum') + timeline.record_event(messages.event("dum", {})) + log.debug("dum") timeline.freeze() assert timeline.is_frozen @@ -468,7 +483,7 @@ def test_unobserved(make_timeline, daemon): assert not timeline.is_frozen worker_can_proceed.set() - dum = timeline.wait_for_next(Event('dum')) + dum = timeline.wait_for_next(Event("dum")) assert timeline.is_frozen assert dum.observed @@ -479,11 +494,11 @@ def test_unobserved(make_timeline, daemon): worker_can_proceed.set() worker.join() - dum2 = timeline.wait_for_next(Event('dum'), freeze=False) + dum2 = timeline.wait_for_next(Event("dum"), freeze=False) assert not timeline.is_frozen assert dum2.observed - timeline.wait_until_realized(Event('dum') >> Event('dum'), freeze=True) + timeline.wait_until_realized(Event("dum") >> Event("dum"), freeze=True) assert timeline.is_frozen dee = dum.next @@ -494,7 +509,7 @@ def test_unobserved(make_timeline, daemon): timeline.proceed() # Observe it! - timeline.expect_realized(Event('dee')) + timeline.expect_realized(Event("dee")) assert dee.observed # Should be good now. @@ -504,48 +519,48 @@ def test_unobserved(make_timeline, daemon): def test_new(make_timeline): timeline, _ = make_timeline() - m1 = timeline.mark('1') + m1 = timeline.mark("1") timeline.freeze() - assert timeline.expect_new(Mark('1')) is m1 + assert timeline.expect_new(Mark("1")) is m1 with pytest.raises(Exception): - timeline.expect_new(Mark('2')) + timeline.expect_new(Mark("2")) timeline.proceed() - m2 = timeline.mark('2') + m2 = timeline.mark("2") timeline.freeze() with pytest.raises(Exception): - timeline.expect_new(Mark('1')) - assert timeline.expect_new(Mark('2')) is m2 + timeline.expect_new(Mark("1")) + assert timeline.expect_new(Mark("2")) is m2 with pytest.raises(Exception): - timeline.expect_new(Mark('3')) + timeline.expect_new(Mark("3")) timeline.unfreeze() - m3 = timeline.mark('3') + m3 = timeline.mark("3") timeline.freeze() with pytest.raises(Exception): - timeline.expect_new(Mark('1')) - assert timeline.expect_new(Mark('2')) is m2 - assert timeline.expect_new(Mark('3')) is m3 + timeline.expect_new(Mark("1")) + assert timeline.expect_new(Mark("2")) is m2 + assert timeline.expect_new(Mark("3")) is m3 timeline.proceed() - m4 = timeline.mark('4') - timeline.mark('4') + m4 = timeline.mark("4") + timeline.mark("4") timeline.freeze() with pytest.raises(Exception): - timeline.expect_new(Mark('1')) + timeline.expect_new(Mark("1")) with pytest.raises(Exception): - timeline.expect_new(Mark('2')) + timeline.expect_new(Mark("2")) with pytest.raises(Exception): - timeline.expect_new(Mark('3')) - assert timeline.expect_new(Mark('4')) is m4 + timeline.expect_new(Mark("3")) + assert timeline.expect_new(Mark("4")) is m4 @pytest.mark.timeout(3) -@pytest.mark.parametrize('order', ['mark_then_wait', 'wait_then_mark']) +@pytest.mark.parametrize("order", ["mark_then_wait", "wait_then_mark"]) def test_concurrency(make_timeline, daemon, order): timeline, initial_history = make_timeline() @@ -555,19 +570,20 @@ def test_concurrency(make_timeline, daemon, order): @daemon def worker(): worker_can_proceed.wait() - mark = timeline.mark('tada') + mark = timeline.mark("tada") occurrences.append(mark) - if order == 'mark_then_wait': + if order == "mark_then_wait": worker_can_proceed.set() unblock_worker_later = None else: + @daemon def unblock_worker_later(): time.sleep(0.1) worker_can_proceed.set() - mark = timeline.wait_for_next(Mark('tada'), freeze=True) + mark = timeline.wait_for_next(Mark("tada"), freeze=True) worker.join() assert mark is occurrences[0] diff --git a/tests/watchdog/__init__.py b/tests/watchdog/__init__.py index 421c0aa8..50cf1c59 100644 --- a/tests/watchdog/__init__.py +++ b/tests/watchdog/__init__.py @@ -11,7 +11,7 @@ ptvsd processes. If the test runner process goes down, any ptvsd test processes are automatically killed. """ -__all__ = ["start", "register_spawn", "unregister_spawn"] +__all__ = ["start", "register_spawn", "unregister_spawn"] import atexit import os @@ -47,10 +47,7 @@ def start(): ) _process = psutil.Popen( - args, - bufsize=0, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, + args, bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE ) _stream = messaging.JsonIOStream(_process.stdout, _process.stdin, _name)