]> granicus.if.org Git - esp-idf/commitdiff
tiny-test-fw: fix dut for python2 and python3
authorhouchenyao <houchenyao@espressif.com>
Wed, 31 Jan 2018 08:57:40 +0000 (16:57 +0800)
committerbot <bot@espressif.com>
Mon, 5 Feb 2018 06:58:22 +0000 (06:58 +0000)
tools/tiny-test-fw/DUT.py

index 1c6526709b4271a9b0da42a863422a23e307376d..1cfd2c7d531872cf2ada018940ceaa2a816ec160 100644 (file)
@@ -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