From 431c7d9b1a00f2b93829652cfc19be348a8da79b Mon Sep 17 00:00:00 2001 From: Tobias Klockau Date: Wed, 4 Oct 2023 16:22:36 +0200 Subject: [PATCH] test: add _warning tests --- .../_util/test_warning.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/test_raillabel_providerkit/_util/test_warning.py diff --git a/tests/test_raillabel_providerkit/_util/test_warning.py b/tests/test_raillabel_providerkit/_util/test_warning.py new file mode 100644 index 0000000..e8d9cbc --- /dev/null +++ b/tests/test_raillabel_providerkit/_util/test_warning.py @@ -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"])