From cf6fb3cbf1976dd73f56c1b45ad6d73221232adb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=AB=E4=B9=90=E7=9A=84=E8=80=81=E9=BC=A0=E5=AE=9D?= =?UTF-8?q?=E5=AE=9D?= <42690037+LaoshuBaby@users.noreply.github.com> Date: Thu, 29 Feb 2024 02:15:35 +0800 Subject: [PATCH] test: different call method of viz_folium --- .../plugin/{folium => viz_folium}/__main__.py | 6 ++-- .../__main__.py | 0 ...{plugin_folium.py => plugin_viz_folium.py} | 33 ++++++++++++++++--- 3 files changed, 32 insertions(+), 7 deletions(-) rename src/yuheng/plugin/{folium => viz_folium}/__main__.py (87%) rename src/yuheng/plugin/{matplotlib => viz_matplotlib}/__main__.py (100%) rename tests/cases/{plugin_folium.py => plugin_viz_folium.py} (54%) diff --git a/src/yuheng/plugin/folium/__main__.py b/src/yuheng/plugin/viz_folium/__main__.py similarity index 87% rename from src/yuheng/plugin/folium/__main__.py rename to src/yuheng/plugin/viz_folium/__main__.py index 62c42d5..e8bff67 100644 --- a/src/yuheng/plugin/folium/__main__.py +++ b/src/yuheng/plugin/viz_folium/__main__.py @@ -11,7 +11,7 @@ from yuheng.type import Node, Relation, Way -class Map: +class VizFolium: def __init__(self): self.element_list = [] @@ -22,9 +22,11 @@ def add(self, element: Union[Waifu, Way, Node, Relation]) -> None: self.element_list.append(element) return None - def display(self) -> None: + def display(self, **kwargs) -> None: """ This func display some element to html + + If **kwargs is not blank, then we should call self.add() for each one, then display as expected. """ m = folium.Map(location=[11.4, 51.4], zoom_start=0) diff --git a/src/yuheng/plugin/matplotlib/__main__.py b/src/yuheng/plugin/viz_matplotlib/__main__.py similarity index 100% rename from src/yuheng/plugin/matplotlib/__main__.py rename to src/yuheng/plugin/viz_matplotlib/__main__.py diff --git a/tests/cases/plugin_folium.py b/tests/cases/plugin_viz_folium.py similarity index 54% rename from tests/cases/plugin_folium.py rename to tests/cases/plugin_viz_folium.py index 70e9cec..d2f4e38 100644 --- a/tests/cases/plugin_folium.py +++ b/tests/cases/plugin_viz_folium.py @@ -8,13 +8,11 @@ from yuheng import Waifu from yuheng.type import Member, Node, Relation, Way -from yuheng.plugin.folium.__main__ import display +from yuheng.plugin.folium.__main__ import VizFolium, display class TestPluginVisualizationFolium(unittest.TestCase): def setUp(self) -> None: - from yuheng.plugin.folium.__main__ import display - self.test_node_1 = Node( {"id": "1"}, {"name": "folium cafe", "amenity": "cafe"} ) @@ -34,9 +32,34 @@ def setUp(self) -> None: ], ) self.test_map = Waifu() + # 需要插入到Waifu对象里面。 + # self.test_map.insert( + # self.test_node_1, + # self.test_node_2, + # self.test_way, + # self.test_relation, + # ) + + def test_plugin_viz_folium_display_kwargs(self): + carto_viz = VizFolium() + carto_viz.display( + self.test_node_1, + self.test_node_2, + self.test_way, + self.test_relation, + ) + + def test_plugin_viz_folium_display_added(self): + carto_viz = VizFolium() + carto_viz.add(self.test_node_1) + carto_viz.add(self.test_node_2) + carto_viz.add(self.test_way) + carto_viz.add(self.test_relation) + carto_viz.display() - def test_plugin_driver_poly_import(self): - display(self.test_relation) + def test_plugin_viz_folium_display_object(self): + carto_viz = VizFolium() + carto_viz.display(self.test_map) if __name__ == "__main__":