Skip to content

Commit 86a2e56

Browse files
ericsnowcurrentlyDonJayamanne
authored andcommitted
Testing tools adapter py2 (#4646)
(for #4033-ish) This is a fix to #4208 and #4605 which makes sure `pythonFiles/tests` (and `pythonFiles/testing_tools`) works under Python 2.7.
1 parent 5fee502 commit 86a2e56

File tree

9 files changed

+39
-15
lines changed

9 files changed

+39
-15
lines changed

build/ci/templates/compile-and-validate.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ jobs:
156156
arguments: '-m pip install --upgrade -r ./build/test-requirements.txt'
157157

158158

159-
- bash: 'python -m pythonFiles.tests'
159+
- bash: 'python pythonFiles/tests/run_all.py'
160160
displayName: 'run pythonFiles unit tests'
161161

162162

pythonFiles/testing_tools/__init__.py

Whitespace-only changes.
+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11

22
class UnsupportedToolError(ValueError):
33
def __init__(self, tool):
4-
super().__init__('unsupported tool {!r}'.format(tool))
4+
msg = 'unsupported tool {!r}'.format(tool)
5+
super(UnsupportedToolError, self).__init__(msg)
56
self.tool = tool
67

78

89
class UnsupportedCommandError(ValueError):
910
def __init__(self, cmd):
10-
super().__init__('unsupported cmd {!r}'.format(cmd))
11+
msg = 'unsupported cmd {!r}'.format(cmd)
12+
super(UnsupportedCommandError, self).__init__(msg)
1113
self.cmd = cmd

pythonFiles/testing_tools/adapter/pytest.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import absolute_import
2+
13
import os.path
24

35
import pytest

pythonFiles/testing_tools/adapter/report.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
from __future__ import print_function
2+
13
import json
24

35

46
def report_discovered(tests, debug=False,
5-
_send=print):
7+
_send=print):
68
"""Serialize the discovered tests and write to stdout."""
79
data = [{
810
'id': test.id,

pythonFiles/tests/__main__.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010
TESTING_TOOLS_ROOT = os.path.join(SRC_ROOT, 'testing_tools')
1111

1212

13-
if __name__ == '__main__':
13+
def main(argv=sys.argv[1:]):
1414
sys.path.insert(1, DATASCIENCE_ROOT)
1515
sys.path.insert(1, TESTING_TOOLS_ROOT)
1616
ec = pytest.main([
1717
'--rootdir', SRC_ROOT,
1818
TEST_ROOT,
19-
] + sys.argv[1:])
19+
] + argv)
20+
return ec
21+
22+
23+
if __name__ == '__main__':
24+
ec = main()
2025
sys.exit(ec)

pythonFiles/tests/run_all.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Replace the "." entry.
2+
import os.path
3+
import sys
4+
sys.path[0] = os.path.dirname(
5+
os.path.dirname(
6+
os.path.abspath(__file__)))
7+
8+
from tests.__main__ import main
9+
10+
11+
if __name__ == '__main__':
12+
ec = main()
13+
sys.exit(ec)

pythonFiles/tests/testing_tools/adapter/test___main__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class StubTool(StubProxy):
1010

1111
def __init__(self, name, stub=None):
12-
super().__init__(stub, name)
12+
super(StubTool, self).__init__(stub, name)
1313
self.return_discover = None
1414

1515
def discover(self, args, **kwargs):
@@ -22,7 +22,7 @@ def discover(self, args, **kwargs):
2222
class StubReporter(StubProxy):
2323

2424
def __init__(self, stub=None):
25-
super().__init__(stub, 'reporter')
25+
super(StubReporter, self).__init__(stub, 'reporter')
2626

2727
def report(self, discovered, **kwargs):
2828
self.add_call('report', (discovered,), kwargs or None)

pythonFiles/tests/testing_tools/adapter/test_pytest.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class StubSubparsers(StubProxy):
1313

1414
def __init__(self, stub=None, name='subparsers'):
15-
super().__init__(stub, name)
15+
super(StubSubparsers, self).__init__(stub, name)
1616

1717
def add_parser(self, name):
1818
self.add_call('add_parser', None, {'name': name})
@@ -22,7 +22,7 @@ def add_parser(self, name):
2222
class StubArgParser(StubProxy):
2323

2424
def __init__(self, stub=None):
25-
super().__init__(stub, 'argparser')
25+
super(StubArgParser, self).__init__(stub, 'argparser')
2626

2727
def add_argument(self, *args, **kwargs):
2828
self.add_call('add_argument', args, kwargs)
@@ -31,7 +31,7 @@ def add_argument(self, *args, **kwargs):
3131
class StubPyTest(StubProxy):
3232

3333
def __init__(self, stub=None):
34-
super().__init__(stub, 'pytest')
34+
super(StubPyTest, self).__init__(stub, 'pytest')
3535
self.return_main = 0
3636

3737
def main(self, args, plugins):
@@ -42,7 +42,7 @@ def main(self, args, plugins):
4242
class StubPlugin(StubProxy):
4343

4444
def __init__(self, stub=None):
45-
super().__init__(stub, 'plugin')
45+
super(StubPlugin, self).__init__(stub, 'plugin')
4646

4747
def __getattr__(self, name):
4848
if not name.startswith('pytest_'):
@@ -67,7 +67,7 @@ def __init__(self, name):
6767
class StubPytestItem(StubProxy):
6868

6969
def __init__(self, stub=None, **attrs):
70-
super().__init__(stub, 'pytest.Item')
70+
super(StubPytestItem, self).__init__(stub, 'pytest.Item')
7171
self.__dict__.update(attrs)
7272
if 'own_markers' not in attrs:
7373
self.own_markers = ()
@@ -82,7 +82,7 @@ def func(*args, **kwargs):
8282
class StubPytestSession(StubProxy):
8383

8484
def __init__(self, stub=None):
85-
super().__init__(stub, 'pytest.Session')
85+
super(StubPytestSession, self).__init__(stub, 'pytest.Session')
8686

8787
def __getattr__(self, name):
8888
self.add_call(name + ' (attr)', None, None)
@@ -94,7 +94,7 @@ def func(*args, **kwargs):
9494
class StubPytestConfig(StubProxy):
9595

9696
def __init__(self, stub=None):
97-
super().__init__(stub, 'pytest.Config')
97+
super(StubPytestConfig, self).__init__(stub, 'pytest.Config')
9898

9999
def __getattr__(self, name):
100100
self.add_call(name + ' (attr)', None, None)

0 commit comments

Comments
 (0)