Procházet zdrojové kódy

Merge branch 'bugfix/ci_stdout_encoding_v4.0' into 'release/v4.0'

ci: Fix missing sys.stdout.encoding in python2 runners (v4.0)

See merge request espressif/esp-idf!12598
Angus Gratton před 5 roky
rodič
revize
a0efde0997
1 změnil soubory, kde provedl 6 přidání a 3 odebrání
  1. 6 3
      tools/ci/python_packages/tiny_test_fw/DUT.py

+ 6 - 3
tools/ci/python_packages/tiny_test_fw/DUT.py

@@ -81,10 +81,13 @@ def _decode_data(data):
     if isinstance(data, bytes):
         # convert bytes to string. This is a bit of a hack, we know that we want to log this
         # later so encode to the stdout encoding with backslash escapes for anything non-encodable
+        encoding = sys.stdout.encoding
+        if encoding is None:
+            encoding = 'ascii'
         try:
-            return data.decode(sys.stdout.encoding, "backslashreplace")
-        except UnicodeDecodeError:  # Python <3.5 doesn't support backslashreplace
-            return data.decode(sys.stdout.encoding, "replace")
+            return data.decode(encoding, "backslashreplace")
+        except (UnicodeDecodeError, TypeError):  # Python <3.5 doesn't support backslashreplace
+            return data.decode(encoding, "replace")
     return data