feat(tools): Fix some failing tests on Windows runner

This commit is contained in:
Marek Fiala
2023-11-10 16:30:55 +01:00
parent 0a3b57e48a
commit b535ec9a99
2 changed files with 12 additions and 6 deletions

View File

@@ -28,7 +28,7 @@ def test_bootloader_custom_overrides_original(test_app_copy: Path, idf_py: IdfPy
shutil.copytree(idf_path / 'components' / 'esp_bootloader_format', test_app_copy / 'components' / 'esp_bootloader_format') shutil.copytree(idf_path / 'components' / 'esp_bootloader_format', test_app_copy / 'components' / 'esp_bootloader_format')
idf_py('bootloader') idf_py('bootloader')
assert file_contains(test_app_copy / 'build' / 'bootloader' / 'compile_commands.json', assert file_contains(test_app_copy / 'build' / 'bootloader' / 'compile_commands.json',
str(test_app_copy / 'components' / 'bootloader' / 'subproject' / 'main' / 'bootloader_start.c')) (test_app_copy / 'components' / 'bootloader' / 'subproject' / 'main' / 'bootloader_start.c'))
def test_bootloader_custom_ignores_extra_component(test_app_copy: Path, idf_py: IdfPyFunc, default_idf_env: EnvDict) -> None: def test_bootloader_custom_ignores_extra_component(test_app_copy: Path, idf_py: IdfPyFunc, default_idf_env: EnvDict) -> None:

View File

@@ -7,7 +7,7 @@ import shutil
import subprocess import subprocess
import sys import sys
import typing import typing
from pathlib import Path from pathlib import Path, WindowsPath
from typing import Pattern, Union from typing import Pattern, Union
try: try:
@@ -137,7 +137,7 @@ def run_cmake_and_build(*cmake_args: str, env: typing.Optional[EnvDict] = None)
run_cmake('--build', '.') run_cmake('--build', '.')
def file_contains(filename: Union[str, Path], what: Union[str, Pattern]) -> bool: def file_contains(filename: Union[str, Path], what: Union[Union[str, Path], Pattern]) -> bool:
""" """
Returns true if file contains required object Returns true if file contains required object
:param filename: path to file where lookup is executed :param filename: path to file where lookup is executed
@@ -145,10 +145,16 @@ def file_contains(filename: Union[str, Path], what: Union[str, Pattern]) -> bool
""" """
with open(filename, 'r', encoding='utf-8') as f: with open(filename, 'r', encoding='utf-8') as f:
data = f.read() data = f.read()
if isinstance(what, str): if isinstance(what, Pattern):
return what in data
else:
return re.search(what, data) is not None return re.search(what, data) is not None
else:
what_str = str(what)
# In case of windows path, try both single-slash `\` and double-slash '\\' paths
if isinstance(what, WindowsPath):
what_double_slash = what_str.replace('\\', '\\\\')
return what_str in data or what_double_slash in data
return what_str in data
def bin_file_contains(filename: Union[str, Path], what: bytearray) -> bool: def bin_file_contains(filename: Union[str, Path], what: bytearray) -> bool: