Skip to content
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: 13 additions & 10 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .unittesting.syntax import UnitTestingSyntaxCompatibilityCommand
from .unittesting.unit import UnitTestingCommand


# publish plugin interface
__all__ = [
"UnitTestingCommand",
"UnitTestingSyntaxCommand",
Expand All @@ -33,19 +33,22 @@
# publish unittesting module
sys.modules["unittesting"] = sys.modules["UnitTesting"].unittesting

UT33_CODE = """
from UnitTesting import plugin as ut38


class UnitTesting33Command(ut38.UnitTestingCommand):
\"\"\"Execute unit tests for python 3.3 plugins.\"\"\"
pass
"""


def plugin_loaded():
if sys.version_info >= (3, 8):
import json
from textwrap import dedent

UT33_CODE = dedent(
"""
from UnitTesting import plugin as ut38


class UnitTesting33Command(ut38.UnitTestingCommand):
\"\"\"Execute unit tests for python 3.3 plugins.\"\"\"
pass
"""
).lstrip()

UT33 = os.path.join(sublime.packages_path(), "UnitTesting33")
os.makedirs(UT33, exist_ok=True)
Expand Down
92 changes: 89 additions & 3 deletions unittesting/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
import re
import sublime
import sublime_plugin
import threading

from collections import ChainMap
from collections import ChainMap, deque
from fnmatch import fnmatch
from glob import glob

from .utils import OutputPanel

DEFAULT_SETTINGS = {
# input
"tests_dir": "tests",
Expand Down Expand Up @@ -50,6 +49,93 @@ def relative_to_spp(path):
return None


class OutputPanel:
def __init__(
self,
window,
name,
file_regex="",
line_regex="",
base_dir=None,
word_wrap=False,
line_numbers=False,
gutter=False,
scroll_past_end=False,
):
self.name = name
self.window = window
self.output_view = window.create_output_panel(name)

# default to the current file directory
if not base_dir:
view = window.active_view()
if view:
file_name = view.file_name()
if file_name:
base_dir = os.path.dirname(file_name)

settings = self.output_view.settings()
settings.set("result_file_regex", file_regex)
settings.set("result_line_regex", line_regex)
settings.set("result_base_dir", base_dir)
settings.set("word_wrap", word_wrap)
settings.set("line_numbers", line_numbers)
settings.set("gutter", gutter)
settings.set("scroll_past_end", scroll_past_end)

# make sure to apply settings
self.output_view = window.create_output_panel(name)
self.output_view.assign_syntax("unit-testing-test-result.sublime-syntax")
self.output_view.set_read_only(True)
self.closed = False

self.text_queue_lock = threading.Lock()
self.text_queue = deque()

def write(self, s):
with self.text_queue_lock:
self.text_queue.append(s)

def writeln(self, s):
self.write(s + "\n")

def _write(self):
text = ""
with self.text_queue_lock:
while self.text_queue:
text += self.text_queue.popleft()

self.output_view.run_command("append", {"characters": text, "force": True})
self.output_view.show(self.output_view.size())

def flush(self):
self._write()

def show(self):
self.window.run_command("show_panel", {"panel": "output." + self.name})

def close(self):
self.flush()
self.closed = True


class StdioSplitter:
def __init__(self, io, stream):
self.io = io
self.stream = stream

def write(self, data):
self.io.write(data)
self.stream.write(data)

def writeln(self, s):
self.write(s + "\n")

def flush(self):
self.io.flush()
self.stream.flush()


class BaseUnittestingCommand(sublime_plugin.WindowCommand):
def current_package_name(self):
view = self.window.active_view()
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions unittesting/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

from .base import BaseUnittestingCommand
from .base import DONE_MESSAGE
from .base import StdioSplitter
from .core import DeferrableTestCase
from .core import DeferrableTestLoader
from .core import DeferringTextTestRunner
from .utils import reload_package
from .utils import StdioSplitter
from .reloader import reload_package

try:
import coverage
Expand Down
5 changes: 0 additions & 5 deletions unittesting/utils/__init__.py

This file was deleted.

73 changes: 0 additions & 73 deletions unittesting/utils/output_panel.py

This file was deleted.

15 changes: 0 additions & 15 deletions unittesting/utils/stdio_splitter.py

This file was deleted.