Skip to content

Commit 0b33930

Browse files
Trying to get stresstest.py to work with UTF-16 as the test encoding (doesn't work yet)
1 parent 839c489 commit 0b33930

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

stresstest.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
# chars in the test string.
3838
# ENCODING = 'cp1252'
3939

40+
# There are some issues with the test program in utf-16 but I think the logging itself works...?
41+
# ENCODING = 'utf-16'
42+
4043
ENCODING = 'utf-8'
4144

4245

@@ -54,7 +57,7 @@ def __init__(self, sharedfile, uniquefile, name="LogStressTester", logger_delay=
5457
self.log = None
5558
self.use_gzip = True
5659
self.extended_unicode = True
57-
if PY2:
60+
if PY2 and ENCODING != 'utf-8':
5861
# hopefully temporary... the problem is with stdout in the tester I think
5962
self.extended_unicode = False
6063

@@ -112,8 +115,8 @@ def run(self):
112115
"the worlds largest prime number: %d", "%d happy meals!"]
113116
if self.extended_unicode:
114117
msgs.extend([
115-
"\U0001d122 \U00024b00 Euro: \u20ac%d",
116-
"my favorite number is %d ①②③④⑤⑥⑦⑧!"
118+
u"\U0001d122 \U00024b00 Euro: \u20ac%d",
119+
u"my favorite number is %d ①②③④⑤⑥⑦⑧!"
117120
])
118121

119122
logfuncts = [self.log.debug, self.log.info, self.log.warning, self.log.error]
@@ -168,6 +171,9 @@ def iter_logs(iterable, missing_ok=False):
168171
def combine_logs(combinedlog, iterable, mode="wb"):
169172
""" write all lines (iterable) into a single log file. """
170173
fp = io.open(combinedlog, mode)
174+
if ENCODING == 'utf-16':
175+
import codecs
176+
fp.write(codecs.BOM_UTF16)
171177
for chunk in iterable:
172178
fp.write(chunk)
173179
fp.close()
@@ -255,8 +261,8 @@ def update(self, **kwargs):
255261
def __init__(self, output_path):
256262
self.output_path = output_path
257263
self.tests = []
258-
self.client_stdout = open(os.path.join(output_path, "client_stdout.txt"), "a")
259-
self.client_stderr = open(os.path.join(output_path, "client_stderr.txt"), "a")
264+
self.client_stdout = io.open(os.path.join(output_path, "client_stdout.txt"), "a", encoding=ENCODING)
265+
self.client_stderr = io.open(os.path.join(output_path, "client_stderr.txt"), "a", encoding=ENCODING)
260266

261267
def launchPopen(self, *args, **kwargs):
262268
if "stdout" not in kwargs:

0 commit comments

Comments
 (0)