Skip to content

Commit 1e4508b

Browse files
houchenyaoespressif-bot
authored andcommitted
tiny-test-fw: fix dut for python2 and python3
1 parent 475ffe7 commit 1e4508b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

tools/tiny-test-fw/DUT.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def write(self, data, eol="\r\n", flush=True):
316316
if flush:
317317
self.data_cache.flush()
318318
# do write if cache
319-
if data:
319+
if data is not None:
320320
self._port_write(data + eol if eol else data)
321321

322322
@_expect_lock
@@ -557,9 +557,9 @@ def _format_data(data):
557557
:return: formatted data (str)
558558
"""
559559
timestamp = time.time()
560-
timestamp = "{}:{}".format(time.strftime("%m-%d %H:%M:%S", time.localtime(timestamp)),
561-
str(timestamp % 1)[2:5])
562-
formatted_data = "[{}]:\r\n{}\r\n".format(timestamp, _decode_data(data))
560+
timestamp = "[{}:{}]".format(time.strftime("%m-%d %H:%M:%S", time.localtime(timestamp)),
561+
str(timestamp % 1)[2:5])
562+
formatted_data = timestamp.encode() + b"\r\n" + data + b"\r\n"
563563
return formatted_data
564564

565565
def _port_open(self):
@@ -571,11 +571,13 @@ def _port_close(self):
571571
def _port_read(self, size=1):
572572
data = self.port_inst.read(size)
573573
if data:
574-
with open(self.log_file, "a+") as _log_file:
574+
with open(self.log_file, "ab+") as _log_file:
575575
_log_file.write(self._format_data(data))
576576
return data
577577

578578
def _port_write(self, data):
579+
if isinstance(data, str):
580+
data = data.encode()
579581
self.port_inst.write(data)
580582

581583
@classmethod

0 commit comments

Comments
 (0)