diff --git a/tools/test_build_system/test_bootloader.py b/tools/test_build_system/test_bootloader.py index 4f90d7d004..4e7abc07db 100644 --- a/tools/test_build_system/test_bootloader.py +++ b/tools/test_build_system/test_bootloader.py @@ -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: diff --git a/tools/test_build_system/test_build_system_helpers/idf_utils.py b/tools/test_build_system/test_build_system_helpers/idf_utils.py index c4eacdd12a..bec2df14ea 100644 --- a/tools/test_build_system/test_build_system_helpers/idf_utils.py +++ b/tools/test_build_system/test_build_system_helpers/idf_utils.py @@ -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: