| 1 |
"""Tests for CDSETool's logger module.""" |
| 2 |
|
| 3 |
from unittest.mock import MagicMock |
| 4 |
|
| 5 |
import pytest |
| 6 |
|
| 7 |
from cdsetool.download import download_feature |
| 8 |
from cdsetool.logger import NoopLogger |
| 9 |
|
| 10 |
|
| 11 |
def test_noop_logger_is_default() -> None: |
| 12 |
NoopLogger.debug = MagicMock() |
| 13 |
|
| 14 |
assert NoopLogger.debug.call_count == 0 |
| 15 |
|
| 16 |
download_feature( |
| 17 |
{ |
| 18 |
"bad_object": True, |
| 19 |
"Name": "myfile.xml", |
| 20 |
# Missing Id will cause bad URL |
| 21 |
}, |
| 22 |
"somewhere", |
| 23 |
) |
| 24 |
|
| 25 |
assert NoopLogger.debug.call_count == 1 |
| 26 |
|
| 27 |
|
| 28 |
def test_noop_does_not_error() -> None: |
| 29 |
try: |
| 30 |
download_feature( |
| 31 |
{ |
| 32 |
"bad_object": True, |
| 33 |
"Name": "myfile.xml", |
| 34 |
# Missing Id will cause bad URL |
| 35 |
}, |
| 36 |
"somewhere", |
| 37 |
) |
| 38 |
NoopLogger().debug("NoopLogger did not raise an exception") |
| 39 |
except Exception as e: |
| 40 |
pytest.fail(f"Unexpected exception: {e}") |