-
Notifications
You must be signed in to change notification settings - Fork 4
Refactor get_cartography return values and add to_folium_map functions
#393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #393 +/- ##
==========================================
+ Coverage 84.76% 85.07% +0.30%
==========================================
Files 53 53
Lines 5699 5763 +64
Branches 640 649 +9
==========================================
+ Hits 4831 4903 +72
+ Misses 857 849 -8
Partials 11 11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
1aba87d to
bfbc552
Compare
| standardization of attributes. | ||
| """ | ||
|
|
||
| import folium |
Check warning
Code scanning / Prospector (reported by Codacy)
Unable to import 'folium' (import-error) Warning
| infer_speeds: bool = False, | ||
| return_type: str = "gdfs", | ||
| ) -> tuple | nx.DiGraph: | ||
| ) -> tuple[nx.DiGraph, gpd.GeoDataFrame, gpd.GeoDataFrame]: |
Check warning
Code scanning / Prospector (reported by Codacy)
Value 'tuple' is unsubscriptable (unsubscriptable-object) Warning
|
|
||
| import pytest | ||
| import networkx as nx | ||
| import folium |
Check warning
Code scanning / Prospector (reported by Codacy)
Unable to import 'folium' (import-error) Warning test
| result = to_folium_map(sample_graph, which="edges") | ||
| assert isinstance(result, folium.Map) | ||
| # Check that the map has children (the edges) | ||
| assert len(result._children) > 0 |
Check warning
Code scanning / Prospector (reported by Codacy)
Access to a protected member _children of a client class (protected-access) Warning test
| """Test visualization with nodes only.""" | ||
| result = to_folium_map(sample_graph, which="nodes") | ||
| assert isinstance(result, folium.Map) | ||
| assert len(result._children) > 0 |
Check warning
Code scanning / Prospector (reported by Codacy)
Access to a protected member _children of a client class (protected-access) Warning test
| nodes_only = to_folium_map(sample_graph, which="nodes") | ||
| # 'both' should have children from edges and nodes combined | ||
| # (minus the base tile layer which is common) | ||
| assert len(result._children) >= len(edges_only._children) |
Check warning
Code scanning / Prospector (reported by Codacy)
Access to a protected member _children of a client class (protected-access) Warning test
| # 'both' should have children from edges and nodes combined | ||
| # (minus the base tile layer which is common) | ||
| assert len(result._children) >= len(edges_only._children) | ||
| assert len(result._children) >= len(nodes_only._children) |
Check warning
Code scanning / Prospector (reported by Codacy)
Access to a protected member _children of a client class (protected-access) Warning test
| default_result = to_folium_map(sample_graph) | ||
| edges_result = to_folium_map(sample_graph, which="edges") | ||
| # Both should produce maps with the same number of children | ||
| assert len(default_result._children) == len(edges_result._children) |
Check warning
Code scanning / Prospector (reported by Codacy)
Access to a protected member _children of a client class (protected-access) Warning test
| assert -1 < location[0] < 1 # latitude | ||
| assert -1 < location[1] < 1 # longitude | ||
|
|
||
| def test_default_which_parameter(self, sample_graph): |
Check warning
Code scanning / Pylint (reported by Codacy)
Method could be a function Warning test
| assert len(result._children) >= len(edges_only._children) | ||
| assert len(result._children) >= len(nodes_only._children) | ||
|
|
||
| def test_map_center_location(self, sample_graph): |
Check warning
Code scanning / Pylint (reported by Codacy)
Method could be a function Warning test
| assert isinstance(result, folium.Map) | ||
| assert len(result._children) > 0 | ||
|
|
||
| def test_both_edges_and_nodes(self, sample_graph): |
Check warning
Code scanning / Pylint (reported by Codacy)
Method could be a function Warning test
| """Test visualization with nodes only.""" | ||
| result = to_folium_map(sample_graph, which="nodes") | ||
| assert isinstance(result, folium.Map) | ||
| assert len(result._children) > 0 |
Check warning
Code scanning / Pylint (reported by Codacy)
Do not use len(SEQUENCE) to determine if a sequence is empty Warning test
| # Check that the map has children (the edges) | ||
| assert len(result._children) > 0 | ||
|
|
||
| def test_nodes_only(self, sample_graph): |
Check warning
Code scanning / Pylint (reported by Codacy)
Method could be a function Warning test
| result = to_folium_map(sample_graph, which="edges") | ||
| assert isinstance(result, folium.Map) | ||
| # Check that the map has children (the edges) | ||
| assert len(result._children) > 0 |
Check notice
Code scanning / Pylint (reported by Codacy)
Access to a protected member _children of a client class Note test
| """Test visualization with nodes only.""" | ||
| result = to_folium_map(sample_graph, which="nodes") | ||
| assert isinstance(result, folium.Map) | ||
| assert len(result._children) > 0 |
Check notice
Code scanning / Pylint (reported by Codacy)
Access to a protected member _children of a client class Note test
| nodes_only = to_folium_map(sample_graph, which="nodes") | ||
| # 'both' should have children from edges and nodes combined | ||
| # (minus the base tile layer which is common) | ||
| assert len(result._children) >= len(edges_only._children) |
Check notice
Code scanning / Pylint (reported by Codacy)
Access to a protected member _children of a client class Note test
| # 'both' should have children from edges and nodes combined | ||
| # (minus the base tile layer which is common) | ||
| assert len(result._children) >= len(edges_only._children) | ||
| assert len(result._children) >= len(nodes_only._children) |
Check notice
Code scanning / Pylint (reported by Codacy)
Access to a protected member _children of a client class Note test
| default_result = to_folium_map(sample_graph) | ||
| edges_result = to_folium_map(sample_graph, which="edges") | ||
| # Both should produce maps with the same number of children | ||
| assert len(default_result._children) == len(edges_result._children) |
Check notice
Code scanning / Pylint (reported by Codacy)
Access to a protected member _children of a client class Note test
| infer_speeds: bool = False, | ||
| return_type: str = "gdfs", | ||
| ) -> tuple | nx.DiGraph: | ||
| ) -> tuple[nx.DiGraph, gpd.GeoDataFrame, gpd.GeoDataFrame]: |
Check warning
Code scanning / Pylintpython3 (reported by Codacy)
Value 'tuple' is unsubscriptable Warning
| return gdf_edges, gdf_nodes | ||
|
|
||
|
|
||
| def to_folium_map( |
Check warning
Code scanning / Pylintpython3 (reported by Codacy)
Argument name "G" doesn't conform to snake_case naming style Warning
| edges_cart, nodes_cart = get_cartography( | ||
| "Postua, Piedmont, Italy", return_type="gdfs" | ||
| ) | ||
| G_CART, edges_cart, nodes_cart = get_cartography("Postua, Piedmont, Italy") |
Check warning
Code scanning / Pylintpython3 (reported by Codacy)
Variable name "G_CART" doesn't conform to snake_case naming style Warning test
| """Tests for to_folium_map function.""" | ||
|
|
||
| @pytest.fixture | ||
| def sample_graph(self): |
Check warning
Code scanning / Pylintpython3 (reported by Codacy)
Method could be a function Warning test
| edges, nodes = create_manhattan_cartography(n_x=3, n_y=3) | ||
| return graph_from_gdfs(edges, nodes) | ||
|
|
||
| def test_returns_folium_map(self, sample_graph): |
Check warning
Code scanning / Pylintpython3 (reported by Codacy)
Method could be a function Warning test
| result = to_folium_map(sample_graph, which="edges") | ||
| assert isinstance(result, folium.Map) | ||
| # Check that the map has children (the edges) | ||
| assert len(result._children) > 0 |
Check notice
Code scanning / Pylintpython3 (reported by Codacy)
Access to a protected member _children of a client class Note test
| """Test visualization with nodes only.""" | ||
| result = to_folium_map(sample_graph, which="nodes") | ||
| assert isinstance(result, folium.Map) | ||
| assert len(result._children) > 0 |
Check notice
Code scanning / Pylintpython3 (reported by Codacy)
Access to a protected member _children of a client class Note test
| nodes_only = to_folium_map(sample_graph, which="nodes") | ||
| # 'both' should have children from edges and nodes combined | ||
| # (minus the base tile layer which is common) | ||
| assert len(result._children) >= len(edges_only._children) |
Check notice
Code scanning / Pylintpython3 (reported by Codacy)
Access to a protected member _children of a client class Note test
| # 'both' should have children from edges and nodes combined | ||
| # (minus the base tile layer which is common) | ||
| assert len(result._children) >= len(edges_only._children) | ||
| assert len(result._children) >= len(nodes_only._children) |
Check notice
Code scanning / Pylintpython3 (reported by Codacy)
Access to a protected member _children of a client class Note test
| default_result = to_folium_map(sample_graph) | ||
| edges_result = to_folium_map(sample_graph, which="edges") | ||
| # Both should produce maps with the same number of children | ||
| assert len(default_result._children) == len(edges_result._children) |
Check notice
Code scanning / Pylintpython3 (reported by Codacy)
Access to a protected member _children of a client class Note test
| def test_returns_folium_map(self, sample_graph): | ||
| """Test that the function returns a folium.Map object.""" | ||
| result = to_folium_map(sample_graph) | ||
| assert isinstance(result, folium.Map) |
Check notice
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| def test_edges_only(self, sample_graph): | ||
| """Test visualization with edges only (default).""" | ||
| result = to_folium_map(sample_graph, which="edges") | ||
| assert isinstance(result, folium.Map) |
Check notice
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| result = to_folium_map(sample_graph, which="edges") | ||
| assert isinstance(result, folium.Map) | ||
| # Check that the map has children (the edges) | ||
| assert len(result._children) > 0 |
Check notice
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| def test_nodes_only(self, sample_graph): | ||
| """Test visualization with nodes only.""" | ||
| result = to_folium_map(sample_graph, which="nodes") | ||
| assert isinstance(result, folium.Map) |
Check notice
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| """Test visualization with nodes only.""" | ||
| result = to_folium_map(sample_graph, which="nodes") | ||
| assert isinstance(result, folium.Map) | ||
| assert len(result._children) > 0 |
Check notice
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| # The map should be centered around the mean of node coordinates | ||
| # For a Manhattan grid centered at (0, 0), the center should be near (0, 0) | ||
| location = result.location | ||
| assert location is not None |
Check notice
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| # For a Manhattan grid centered at (0, 0), the center should be near (0, 0) | ||
| location = result.location | ||
| assert location is not None | ||
| assert len(location) == 2 |
Check notice
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| assert location is not None | ||
| assert len(location) == 2 | ||
| # Check that location is reasonable (near 0,0 for default manhattan grid) | ||
| assert -1 < location[0] < 1 # latitude |
Check notice
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| assert len(location) == 2 | ||
| # Check that location is reasonable (near 0,0 for default manhattan grid) | ||
| assert -1 < location[0] < 1 # latitude | ||
| assert -1 < location[1] < 1 # longitude |
Check notice
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| default_result = to_folium_map(sample_graph) | ||
| edges_result = to_folium_map(sample_graph, which="edges") | ||
| # Both should produce maps with the same number of children | ||
| assert len(default_result._children) == len(edges_result._children) |
Check notice
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
No description provided.