Skip to content

Commit

Permalink
fix: tests actualization
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilstar97 committed Jul 24, 2024
1 parent 2009126 commit 0a17bad
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 47 deletions.
File renamed without changes.
Binary file added tests/data/buildings.parquet
Binary file not shown.
10 changes: 5 additions & 5 deletions tests/test_blocks.py → tests/test_1_blocks.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""Testing blocks cutter behavior"""
"""Testing blocks generator behavior"""

import os
import pytest
import geopandas as gpd
from blocksnet import BlocksGenerator, LandUse, LandUseProcessor

osm_data_path = "./tests/data"
data_path = "./tests/data"

zones_to_lu = {"zone_1": LandUse.RECREATION, "zone_2": LandUse.RESIDENTIAL, "zone_3": LandUse.BUSINESS}


@pytest.fixture
def boundaries():
gdf = gpd.read_parquet(os.path.join(osm_data_path, "boundaries.parquet"))
gdf = gpd.read_parquet(os.path.join(data_path, "boundaries.parquet"))
crs = gdf.estimate_utm_crs()
return gdf.to_crs(crs)

Expand All @@ -25,7 +25,7 @@ def local_crs(boundaries):
@pytest.fixture
def blocks_generator(boundaries, local_crs):
gdfs = {
name: gpd.read_parquet(os.path.join(osm_data_path, f"{name}.parquet")).to_crs(local_crs)
name: gpd.read_parquet(os.path.join(data_path, f"{name}.parquet")).to_crs(local_crs)
for name in ["roads", "railways", "water"]
}
return BlocksGenerator(boundaries, **gdfs)
Expand Down Expand Up @@ -71,4 +71,4 @@ def test_sameness(blocks, lu_blocks):


def test_output(lu_blocks):
lu_blocks.to_parquet(os.path.join(osm_data_path, "_blocks.parquet"))
lu_blocks.to_parquet(os.path.join(data_path, "_blocks.parquet"))
56 changes: 56 additions & 0 deletions tests/test_2_graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Testing graph generator behavior"""

import os
import pytest
import geopandas as gpd
import osmnx as ox
from blocksnet import GraphGenerator, AdjacencyCalculator

data_path = "./tests/data"


@pytest.fixture
def blocks():
return gpd.read_parquet(os.path.join(data_path, "_blocks.parquet"))


@pytest.fixture
def graph_generator(blocks):
return GraphGenerator(blocks)


@pytest.fixture
def graph(graph_generator):
return graph_generator.run("intermodal")


@pytest.fixture
def adjacency_calculator(blocks, graph):
return AdjacencyCalculator(blocks, graph)


@pytest.fixture
def adjacency_matrix(adjacency_calculator):
return adjacency_calculator.run()


def test_within(graph, graph_generator):
"""Check if graph nodes are within the initial geometry"""
nodes, _ = ox.graph_to_gdfs(graph)
assert all(nodes.within(graph_generator.territory.unary_union))


def test_index(blocks, adjacency_matrix):
"""Check if blocks index matches matrix index and columns"""
assert (blocks.index == adjacency_matrix.index).all()
assert (blocks.index == adjacency_matrix.columns).all()


def test_values(adjacency_matrix):
"""Check if adjacency matrix values are positive"""
values = adjacency_matrix.values.ravel()
assert all(v >= 0 for v in values)


def test_output(adjacency_matrix):
adjacency_matrix.to_pickle(os.path.join(data_path, "_adj_mx.pickle"))
50 changes: 50 additions & 0 deletions tests/test_3_city.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""Testing city model behavior"""

import os
import pytest
import geopandas as gpd
import pandas as pd
import statistics
from blocksnet import City

data_path = "./tests/data"


@pytest.fixture
def blocks():
return gpd.read_parquet(os.path.join(data_path, "_blocks.parquet"))


@pytest.fixture
def adjacency_matrix():
return pd.read_pickle(os.path.join(data_path, "_adj_mx.pickle"))


@pytest.fixture
def local_crs(blocks):
return blocks.crs


@pytest.fixture
def buildings(local_crs):
return gpd.read_parquet(os.path.join(data_path, "buildings.parquet")).to_crs(local_crs)


@pytest.fixture
def city(blocks, adjacency_matrix, buildings):
city = City(blocks, adjacency_matrix)
city.update_buildings(buildings)
return city


def test_coherence(city, blocks, adjacency_matrix):
blocks_gdf = city.get_blocks_gdf(True)
assert all(blocks.index == blocks_gdf.index)
assert all(adjacency_matrix.index == city.adjacency_matrix.index)
assert all(adjacency_matrix.columns == city.adjacency_matrix.columns)
assert all(blocks_gdf.index == city.adjacency_matrix.index)
assert all(city.adjacency_matrix.index == city.adjacency_matrix.columns)


def test_output(city):
city.to_pickle(os.path.join(data_path, "_city.pickle"))
42 changes: 0 additions & 42 deletions tests/test_preprocessing.py

This file was deleted.

0 comments on commit 0a17bad

Please sign in to comment.