Skip to content

Commit deb1824

Browse files
cclausstargos
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 <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: David Carlier <[email protected]>
1 parent 4f91459 commit deb1824

File tree

7 files changed

+28
-13
lines changed

7 files changed

+28
-13
lines changed

Makefile

+1-1
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:
File renamed without changes.

tools/gyp/pylib/gyp/MSVSSettings_test.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66

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

9-
import StringIO
109
import unittest
1110
import gyp.MSVSSettings as MSVSSettings
1211

12+
try:
13+
from StringIO import StringIO # Python 2
14+
except ImportError:
15+
from io import StringIO # Python 3
16+
1317

1418
class TestSequenceFunctions(unittest.TestCase):
1519

1620
def setUp(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

+6-2
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-
import collections
65
import errno
76
import filecmp
87
import os.path
98
import re
109
import tempfile
1110
import sys
1211

12+
try:
13+
from collections.abc import MutableSet
14+
except ImportError:
15+
from collections import MutableSet
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-
class OrderedSet(collections.MutableSet):
500+
class OrderedSet(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

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88

99
import gyp.easy_xml as easy_xml
1010
import unittest
11-
import StringIO
11+
12+
try:
13+
from StringIO import StringIO # Python 2
14+
except ImportError:
15+
from io import StringIO # Python 3
1216

1317

1418
class TestSequenceFunctions(unittest.TestCase):
1519

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

1923
def test_EasyXml_simple(self):
2024
self.assertEqual(

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77

88
import gyp.generator.msvs as msvs
99
import unittest
10-
import StringIO
10+
11+
try:
12+
from StringIO import StringIO # Python 2
13+
except ImportError:
14+
from io import StringIO # Python 3
1115

1216

1317
class TestSequenceFunctions(unittest.TestCase):
1418

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

1822
def test_GetLibraries(self):
1923
self.assertEqual(

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66

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

9-
import gyp.generator.ninja as ninja
10-
import unittest
11-
import StringIO
129
import sys
13-
import TestCommon
10+
import unittest
11+
12+
import gyp.generator.ninja as ninja
1413

1514

1615
class TestPrefixesAndSuffixes(unittest.TestCase):

0 commit comments

Comments
 (0)