Skip to content
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

Fixes check when creating links table #586

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ CREATE TABLE if not exists links (ogc_fid INTEGER PRIMARY KEY,
CHECK(TYPEOF(b_node) == 'integer')
CHECK(TYPEOF(direction) == 'integer')
CHECK(LENGTH(modes)>0)
CHECK(LENGTH(direction)==1));
CHECK(direction IN (-1, 0, 1)));

--#
select AddGeometryColumn( 'links', 'geometry', 4326, 'LINESTRING', 'XY', 1);
Expand Down
24 changes: 24 additions & 0 deletions tests/aequilibrae/project/test_network_triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import uuid
from shutil import copytree
import sqlite3
from aequilibrae.project import Project
from aequilibrae.project.project_creation import remove_triggers, add_triggers
from ...data import siouxfalls_project
Expand Down Expand Up @@ -67,3 +68,26 @@ def test_add_regular_node_change_centroid_id(self):
curr.execute("Update nodes set is_centroid=0 where node_id=?", data[:1])
self.siouxfalls.conn.commit()
self.assertEqual(nodes, network.count_nodes(), "Failed to delete node when changing centroid flag")

def test_link_direction(self):
curr = self.siouxfalls.conn.cursor()
network = self.siouxfalls.network
links = network.count_links()

sql = "UPDATE links SET direction=-2 WHERE link_id=1;"
with self.assertRaises(sqlite3.IntegrityError):
curr.execute(sql)

data = [987654, 2, "c", "default", LineString([Point(0, 0), Point(1, 0)]).wkb]
sql = "insert into links (link_id, direction, modes, link_type, geometry) Values(?,?,?,?,GeomFromWKB(?, 4326));"
with self.assertRaises(sqlite3.IntegrityError):
curr.execute(sql, data)

data = [
(987654, -1, "c", "default", LineString([Point(0, 0), Point(1, 0)]).wkb),
(876543, 0, "c", "default", LineString([Point(1, 0), Point(1, 1)]).wkb),
(765432, 1, "c", "default", LineString([Point(1, 1), Point(0, 1)]).wkb),
]
curr.executemany(sql, data)
self.siouxfalls.conn.commit()
self.assertEqual(network.count_links(), links + 3, "Failed when adding new links to the project.")