Skip to content

Commit 7f27f3e

Browse files
committed
-
1 parent 32404b0 commit 7f27f3e

File tree

13 files changed

+1516
-628
lines changed

13 files changed

+1516
-628
lines changed

source_py2/python_toolbox/third_party/enum/enum.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
__all__ = ['Enum', 'IntEnum', 'unique']
66

7-
version = 1, 0, 3
7+
version = 1, 0, 4
88

99
pyver = float('%s.%s' % _sys.version_info[:2])
1010

@@ -29,6 +29,12 @@ def any(iterable):
2929
# in Python 3 it's just str, but was missing in 3.1
3030
basestring = str
3131

32+
try:
33+
unicode
34+
except NameError:
35+
# In Python 3 unicode no longer exists (it's just str)
36+
unicode = str
37+
3238
class _RouteClassAttributeToGetattr(object):
3339
"""Route attribute access on a class to __getattr__.
3440
@@ -406,6 +412,13 @@ def _create_(cls, class_name, names=None, module=None, type=None):
406412
* A mapping of member name -> value.
407413
408414
"""
415+
if pyver < 3.0:
416+
# if class_name is unicode, attempt a conversion to ASCII
417+
if isinstance(class_name, unicode):
418+
try:
419+
class_name = class_name.encode('ascii')
420+
except UnicodeEncodeError:
421+
raise TypeError('%r is not representable in ASCII' % class_name)
409422
metacls = cls.__class__
410423
if type is None:
411424
bases = (cls, )

source_py2/python_toolbox/third_party/unittest2/__init__.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
unittest2
33
44
unittest2 is a backport of the new features added to the unittest testing
5-
framework in Python 2.7. It is tested to run on Python 2.4 - 2.6.
5+
framework in Python 2.7 and beyond. It is tested to run on Python 2.4 - 2.7.
66
77
To use unittest2 instead of unittest simply replace ``import unittest`` with
88
``import unittest2``.
@@ -31,38 +31,57 @@
3131
'defaultTestLoader', 'SkipTest', 'skip', 'skipIf', 'skipUnless',
3232
'expectedFailure', 'TextTestResult', '__version__', 'collector']
3333

34-
__version__ = '0.5.1'
34+
__version__ = '1.0.1'
3535

3636
# Expose obsolete functions for backwards compatibility
3737
__all__.extend(['getTestCaseNames', 'makeSuite', 'findTestCases'])
3838

3939

40-
from python_toolbox.third_party.unittest2.collector import collector
41-
from python_toolbox.third_party.unittest2.result import TestResult
42-
from python_toolbox.third_party.unittest2.case import (
40+
from unittest2.collector import collector
41+
from unittest2.result import TestResult
42+
from unittest2.case import (
4343
TestCase, FunctionTestCase, SkipTest, skip, skipIf,
4444
skipUnless, expectedFailure
4545
)
46-
from python_toolbox.third_party.unittest2.suite import BaseTestSuite, TestSuite
47-
from python_toolbox.third_party.unittest2.loader import (
46+
from unittest2.suite import BaseTestSuite, TestSuite
47+
from unittest2.loader import (
4848
TestLoader, defaultTestLoader, makeSuite, getTestCaseNames,
4949
findTestCases
5050
)
51-
from python_toolbox.third_party.unittest2.main import TestProgram, main, main_
52-
from python_toolbox.third_party.unittest2.runner import TextTestRunner, TextTestResult
51+
from unittest2.main import TestProgram, main
52+
from unittest2.runner import TextTestRunner, TextTestResult
5353

5454
try:
55-
from python_toolbox.third_party.unittest2.signals import (
55+
from unittest2.signals import (
5656
installHandler, registerResult, removeResult, removeHandler
5757
)
5858
except ImportError:
5959
# Compatibility with platforms that don't have the signal module
6060
pass
6161
else:
62-
__all__.extend(['installHandler', 'registerResult', 'removeResult',
62+
__all__.extend(['installHandler', 'registerResult', 'removeResult',
6363
'removeHandler'])
6464

6565
# deprecated
6666
_TextTestResult = TextTestResult
6767

68-
__unittest = True
68+
# There are no tests here, so don't try to run anything discovered from
69+
# introspecting the symbols (e.g. FunctionTestCase). Instead, all our
70+
# tests come from within unittest.test.
71+
def load_tests(loader, tests, pattern):
72+
import os.path
73+
# top level directory cached on loader instance
74+
this_dir = os.path.dirname(__file__)
75+
return loader.discover(start_dir=this_dir, pattern=pattern)
76+
77+
__unittest = True
78+
79+
def load_tests(loader, tests, pattern):
80+
# All our tests are in test/ - the test objects found in unittest2 itself
81+
# are base classes not intended to be executed. This load_tests intercepts
82+
# discovery to prevent that.
83+
import unittest2.test
84+
result = loader.suiteClass()
85+
for path in unittest2.test.__path__:
86+
result.addTests(loader.discover(path, pattern=pattern))
87+
return result

source_py2/python_toolbox/third_party/unittest2/__main__.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@
22

33
import sys
44
if sys.argv[0].endswith("__main__.py"):
5-
sys.argv[0] = "unittest2"
5+
import os.path
6+
# We change sys.argv[0] to make help message more useful
7+
# use executable without path, unquoted
8+
# (it's just a hint anyway)
9+
# (if you have spaces in your executable you get what you deserve!)
10+
executable = os.path.basename(sys.executable)
11+
sys.argv[0] = executable + " -m unittest2"
12+
del os
613

714
__unittest = True
815

9-
from unittest2.main import main_
10-
main_()
16+
from unittest2.main import main, TestProgram
17+
def main_():
18+
main(module=None)
19+
20+
if __name__=="__main__":
21+
main_()

0 commit comments

Comments
 (0)