fix(uf2): Ignore ESPBAUD, ESPPORT when calling idf.py uf2[-app]

This commit is contained in:
Jan Beran
2024-09-23 15:48:59 +02:00
parent aba133e842
commit 431923f23c
4 changed files with 116 additions and 28 deletions

View File

@@ -1,13 +1,15 @@
#!/usr/bin/env python
#
# SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
import json
import os
import subprocess
import sys
from unittest import TestCase, main, mock
from typing import List
from unittest import main
from unittest import mock
from unittest import TestCase
import elftools.common.utils as ecu
import jsonschema
@@ -344,5 +346,62 @@ class TestFileArgumentExpansion(TestCase):
self.assertIn('(expansion of @args_non_existent) could not be opened', cm.exception.output.decode('utf-8', 'ignore'))
class TestWrapperCommands(TestCase):
@classmethod
def setUpClass(cls):
cls.sample_project_dir = os.path.join(current_dir, '..', 'test_build_system', 'build_test_app')
os.chdir(cls.sample_project_dir)
super().setUpClass()
def call_command(self, command: List[str]) -> str:
try:
output = subprocess.check_output(
command,
env=os.environ,
stderr=subprocess.STDOUT).decode('utf-8', 'ignore')
return output
except subprocess.CalledProcessError as e:
self.fail(f'Process should have exited normally, but it exited with a return code of {e.returncode}')
@classmethod
def tearDownClass(cls):
subprocess.run([sys.executable, idf_py_path, 'fullclean'], stdout=subprocess.DEVNULL)
os.chdir(current_dir)
super().tearDownClass()
class TestUF2Commands(TestWrapperCommands):
"""
Test if uf2 commands are invoked as expected.
This test is not testing the functionality of mkuf2.py/idf.py uf2, but the invocation of the command from idf.py.
"""
def test_uf2(self):
uf2_command = [sys.executable, idf_py_path, 'uf2']
output = self.call_command(uf2_command)
self.assertIn('Executing:', output)
def test_uf2_with_envvars(self):
# Values do not really matter, they should not be used.
os.environ['ESPBAUD'] = '115200'
os.environ['ESPPORT'] = '/dev/ttyUSB0'
self.test_uf2()
os.environ.pop('ESPBAUD')
os.environ.pop('ESPPORT')
def test_uf2_app(self):
uf2_app_command = [sys.executable, idf_py_path, 'uf2-app']
output = self.call_command(uf2_app_command)
self.assertIn('Executing:', output)
def test_uf2_app_with_envvars(self):
# Values do not really matter, they should not be used.
os.environ['ESPBAUD'] = '115200'
os.environ['ESPPORT'] = '/dev/ttyUSB0'
self.test_uf2_app()
os.environ.pop('ESPBAUD')
os.environ.pop('ESPPORT')
if __name__ == '__main__':
main()