# flake8: noqa import os import pytest from clog.utils.common import ( is_path_spec, LogLevel, ) class TestCommon: @pytest.mark.parametrize( "value, expected", [ ("log.txt", True), (".log", True), (".a_file", True), ("a file.txt", False), ("log123", True), ("a^bad,spec", False), ("may\\not\\exist\\but_valid" if os.name == 'nt'\ else "may/not/exist/but_valid", True), (os.path.realpath("log.txt"), True) ] ) def test_is_path_spec(self, value, expected): assert is_path_spec(value) is expected @pytest.mark.parametrize( "value, expected", [ (LogLevel.NORMAL, 0), (LogLevel.PASS, 1), (LogLevel.DEBUG, 2), (LogLevel.WARN, 3), (LogLevel.ERROR, 4), ] ) def test_log_level_values(self, value, expected): assert value == expected @pytest.mark.parametrize( "value, expected", [ *zip([eval(f"LogLevel.{_}") for _ in dir(LogLevel) if _.isupper()], [eval(f"LogLevel.{_}") for _ in dir(LogLevel) if _.isupper()]) ] ) def test_log_level_through_identity(self, value, expected): assert value is expected