Added files which hold unit tests for each package component respectfully. Unit testing makes use of the pytest library. Majority of tests are self-explanatory, with wordy function headers to help understand the purpose of the test. Note, test modules DO NOT provide best practices and are separate from the standards set for the remaining code base. For this reason, mypy and flake8 are told to ignore testing modules. pytest-cov is used to gain an idea of how much of the code base is being reached by the unit tests. Coverage does not have to be 100%, and 100% coverage does not indicate "bug-free" code. If any bugs are identified, or further unit tests are possible to increase code base coverage, create a new Issue, or PR request with the appropriate changes.
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
# 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 |