From b1d4e3151667f6e1d7942435374aac8ab6b6469d Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 11 Aug 2026 15:19:02 +0200 Subject: add name/description to Python MbTiles struct --- .../__pycache__/__init__.cpython-314.pyc | Bin 0 -> 207 bytes hittekaart-py/hittekaart_py/hittekaart_py.pyi | 2 +- hittekaart-py/src/lib.rs | 18 +++++++++++------- 3 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 hittekaart-py/hittekaart_py/__pycache__/__init__.cpython-314.pyc (limited to 'hittekaart-py') diff --git a/hittekaart-py/hittekaart_py/__pycache__/__init__.cpython-314.pyc b/hittekaart-py/hittekaart_py/__pycache__/__init__.cpython-314.pyc new file mode 100644 index 0000000..11caa7e Binary files /dev/null and b/hittekaart-py/hittekaart_py/__pycache__/__init__.cpython-314.pyc differ diff --git a/hittekaart-py/hittekaart_py/hittekaart_py.pyi b/hittekaart-py/hittekaart_py/hittekaart_py.pyi index b3d110c..00ed13c 100644 --- a/hittekaart-py/hittekaart_py/hittekaart_py.pyi +++ b/hittekaart-py/hittekaart_py/hittekaart_py.pyi @@ -17,7 +17,7 @@ class Storage: def OsmAnd(path: bytes) -> "Storage": ... @staticmethod - def MbTiles(path: bytes) -> "Storage": ... + def MbTiles(path: bytes, name: str | None, description: str | None) -> "Storage": ... class HeatmapRenderer: diff --git a/hittekaart-py/src/lib.rs b/hittekaart-py/src/lib.rs index b93d9d6..3a9b3ed 100644 --- a/hittekaart-py/src/lib.rs +++ b/hittekaart-py/src/lib.rs @@ -88,7 +88,7 @@ impl Track { enum StorageType { Folder(PathBuf), OsmAnd(PathBuf), - MbTiles(PathBuf), + MbTiles(PathBuf, Option, Option), } /// Represents a storage target. @@ -125,17 +125,17 @@ impl Storage { } #[staticmethod] - #[pyo3(name = "MbTiles")] - fn mbtiles(path: &[u8]) -> Self { + #[pyo3(name = "MbTiles", signature = (path, name = None, description = None))] + fn mbtiles(path: &[u8], name: Option, description: Option) -> Self { let path = OsStr::from_bytes(path); - Storage(StorageType::MbTiles(path.into())) + Storage(StorageType::MbTiles(path.into(), name, description)) } fn __repr__(&self) -> String { match self.0 { StorageType::Folder(ref path) => format!("", path.display()), StorageType::OsmAnd(ref path) => format!("", path.display()), - StorageType::MbTiles(ref path) => format!("", path.display()), + StorageType::MbTiles(ref path, ..) => format!("", path.display()), } } } @@ -152,9 +152,13 @@ impl Storage { .map_err(|e| err_to_py(&e))?; Ok(Box::new(storage)) } - StorageType::MbTiles(ref path) => { - let storage = hittekaart::storage::MbTiles::open(path.clone()) + StorageType::MbTiles(ref path, ref name, ref desc) => { + let mut storage = hittekaart::storage::MbTiles::open(path.clone()) .map_err(|e| err_to_py(&e))?; + if let Some(n) = name { + storage = storage.with_name(n.clone()); + } + storage = storage.with_description(desc.clone()); Ok(Box::new(storage)) } } -- cgit v1.2.3 From bfdb5b970f313e7cb64cd7e2b34394fea5358d6b Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 17 Aug 2026 20:17:47 +0200 Subject: add Python tests mostly to check that the API and the calling works --- hittekaart-py/tests/test_api.py | 71 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 hittekaart-py/tests/test_api.py (limited to 'hittekaart-py') diff --git a/hittekaart-py/tests/test_api.py b/hittekaart-py/tests/test_api.py new file mode 100644 index 0000000..1ea51c2 --- /dev/null +++ b/hittekaart-py/tests/test_api.py @@ -0,0 +1,71 @@ +from hittekaart_py import ( + Track, HeatmapRenderer, MarktileRenderer, TilehuntRenderer, Settings, Storage, generate +) + + +def tracks(): + return [ + Track.from_file(b"../test-assets/Synthetic_BRouter_1.gpx.gz", "gzip"), + ] + + +def storage(): + return Storage.MbTiles(b":memory:", "heat", "mappy") + + +def test_track_from_file(): + track = Track.from_file(b"../test-assets/Synthetic_BRouter_1.gpx.gz", "gzip") + assert track is not None + + +def test_track_from_coordinates(): + track = Track.from_coordinates([(1.0, 2.0), (3.0, 4.0)]) + assert track is not None + + +def test_storage_folder(): + storage = Storage.Folder(b"/tmp") + assert storage is not None + + +def test_storage_osmand(): + storage = Storage.OsmAnd(b":memory:") + assert storage is not None + + +def test_storage_mbtiles(): + storage = Storage.MbTiles(b":memory:") + assert storage is not None + + storage = Storage.MbTiles(b":memory:", "Heatmap") + assert storage is not None + + storage = Storage.MbTiles(b":memory:", "Heatmap", "This is my heatmap") + assert storage is not None + + +def test_generate_heatmap(): + generate( + Settings(), + tracks(), + HeatmapRenderer(), + storage(), + ) + + +def test_generate_marktile(): + generate( + Settings(), + tracks(), + MarktileRenderer(), + storage(), + ) + + +def test_generate_tilehunt(): + generate( + Settings(), + tracks(), + TilehuntRenderer(10), + storage(), + ) -- cgit v1.2.3