Skip to content

Commit 4729661

Browse files
author
deathaxe
authored
Reorganize imports and publications (#248)
This commit... 1. publishes `unittest.TestCase` as `unittesting.TestCase` for convenience. 2. imports `expectedFailure` via `core.py38.case` for API compatibility.
1 parent 368364a commit 4729661

23 files changed

+87
-64
lines changed

tests/_Async/tests/test.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import sublime
2-
from unittest import TestCase
32
import time
43

4+
from unittest import TestCase
5+
56

67
class TestAsync(TestCase):
78

tests/_Deferred/tests/test.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from unittesting import DeferrableViewTestCase, expectedFailure
1+
from unittesting import DeferrableViewTestCase
2+
from unittesting import expectedFailure
23

34

45
class TestDeferrable(DeferrableViewTestCase):

tests/test_await_worker.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from functools import partial
2-
import time
3-
41
import sublime
2+
import time
53

6-
from unittesting import DeferrableTestCase, AWAIT_WORKER
4+
from functools import partial
5+
from unittesting import AWAIT_WORKER
6+
from unittesting import DeferrableTestCase
77

88

99
def run_in_worker(fn, *args, **kwargs):

tests/test_deferred_timing.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from functools import partial
2-
import time
3-
from unittest.mock import patch
4-
51
import sublime
2+
import time
63

4+
from functools import partial
5+
from unittest.mock import patch
76
from unittesting import DeferrableTestCase
87

98

tests/test_expected_failures.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import sublime
1+
import sys
22

3-
try:
4-
from unittest.case import _ExpectedFailure, _UnexpectedSuccess
5-
except ImportError:
6-
pass
73
from unittest import skipIf
8-
from unittesting import DeferrableTestCase, expectedFailure
4+
from unittesting import DeferrableTestCase
5+
from unittesting import expectedFailure
6+
7+
PY33 = sys.version_info == (3,3)
8+
if PY33:
9+
from unittest.case import _ExpectedFailure, _UnexpectedSuccess
910

1011

1112
class TestExpectedFailures(DeferrableTestCase):
12-
@skipIf(sublime.version() >= '4000', "Sublime Text 4 has optimization on")
13+
@skipIf(not PY33, "Sublime Text 4 has optimization on")
1314
@expectedFailure
1415
def test_direct_failure1(self):
1516
assert False
@@ -24,7 +25,7 @@ def testitem():
2425
yield
2526
1 / 0
2627

27-
ex = ZeroDivisionError if sublime.version() >= "4000" else _ExpectedFailure
28+
ex = _ExpectedFailure if PY33 else ZeroDivisionError
2829
try:
2930
yield from testitem()
3031
except ex:
@@ -37,15 +38,15 @@ def test_expected_failure(self):
3738
def testitem():
3839
1 / 0
3940

40-
ex = ZeroDivisionError if sublime.version() >= "4000" else _ExpectedFailure
41+
ex = _ExpectedFailure if PY33 else ZeroDivisionError
4142
try:
4243
yield from testitem()
4344
except ex:
4445
pass
4546
else:
4647
self.fail('Expected _ExpectedFailure')
4748

48-
@skipIf(sublime.version() >= '4000', "not applicable in Python 3.8")
49+
@skipIf(not PY33, "not applicable in Python 3.8")
4950
def test_unexpected_success_coroutine(self):
5051

5152
@expectedFailure
@@ -59,7 +60,7 @@ def testitem():
5960
else:
6061
self.fail('Expected _UnexpectedSuccess')
6162

62-
@skipIf(sublime.version() >= '4000', "not applicable in Python 3.8")
63+
@skipIf(not PY33, "not applicable in Python 3.8")
6364
def test_unexpected_success(self):
6465

6566
@expectedFailure

unittesting/color_scheme.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import sublime
22
import sublime_plugin
3-
43
import sys
54

6-
from .mixin import UnitTestingMixin
75
from .const import DONE_MESSAGE
6+
from .mixin import UnitTestingMixin
87

98

109
class UnitTestingColorSchemeCommand(sublime_plugin.ApplicationCommand, UnitTestingMixin):

unittesting/core/__init__.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
import sys
22

33
if sys.version_info >= (3, 8):
4-
from .py38.runner import DeferringTextTestRunner, AWAIT_WORKER
54
from .py38.case import DeferrableTestCase
5+
from .py38.case import expectedFailure
6+
from .py38.runner import AWAIT_WORKER
7+
from .py38.runner import DeferringTextTestRunner
68
from .py38.suite import DeferrableTestSuite
7-
from unittest import expectedFailure
89
else:
9-
from .py33.runner import DeferringTextTestRunner, AWAIT_WORKER
10-
from .py33.case import DeferrableTestCase, expectedFailure
10+
from .py33.case import DeferrableTestCase
11+
from .py33.case import expectedFailure
12+
from .py33.runner import AWAIT_WORKER
13+
from .py33.runner import DeferringTextTestRunner
1114
from .py33.suite import DeferrableTestSuite
1215

13-
from .loader import UnitTestingLoader as TestLoader # noqa
16+
from .loader import UnitTestingLoader as TestLoader
1417

1518
__all__ = [
16-
"TestLoader",
17-
"DeferringTextTestRunner",
19+
"AWAIT_WORKER",
1820
"DeferrableTestCase",
1921
"DeferrableTestSuite",
20-
"AWAIT_WORKER",
21-
"expectedFailure"
22+
"DeferringTextTestRunner",
23+
"expectedFailure",
24+
"TestLoader",
2225
]

unittesting/core/loader.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from unittest import TestSuite
22
from unittest import TestLoader
3+
34
from . import DeferrableTestSuite
45

56

unittesting/core/py33/__init__.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
from . import case # noqa: F401
2-
from . import runner # noqa: F401
3-
from . import suite # noqa: F401

unittesting/core/py33/case.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import sys
2-
import unittest
32
import warnings
3+
44
from functools import wraps
5-
from unittest.case import _ExpectedFailure, _UnexpectedSuccess, SkipTest, _Outcome
5+
from unittest import TestCase
6+
from unittest.case import _ExpectedFailure
7+
from unittest.case import _Outcome
8+
from unittest.case import _UnexpectedSuccess
9+
from unittest.case import SkipTest
610

711
from ...utils import isiterable
812
from .runner import defer
913

14+
__all__ = [
15+
"DeferrableTestCase",
16+
"expectedFailure"
17+
]
18+
1019

1120
def expectedFailure(func):
1221
@wraps(func)
@@ -21,7 +30,7 @@ def wrapper(*args, **kwargs):
2130
return wrapper
2231

2332

24-
class DeferrableTestCase(unittest.TestCase):
33+
class DeferrableTestCase(TestCase):
2534

2635
def _executeTestPart(self, function, outcome, isTest=False):
2736
try:

unittesting/core/py33/runner.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import warnings
44

55
from functools import partial
6-
from unittest.runner import TextTestRunner, registerResult
6+
from unittest.runner import TextTestRunner
7+
from unittest.runner import registerResult
78

89
DEFAULT_CONDITION_POLL_TIME = 17
910
DEFAULT_CONDITION_TIMEOUT = 4000

unittesting/core/py33/suite.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
from unittest.suite import TestSuite, _isnotsuite, _call_if_exists, _DebugResult
21
from unittest import util
2+
from unittest.suite import _call_if_exists
3+
from unittest.suite import _DebugResult
4+
from unittest.suite import _isnotsuite
5+
from unittest.suite import TestSuite
6+
37
from ...utils import isiterable
48

59

unittesting/core/py38/__init__.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
from . import case # noqa: F401
2-
from . import runner # noqa: F401
3-
from . import suite # noqa: F401

unittesting/core/py38/case.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import sys
2-
import unittest
2+
3+
from unittest import TestCase
34
from unittest.case import _Outcome
4-
from .runner import defer
5+
from unittest.case import expectedFailure
6+
57
from ...utils import isiterable
8+
from .runner import defer
9+
10+
__all__ = [
11+
"DeferrableTestCase",
12+
"expectedFailure"
13+
]
614

715

8-
class DeferrableTestCase(unittest.TestCase):
16+
class DeferrableTestCase(TestCase):
917

1018
def _callSetUp(self):
1119
deferred = self.setUp()

unittesting/core/py38/runner.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import warnings
44

55
from functools import partial
6-
from unittest.runner import TextTestRunner, registerResult
6+
from unittest.runner import TextTestRunner
7+
from unittest.runner import registerResult
78

89
DEFAULT_CONDITION_POLL_TIME = 17
910
DEFAULT_CONDITION_TIMEOUT = 4000

unittesting/core/py38/suite.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
from unittest.suite import TestSuite, _isnotsuite, _call_if_exists, _DebugResult
21
from unittest import util
2+
from unittest.suite import _call_if_exists
3+
from unittest.suite import _DebugResult
4+
from unittest.suite import _isnotsuite
5+
from unittest.suite import TestSuite
6+
37
from ...utils import isiterable
48

59

unittesting/current.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
from fnmatch import fnmatch
55

6-
from .package import UnitTestingCommand
76
from .coverage import UnitTestingCoverageCommand
7+
from .package import UnitTestingCommand
88

99

1010
class UnitTestingCurrentPackageCommand(UnitTestingCommand):

unittesting/helpers/override_preferences_test_cast.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import shutil
44
import sublime
55

6-
from .. import DeferrableTestCase
6+
from ..core import DeferrableTestCase
77

88

99
class OverridePreferencesTestCase(DeferrableTestCase):

unittesting/helpers/temp_directory_test_case.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sublime
44
import tempfile
55

6-
from .. import DeferrableTestCase
6+
from ..core import DeferrableTestCase
77

88

99
class TempDirectoryTestCase(DeferrableTestCase):

unittesting/helpers/view_test_case.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sublime
22

33
from unittest import TestCase
4-
from .. import DeferrableTestCase
4+
from ..core import DeferrableTestCase
55

66
__all__ = [
77
"DeferrableViewTestCase",

unittesting/mixin.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
from collections import ChainMap
77
from glob import glob
88

9-
from .utils import reload_package
10-
from .utils import OutputPanel
119
from .utils import JsonFile
10+
from .utils import OutputPanel
1211
from .utils import ProgressBar
13-
14-
12+
from .utils import reload_package
1513

1614
DEFAULT_SETTINGS = {
1715
"tests_dir": "tests",

unittesting/package.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
import sys
66
import threading
77

8-
from unittest import TextTestRunner, TestSuite
8+
from unittest import TextTestRunner
9+
from unittest import TestSuite
910

10-
from .core import (
11-
TestLoader,
12-
DeferringTextTestRunner,
13-
DeferrableTestCase
14-
)
15-
from .mixin import UnitTestingMixin
1611
from .const import DONE_MESSAGE
12+
from .core import DeferrableTestCase
13+
from .core import DeferringTextTestRunner
14+
from .core import TestLoader
15+
from .mixin import UnitTestingMixin
1716
from .utils import ProgressBar, StdioSplitter
1817

1918

unittesting/syntax.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import sublime_api
33
import sublime_plugin
44

5-
from .mixin import UnitTestingMixin
65
from .const import DONE_MESSAGE
6+
from .mixin import UnitTestingMixin
77

88

99
class UnitTestingSyntaxBase(sublime_plugin.ApplicationCommand, UnitTestingMixin):

0 commit comments

Comments
 (0)