Skip to content

Commit d148330

Browse files
cclaussMylesBorins
authored andcommitted
test: fix Python unittests in ./test and ./tools
Co-authored-by: @patrickhousley Fixes to Python tests to ensure that the following all pass: 1. __python2 -m pytest ./test ./tools__ # 30 tests pass 2. __python3 -m pytest ./test ./tools__ # 30 tests pass 3. __python2 -m unittest discover -s ./test/tools__ # 1 test passes 4. __python3 -m unittest discover -s ./test/tools__ # 1 test passes 5. __PYTHON=python2 make tooltest__ # 1 test passes 6. __PYTHON=python3 make tooltest__ # 1 test passes This is a subset of #30033 PR-URL: #30340 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: David Carlier <devnexen@gmail.com>
1 parent 5e2848d commit d148330

7 files changed

Lines changed: 28 additions & 13 deletions

File tree

‎Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ jstest: build-addons build-js-native-api-tests build-node-api-tests ## Runs addo
300300

301301
.PHONY: tooltest
302302
tooltest:
303-
@$(PYTHON) test/tools/test-js2c.py
303+
@$(PYTHON)-m unittest discover -s ./test/tools
304304

305305
.PHONY: coverage-run-js
306306
coverage-run-js:

‎tools/gyp/pylib/gyp/MSVSSettings_test.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66

77
"""Unit tests for the MSVSSettings.py file."""
88

9-
importStringIO
109
importunittest
1110
importgyp.MSVSSettingsasMSVSSettings
1211

12+
try:
13+
fromStringIOimportStringIO# Python 2
14+
exceptImportError:
15+
fromioimportStringIO# Python 3
16+
1317

1418
classTestSequenceFunctions(unittest.TestCase):
1519

1620
defsetUp(self):
17-
self.stderr=StringIO.StringIO()
21+
self.stderr=StringIO()
1822

1923
def_ExpectedWarnings(self, expected):
2024
"""Compares recorded lines to expected warnings."""

‎tools/gyp/pylib/gyp/common.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
# Use of this source code is governed by a BSD-style license that can be
33
# found in the LICENSE file.
44

5-
importcollections
65
importerrno
76
importfilecmp
87
importos.path
98
importre
109
importtempfile
1110
importsys
1211

12+
try:
13+
fromcollections.abcimportMutableSet
14+
exceptImportError:
15+
fromcollectionsimportMutableSet
16+
1317

1418
# A minimal memoizing decorator. It'll blow up if the args aren't immutable,
1519
# among other "problems".
@@ -493,7 +497,7 @@ def uniquer(seq, idfun=None):
493497

494498

495499
# Based on http://code.activestate.com/recipes/576694/.
496-
classOrderedSet(collections.MutableSet):
500+
classOrderedSet(MutableSet):
497501
def__init__(self, iterable=None):
498502
self.end=end= []
499503
end+= [None, end, end] # sentinel node for doubly linked list

‎tools/gyp/pylib/gyp/easy_xml_test.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88

99
importgyp.easy_xmlaseasy_xml
1010
importunittest
11-
importStringIO
11+
12+
try:
13+
fromStringIOimportStringIO# Python 2
14+
exceptImportError:
15+
fromioimportStringIO# Python 3
1216

1317

1418
classTestSequenceFunctions(unittest.TestCase):
1519

1620
defsetUp(self):
17-
self.stderr=StringIO.StringIO()
21+
self.stderr=StringIO()
1822

1923
deftest_EasyXml_simple(self):
2024
self.assertEqual(

‎tools/gyp/pylib/gyp/generator/msvs_test.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77

88
importgyp.generator.msvsasmsvs
99
importunittest
10-
importStringIO
10+
11+
try:
12+
fromStringIOimportStringIO# Python 2
13+
exceptImportError:
14+
fromioimportStringIO# Python 3
1115

1216

1317
classTestSequenceFunctions(unittest.TestCase):
1418

1519
defsetUp(self):
16-
self.stderr=StringIO.StringIO()
20+
self.stderr=StringIO()
1721

1822
deftest_GetLibraries(self):
1923
self.assertEqual(

‎tools/gyp/pylib/gyp/generator/ninja_test.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66

77
""" Unit tests for the ninja.py file. """
88

9-
importgyp.generator.ninjaasninja
10-
importunittest
11-
importStringIO
129
importsys
13-
importTestCommon
10+
importunittest
11+
12+
importgyp.generator.ninjaasninja
1413

1514

1615
classTestPrefixesAndSuffixes(unittest.TestCase):

0 commit comments

Comments
 (0)