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

pull/12732/head
Marek Fiala 2023-11-10 16:30:55 +01:00
rodzic 0a3b57e48a
commit b535ec9a99
2 zmienionych plików z 12 dodań i 6 usunięć

Wyświetl plik

@ -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')
idf_py('bootloader')
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:

Wyświetl plik

@ -7,7 +7,7 @@ import shutil
import subprocess
import sys
import typing
from pathlib import Path
from pathlib import Path, WindowsPath
from typing import Pattern, Union
try:
@ -137,7 +137,7 @@ def run_cmake_and_build(*cmake_args: str, env: typing.Optional[EnvDict] = None)
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
: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:
data = f.read()
if isinstance(what, str):
return what in data
else:
if isinstance(what, Pattern):
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: