Skip to content

Commit 1bedd86

Browse files
committed
Generate realistic test coverage data by not including ipfshttpclient before the test system is started
1 parent cf90fda commit 1bedd86

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

test/run-tests.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from __future__ import print_function
33

44
import contextlib
5+
import locale
56
import pathlib
67
import os
78
import random
@@ -10,7 +11,7 @@
1011
import sys
1112
import time
1213

13-
import ipfshttpclient
14+
import six
1415

1516

1617
if not hasattr(contextlib, "suppress"):
@@ -74,8 +75,17 @@ def _contextlib_suppress(*exceptions):
7475
# Start daemon #
7576
################
7677

78+
#PY2: Only add `encoding` parameter on Python 3 as it's not available on Unicode-hostile versions
79+
extra_args = {}
80+
if not six.PY2:
81+
extra_args["encoding"] = locale.getpreferredencoding()
82+
7783
# Spawn IPFS daemon in data directory
78-
DAEMON = subprocess.Popen(["ipfs", "daemon", "--enable-pubsub-experiment"])
84+
DAEMON = subprocess.Popen(["ipfs", "daemon", "--enable-pubsub-experiment"],
85+
stdout = subprocess.PIPE,
86+
stderr = subprocess.STDOUT,
87+
**extra_args
88+
)
7989
os.environ["PY_IPFS_HTTP_CLIENT_TEST_DAEMON_PID"] = str(DAEMON.pid)
8090

8191
# Collect the exit code of `DAEMON` when `SIGCHLD` is received
@@ -85,13 +95,13 @@ def _contextlib_suppress(*exceptions):
8595
signal.signal(signal.SIGCHLD, lambda *a: DAEMON.poll())
8696

8797
# Wait for daemon to start up
88-
while True:
89-
try:
90-
ipfshttpclient.connect(HOST, PORT)
91-
except ipfshttpclient.exceptions.ConnectionError:
92-
time.sleep(0.05)
93-
else:
98+
#PY2: Using `for line in DAEMON.stdout` hangs the process
99+
line = DAEMON.stdout.readline()
100+
while line is not None:
101+
print(line, end="")
102+
if line.strip() == "Daemon is ready":
94103
break
104+
line = DAEMON.stdout.readline()
95105

96106

97107
##################
@@ -121,5 +131,11 @@ def _contextlib_suppress(*exceptions):
121131
DAEMON.kill()
122132

123133
print("IPFS daemon was still running after test!", file=sys.stderr)
134+
135+
output = list(DAEMON.stdout)
136+
if output:
137+
print("IPFS daemon printed extra messages:", file=sys.stderr)
138+
for line in output:
139+
print("\t{0}".format(line), end="", file=sys.stderr)
124140

125141
sys.exit(PYTEST_CODE)

0 commit comments

Comments
 (0)