1#!/usr/bin/env python3
2# Copyright (c) 2023 Intel Corporation
3#
4# SPDX-License-Identifier: Apache-2.0
5"""
6Tests for log_helper.py functions
7"""
8
9import logging
10import mock
11import pytest
12
13from importlib import reload
14
15import twisterlib.log_helper
16
17
18TESTDATA = [
19    ('Windows', 'dummy message: [\'dummy\', \'command\', \'-flag\']'),
20    ('Linux', 'dummy message: dummy command -flag'),
21]
22
23@pytest.mark.parametrize(
24    'system, expected_log',
25    TESTDATA,
26    ids=['Windows', 'Linux']
27)
28def test_log_command(caplog, system, expected_log):
29    caplog.set_level(logging.DEBUG)
30
31    logger = logging.getLogger('dummy')
32    message = 'dummy message'
33    args = ['dummy', 'command', '-flag']
34
35    with mock.patch('platform.system', return_value=system):
36        reload(twisterlib.log_helper)
37        twisterlib.log_helper.log_command(logger, message, args)
38
39    reload(twisterlib.log_helper)
40
41    assert expected_log in caplog.text
42