File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
chartlets.py/tests/components/charts Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments