1# Copyright (c) 2024 Nordic Semiconductor ASA 2# 3# SPDX-License-Identifier: Apache-2.0 4from __future__ import annotations 5 6import logging 7import re 8 9from pathlib import Path 10 11 12logger = logging.getLogger(__name__) 13 14 15def find_in_config(config_file: Path | str, config_key: str) -> str: 16 """Find key in config file""" 17 re_key = re.compile(rf'{config_key}=(.+)') 18 with open(config_file) as f: 19 lines = f.readlines() 20 for line in lines: 21 if m := re_key.match(line): 22 logger.debug('Found matching key: %s' % line.strip()) 23 return m.group(1).strip('"\'') 24 logger.debug('Not found key: %s' % config_key) 25 return '' 26 27 28def match_lines(output_lines: list[str], searched_lines: list[str]) -> None: 29 """Check all lines exist in the output""" 30 for sl in searched_lines: 31 assert any(sl in line for line in output_lines) 32 33 34def match_no_lines(output_lines: list[str], searched_lines: list[str]) -> None: 35 """Check lines not found in the output""" 36 for sl in searched_lines: 37 assert all(sl not in line for line in output_lines) 38