From: houchenyao Date: Wed, 31 Jan 2018 08:57:40 +0000 (+0800) Subject: tiny-test-fw: fix dut for python2 and python3 X-Git-Tag: v3.1-beta1~418^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1e4508bc8d6cdf2cc2b0891354afec27dc6d2d96;p=esp-idf tiny-test-fw: fix dut for python2 and python3 --- diff --git a/tools/tiny-test-fw/DUT.py b/tools/tiny-test-fw/DUT.py index 1c6526709b..1cfd2c7d53 100644 --- a/tools/tiny-test-fw/DUT.py +++ b/tools/tiny-test-fw/DUT.py @@ -316,7 +316,7 @@ class BaseDUT(object): if flush: self.data_cache.flush() # do write if cache - if data: + if data is not None: self._port_write(data + eol if eol else data) @_expect_lock @@ -557,9 +557,9 @@ class SerialDUT(BaseDUT): :return: formatted data (str) """ timestamp = time.time() - timestamp = "{}:{}".format(time.strftime("%m-%d %H:%M:%S", time.localtime(timestamp)), - str(timestamp % 1)[2:5]) - formatted_data = "[{}]:\r\n{}\r\n".format(timestamp, _decode_data(data)) + timestamp = "[{}:{}]".format(time.strftime("%m-%d %H:%M:%S", time.localtime(timestamp)), + str(timestamp % 1)[2:5]) + formatted_data = timestamp.encode() + b"\r\n" + data + b"\r\n" return formatted_data def _port_open(self): @@ -571,11 +571,13 @@ class SerialDUT(BaseDUT): def _port_read(self, size=1): data = self.port_inst.read(size) if data: - with open(self.log_file, "a+") as _log_file: + with open(self.log_file, "ab+") as _log_file: _log_file.write(self._format_data(data)) return data def _port_write(self, data): + if isinstance(data, str): + data = data.encode() self.port_inst.write(data) @classmethod