def test_layer_errors(): toplevel_chart = alt.Chart("data.txt").mark_point().configure_legend( columns=2) facet_chart1 = alt.Chart("data.txt").mark_point().encode(facet="row:Q") facet_chart2 = alt.Chart("data.txt").mark_point().facet("row:Q") repeat_chart = alt.Chart("data.txt").mark_point().repeat(["A", "B", "C"]) simple_chart = alt.Chart("data.txt").mark_point() with pytest.raises(ValueError) as err: toplevel_chart + simple_chart assert str(err.value).startswith( 'Objects with "config" attribute cannot be used within LayerChart.') with pytest.raises(ValueError) as err: repeat_chart + simple_chart assert str(err.value) == "Repeat charts cannot be layered." with pytest.raises(ValueError) as err: facet_chart1 + simple_chart assert str(err.value) == "Faceted charts cannot be layered." with pytest.raises(ValueError) as err: alt.layer(simple_chart) + facet_chart2 assert str(err.value) == "Faceted charts cannot be layered."
def test_layer_add_selection(): base = alt.Chart("data.csv").mark_point() selection = alt.selection_single() chart1 = alt.layer(base.add_selection(selection), base) chart2 = alt.layer(base, base).add_selection(selection) assert chart1.to_dict() == chart2.to_dict()