Skip to content

Commit

Permalink
test: add _warning tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tklockau committed Oct 4, 2023
1 parent 44d1813 commit 431c7d9
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/test_raillabel_providerkit/_util/test_warning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright DB Netz AG and contributors
# SPDX-License-Identifier: Apache-2.0

import os
import sys
from pathlib import Path

import pytest

sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent))

from raillabel._util._warning import _warning, _WarningsLogger


def test_issue_warning():
with _WarningsLogger() as logger:
_warning("lorem ipsum")

assert logger.warnings == [
"lorem ipsum"
]

def test_handover_exception():
with pytest.raises(RuntimeError) as error:
with _WarningsLogger() as logger:
raise RuntimeError("weewoo something went wrong")

def test_clear_warnings():
with _WarningsLogger() as logger1:
_warning("lorem ipsum")

with _WarningsLogger() as logger2:
pass

assert len(logger2.warnings) == 0


if __name__ == "__main__":
os.system("clear")
pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear", "-v"])

0 comments on commit 431c7d9

Please sign in to comment.