mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-30 19:19:21 +00:00
feat(tools): Enforce utf-8 encoding with open() function
This commit is contained in:
@@ -46,7 +46,7 @@ def test_examples_app_trace_basic(dut: IdfDut, openocd: OpenOcd) -> None:
|
||||
assert 'Targets connected.' in dut.openocd.write('esp apptrace start file://apptrace.log 0 2000 3 0 0')
|
||||
apptrace_wait_stop(dut.openocd)
|
||||
|
||||
with open(openocd._logfile) as oocd_log: # pylint: disable=protected-access
|
||||
with open(openocd._logfile, encoding='utf-8') as oocd_log: # pylint: disable=protected-access
|
||||
cores = 1 if dut.app.sdkconfig.get('ESP_SYSTEM_SINGLE_CORE_MODE') is True else 2
|
||||
params_str = 'App trace params: from {} cores,'.format(cores)
|
||||
found = False
|
||||
@@ -59,7 +59,7 @@ def test_examples_app_trace_basic(dut: IdfDut, openocd: OpenOcd) -> None:
|
||||
'"{}" could not be found in {}'.format(params_str, openocd._logfile) # pylint: disable=protected-access
|
||||
)
|
||||
|
||||
with open('apptrace.log') as apptrace_log:
|
||||
with open('apptrace.log', encoding='utf-8') as apptrace_log:
|
||||
for sample_num in range(1, 51):
|
||||
log_str = 'Apptrace test data[{}]:{}'.format(sample_num, sample_num * sample_num)
|
||||
found = False
|
||||
|
@@ -1,6 +1,5 @@
|
||||
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import argparse
|
||||
import datetime
|
||||
import json
|
||||
@@ -9,7 +8,8 @@ import signal
|
||||
import sys
|
||||
from enum import Enum
|
||||
from functools import partial
|
||||
from typing import Any, List
|
||||
from typing import Any
|
||||
from typing import List
|
||||
|
||||
try:
|
||||
import espytrace.apptrace
|
||||
@@ -47,7 +47,7 @@ app.layout = html.Div(
|
||||
html.Div([
|
||||
html.H2('Telemetry Data'),
|
||||
html.Div(id='live-update-data'),
|
||||
dcc.Graph(id='live-update-graph', style={'height': 800}), # Height of the plotting area setted to 800px
|
||||
dcc.Graph(id='live-update-graph', style={'height': 800}), # Height of the plotting area set to 800px
|
||||
dcc.Interval(
|
||||
id='interval-component',
|
||||
interval=5 * 100, # Graph will be updated every 500 ms
|
||||
@@ -57,7 +57,7 @@ app.layout = html.Div(
|
||||
)
|
||||
|
||||
|
||||
# Multiple components can update everytime interval gets fired.
|
||||
# Multiple components can update every time interval gets fired.
|
||||
@app.callback(Output('live-update-graph', 'figure'),
|
||||
Input('interval-component', 'n_intervals'))
|
||||
def update_graph_live(_n: Any) -> Any: # pylint: disable=undefined-argument
|
||||
@@ -162,13 +162,13 @@ class CustomRequestHandler(espytrace.apptrace.TCPRequestHandler):
|
||||
|
||||
|
||||
def read_json(file_path: str) -> Any:
|
||||
with open(file_path, 'r') as f:
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
return data
|
||||
|
||||
|
||||
def save_data(file_path: str) -> None:
|
||||
with open(file_path, 'w') as f:
|
||||
with open(file_path, 'w', encoding='utf-8') as f:
|
||||
f.writelines(output_lines)
|
||||
|
||||
|
||||
|
@@ -99,7 +99,7 @@ class EfuseFlashEncSerial(IdfSerial):
|
||||
with tempfile.NamedTemporaryFile(suffix='.json') as temp_file:
|
||||
temp_file_path = temp_file.name
|
||||
espefuse.main(f'--virt -c {self.target} summary --format json --file {temp_file_path}'.split())
|
||||
with open(temp_file_path, 'r') as file:
|
||||
with open(temp_file_path, 'r', encoding='utf-8') as file:
|
||||
efuse_summary = json.load(file)
|
||||
if efuse_name in efuse_summary:
|
||||
data = efuse_summary[efuse_name]
|
||||
|
@@ -68,7 +68,7 @@ server_key = '-----BEGIN PRIVATE KEY-----\n'\
|
||||
|
||||
|
||||
def create_file(server_file: str, file_data: str) -> None:
|
||||
with open(server_file, 'w+') as file:
|
||||
with open(server_file, 'w+', encoding='utf-8') as file:
|
||||
file.write(file_data)
|
||||
|
||||
|
||||
|
@@ -151,13 +151,13 @@ def start_https_server(ota_image_dir: str, server_ip: str, server_port: int, ser
|
||||
|
||||
if server_file is None:
|
||||
server_file = os.path.join(ota_image_dir, 'server_cert.pem')
|
||||
cert_file_handle = open(server_file, 'w+')
|
||||
cert_file_handle = open(server_file, 'w+', encoding='utf-8')
|
||||
cert_file_handle.write(server_cert)
|
||||
cert_file_handle.close()
|
||||
|
||||
if key_file is None:
|
||||
key_file = os.path.join(ota_image_dir, 'server_key.pem')
|
||||
key_file_handle = open('server_key.pem', 'w+')
|
||||
key_file_handle = open('server_key.pem', 'w+', encoding='utf-8')
|
||||
key_file_handle.write(server_key)
|
||||
key_file_handle.close()
|
||||
|
||||
|
@@ -80,13 +80,13 @@ def start_https_server(ota_image_dir: str, server_ip: str, server_port: int, ser
|
||||
|
||||
if server_file is None:
|
||||
server_file = os.path.join(ota_image_dir, 'server_cert.pem')
|
||||
cert_file_handle = open(server_file, 'w+')
|
||||
cert_file_handle = open(server_file, 'w+', encoding='utf-8')
|
||||
cert_file_handle.write(server_cert)
|
||||
cert_file_handle.close()
|
||||
|
||||
if key_file is None:
|
||||
key_file = os.path.join(ota_image_dir, 'server_key.pem')
|
||||
key_file_handle = open('server_key.pem', 'w+')
|
||||
key_file_handle = open('server_key.pem', 'w+', encoding='utf-8')
|
||||
key_file_handle.write(server_key)
|
||||
key_file_handle.close()
|
||||
|
||||
@@ -102,12 +102,12 @@ def start_https_server(ota_image_dir: str, server_ip: str, server_port: int, ser
|
||||
def start_tls1_3_server(ota_image_dir: str, server_port: int) -> subprocess.Popen:
|
||||
os.chdir(ota_image_dir)
|
||||
server_file = os.path.join(ota_image_dir, 'server_cert.pem')
|
||||
cert_file_handle = open(server_file, 'w+')
|
||||
cert_file_handle = open(server_file, 'w+', encoding='utf-8')
|
||||
cert_file_handle.write(server_cert)
|
||||
cert_file_handle.close()
|
||||
|
||||
key_file = os.path.join(ota_image_dir, 'server_key.pem')
|
||||
key_file_handle = open('server_key.pem', 'w+')
|
||||
key_file_handle = open('server_key.pem', 'w+', encoding='utf-8')
|
||||
key_file_handle.write(server_key)
|
||||
key_file_handle.close()
|
||||
|
||||
|
@@ -34,7 +34,7 @@ def test_examples_sysview_tracing(dut: IdfDut) -> None:
|
||||
|
||||
dut.gdb.write('c', non_blocking=True)
|
||||
time.sleep(1) # to avoid EOF file error
|
||||
with open(dut.gdb._logfile) as fr: # pylint: disable=protected-access
|
||||
with open(dut.gdb._logfile, encoding='utf-8') as fr: # pylint: disable=protected-access
|
||||
gdb_pexpect_proc = pexpect.fdpexpect.fdspawn(fr.fileno())
|
||||
gdb_pexpect_proc.expect('Thread 2 "main" hit Breakpoint 1, app_main ()')
|
||||
|
||||
|
@@ -49,7 +49,7 @@ def test_examples_sysview_tracing_heap_log(idf_path: str, dut: IdfDut) -> None:
|
||||
sysviewtrace.expect(r'Found \d+ leaked bytes in \d+ blocks.', timeout=120)
|
||||
|
||||
# Validate GDB logs
|
||||
with open(dut.gdb._logfile) as fr: # pylint: disable=protected-access
|
||||
with open(dut.gdb._logfile, encoding='utf-8') as fr: # pylint: disable=protected-access
|
||||
gdb_pexpect_proc = pexpect.fdpexpect.fdspawn(fr.fileno())
|
||||
gdb_pexpect_proc.expect_exact(
|
||||
'Thread 2 "main" hit Temporary breakpoint 1, heap_trace_start (mode_param', timeout=10) # should be (mode_param=HEAP_TRACE_ALL) # TODO GCC-329
|
||||
|
Reference in New Issue
Block a user