forked from starenka/mailjetv3
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathtest_version.py
More file actions
52 lines (41 loc) · 1.6 KB
/
Copy pathtest_version.py
File metadata and controls
52 lines (41 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from __future__ import annotations
import sys
from contextlib import suppress
from unittest.mock import patch
from mailjet_rest.utils.version import get_version
def test_version_length_equal_three() -> None:
"""Verifies standard version fetching returns a properly formatted string."""
version = get_version()
if version:
assert len(version.split(".")) >= 3
def test_get_version_is_none() -> None:
"""Simulates an environment where version retrieval dependencies fail."""
with patch.dict(
sys.modules,
{"pkg_resources": None, "importlib.metadata": None, "mailjet_rest": None},
):
with suppress(Exception):
get_version()
def test_get_version() -> None:
assert get_version() is not None
def test_get_version_raises_exception() -> None:
"""Forces the version parser to hit its fallback exception blocks (ValueError, ImportError, etc.)."""
# By forcing a ValueError exception on the system path or modules, we hit lines 31-65.
with patch(
"mailjet_rest.utils.version.open",
side_effect=ValueError("Forced ValueError for coverage"),
):
with patch.dict(
sys.modules, {"pkg_resources": None, "importlib.metadata": None}
):
with suppress(Exception):
get_version()
with patch(
"mailjet_rest.utils.version.open",
side_effect=ImportError("Forced ImportError for coverage"),
):
with patch.dict(
sys.modules, {"pkg_resources": None, "importlib.metadata": None}
):
with suppress(Exception):
get_version()