Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 0c9d6c3

Browse files
committed
Fix: Update to modern subprocess use.
1 parent 81b8a9a commit 0c9d6c3

1 file changed

Lines changed: 12 additions & 25 deletions

File tree

runestone/unittest_base.py

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,19 @@ def setUpModule(self):
7575
# otherwise the runestone build may fail due to lack of a runestone.js file!
7676
p = subprocess.run(
7777
["npm.cmd" if IS_WINDOWS else "npm", "run", "build"],
78-
stdout=subprocess.PIPE,
79-
stderr=subprocess.PIPE,
80-
universal_newlines=True,
78+
capture_output=True,
79+
text=True,
8180
)
81+
print(p.stdout + p.stderr)
8282
self.assertFalse(p.returncode)
8383
# Compile the docs. Save the stdout and stderr for examination.
84-
p = subprocess.Popen(
84+
p = subprocess.run(
8585
["runestone", "build", "--all"],
86-
stdout=subprocess.PIPE,
87-
stderr=subprocess.PIPE,
88-
universal_newlines=True,
86+
capture_output=True,
87+
text=True,
8988
)
90-
self.build_stdout_data, self.build_stderr_data = p.communicate()
89+
self.build_stdout_data = p.stdout
90+
self.build_stderr_data = p.stderr
9191
print(self.build_stdout_data + self.build_stderr_data)
9292
if self.exit_status_success:
9393
self.assertFalse(p.returncode)
@@ -99,8 +99,8 @@ def setUpModule(self):
9999
# -n: Display addresses numerically. Looking up names is slow.
100100
# -o: Include the PID for each connection.
101101
["netstat", "-no"],
102-
universal_newlines=True,
103-
stdout=subprocess.PIPE,
102+
capture_output=True,
103+
text=True,
104104
).stdout
105105
# Skip the first four lines, which are headings.
106106
for connection in netstat_output.splitlines()[4:]:
@@ -114,8 +114,8 @@ def setUpModule(self):
114114
else:
115115
lsof_output = subprocess.run(
116116
["lsof", "-i", ":{0}".format(PORT)],
117-
universal_newlines=True,
118-
stdout=subprocess.PIPE,
117+
capture_output=True,
118+
text=True,
119119
).stdout
120120
for process in lsof_output.split("\n")[1:]:
121121
data = [x for x in process.split(" ") if x != ""]
@@ -195,19 +195,6 @@ def tearDownModule(self):
195195
global mf
196196
mf = None
197197

198-
# Without this, Python 2.7 produces errors when running unit tests:
199-
#
200-
# .. code::
201-
# :number-lines:
202-
#
203-
# python -m unittest discover
204-
#
205-
# ImportError: Failed to import test module: runestone.tabbedStuff.test.test_tabbedStuff
206-
# Traceback (most recent call last): (omitted)
207-
# ValueError: no such test method in <class 'runestone.unittest_base.ModuleFixture'>: runTest
208-
def runTest(self):
209-
pass
210-
211198

212199
# Provide a simple way to instantiante a ModuleFixture in a test module. Typical use:
213200
#

0 commit comments

Comments
 (0)