Skip to content

Commit c1edcbf

Browse files
committed
Python test coverage now at 100%
1 parent 0d9142d commit c1edcbf

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import importlib
2+
import pathlib
3+
import sys
4+
5+
import pytest
6+
7+
8+
def test_no_altair(monkeypatch: pytest.MonkeyPatch):
9+
"""Test that the VegaChart component handles the absense
10+
of "altair" gracefully.
11+
"""
12+
project_root = pathlib.Path(__file__).absolute().parent
13+
while project_root.parent != project_root and not (project_root / "chartlets" / "__init__.py").exists():
14+
project_root = project_root.parent
15+
16+
# Simulate the absence of the 'altair' module
17+
print("project_root:", project_root)
18+
monkeypatch.setattr(sys, "path", [f"{project_root}"])
19+
if "altair" in sys.modules:
20+
monkeypatch.delitem(sys.modules,"altair")
21+
22+
# Import the code that handles the missing "altair" package
23+
importlib.invalidate_caches()
24+
vega_module = importlib.import_module("chartlets.components.charts.vega")
25+
importlib.reload(vega_module)
26+
27+
# Assert "chartlets.components.charts.vega" handles the
28+
# missing package appropriately by using an "altair" dummy.
29+
altair = vega_module.altair
30+
assert altair is not None
31+
assert altair.Chart is int

0 commit comments

Comments
 (0)