Skip to content

Commit 03a7f91

Browse files
[pre-commit.ci] Corrections automatiques appliquées par les git hooks.
1 parent a3a4bb6 commit 03a7f91

File tree

1 file changed

+67
-65
lines changed

1 file changed

+67
-65
lines changed

tests/test_vector.py

Lines changed: 67 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -385,17 +385,19 @@ def test_vector_srs_property_with_multiple_tables() -> None:
385385
"""Test that Vector.srs returns unique SRS from all tables, testing lines 289-294."""
386386
vector = Vector()
387387
vector.path = "/tmp/test.gpkg"
388-
388+
389389
# Create tables with different SRS
390390
table1 = Table("table1", 10, "EPSG:4326", (0, 0, 1, 1), {"id": "Integer"}, ["geom"])
391391
table2 = Table("table2", 20, "EPSG:3857", (0, 0, 2, 2), {"name": "String"}, ["geom"])
392-
table3 = Table("table3", 30, "EPSG:4326", (0, 0, 3, 3), {"value": "Real"}, ["geom"]) # Duplicate SRS
393-
392+
table3 = Table(
393+
"table3", 30, "EPSG:4326", (0, 0, 3, 3), {"value": "Real"}, ["geom"]
394+
) # Duplicate SRS
395+
394396
vector.tables = {"table1": table1, "table2": table2, "table3": table3}
395-
397+
396398
# Test the srs property (lines 289-294)
397399
result = vector.srs
398-
400+
399401
# Should return unique SRS only
400402
assert isinstance(result, list)
401403
assert len(result) == 2
@@ -408,9 +410,9 @@ def test_vector_srs_property_empty_tables() -> None:
408410
vector = Vector()
409411
vector.path = "/tmp/test.geojson"
410412
vector.tables = {}
411-
413+
412414
result = vector.srs
413-
415+
414416
assert isinstance(result, list)
415417
assert len(result) == 0
416418

@@ -419,12 +421,12 @@ def test_vector_srs_property_single_table() -> None:
419421
"""Test that Vector.srs returns single SRS for one table."""
420422
vector = Vector()
421423
vector.path = "/tmp/test.shp"
422-
424+
423425
table = Table("single", 100, "EPSG:2154", (1, 2, 3, 4), {"attr": "String"}, ["geom"])
424426
vector.tables = {"single": table}
425-
427+
426428
result = vector.srs
427-
429+
428430
assert isinstance(result, list)
429431
assert len(result) == 1
430432
assert result[0] == "EPSG:2154"
@@ -444,16 +446,16 @@ def test_vector_from_parameters() -> None:
444446
"srs": "EPSG:4326",
445447
"bbox": [0.0, 0.0, 1.0, 1.0],
446448
"attributes": {"id": "Integer"},
447-
"geometry_columns": ["geom"]
449+
"geometry_columns": ["geom"],
448450
},
449451
"table2": {
450452
"name": "table2",
451453
"count": 20,
452454
"srs": "EPSG:3857",
453455
"bbox": [0.0, 0.0, 2.0, 2.0],
454456
"attributes": {"name": "String"},
455-
"geometry_columns": ["geometry"]
456-
}
457+
"geometry_columns": ["geometry"],
458+
},
457459
}
458460

459461
# Call the method
@@ -473,50 +475,50 @@ def test_vector_ok_from_file() -> None:
473475
# Create a mock datasource and layer
474476
mock_datasource = MagicMock()
475477
mock_layer = MagicMock()
476-
478+
477479
# Configure the mock layer
478480
mock_layer.GetName.return_value = "test_layer"
479481
mock_layer.GetFeatureCount.return_value = 100
480482
mock_layer.GetGeometryColumn.return_value = "geom"
481-
483+
482484
# Mock spatial reference
483485
mock_srs = MagicMock()
484486
mock_srs.GetAuthorityName.return_value = "EPSG"
485487
mock_srs.GetAuthorityCode.return_value = "4326"
486488
mock_layer.GetSpatialRef.return_value = mock_srs
487-
489+
488490
# Mock extent (xmin, xmax, ymin, ymax)
489491
mock_layer.GetExtent.return_value = (0.0, 10.0, 0.0, 10.0)
490-
492+
491493
# Mock FID column
492494
mock_layer.GetFIDColumn.return_value = ""
493-
495+
494496
# Mock layer definition with fields
495497
mock_layer_def = MagicMock()
496498
mock_layer_def.GetFieldCount.return_value = 1
497-
499+
498500
mock_field = MagicMock()
499501
mock_field.GetName.return_value = "id"
500502
mock_field.GetTypeName.return_value = "Integer"
501503
mock_layer_def.GetFieldDefn.return_value = mock_field
502-
504+
503505
mock_layer.GetLayerDefn.return_value = mock_layer_def
504-
506+
505507
# Configure the datasource
506508
mock_datasource.GetLayerCount.return_value = 1
507509
mock_datasource.GetLayer.return_value = mock_layer
508-
510+
509511
# Patch ogr.Open to return our mock datasource
510512
with patch("rok4.vector.ogr.Open", return_value=mock_datasource):
511513
vector_geojson = Vector.from_file("test.geojson")
512514
vector_gpkg = Vector.from_file("test.gpkg")
513515
vector_shp = Vector.from_file("test.shp")
514-
516+
515517
# Test if the returned objects are indeed instances of Vector
516518
assert isinstance(vector_geojson, Vector)
517519
assert isinstance(vector_gpkg, Vector)
518520
assert isinstance(vector_shp, Vector)
519-
521+
520522
# Verify that tables were created
521523
assert len(vector_geojson.tables) == 1
522524
assert "test_layer" in vector_geojson.tables
@@ -528,58 +530,58 @@ def test_vector_from_file_with_fid_column() -> None:
528530
# Create a mock datasource and layer
529531
mock_datasource = MagicMock()
530532
mock_layer = MagicMock()
531-
533+
532534
# Configure the mock layer
533535
mock_layer.GetName.return_value = "layer_with_fid"
534536
mock_layer.GetFeatureCount.return_value = 50
535537
mock_layer.GetGeometryColumn.return_value = "geom"
536-
538+
537539
# Mock spatial reference
538540
mock_srs = MagicMock()
539541
mock_srs.GetAuthorityName.return_value = "EPSG"
540542
mock_srs.GetAuthorityCode.return_value = "3857"
541543
mock_layer.GetSpatialRef.return_value = mock_srs
542-
544+
543545
# Mock extent
544546
mock_layer.GetExtent.return_value = (1.0, 5.0, 2.0, 6.0)
545-
547+
546548
# Mock FID column - THIS TESTS LINE 224-225
547549
mock_layer.GetFIDColumn.return_value = "fid"
548-
550+
549551
# Mock layer definition with fields
550552
mock_layer_def = MagicMock()
551553
mock_layer_def.GetFieldCount.return_value = 2
552-
554+
553555
# Mock two fields
554556
mock_field1 = MagicMock()
555557
mock_field1.GetName.return_value = "name"
556558
mock_field1.GetTypeName.return_value = "String"
557-
559+
558560
mock_field2 = MagicMock()
559561
mock_field2.GetName.return_value = "value"
560562
mock_field2.GetTypeName.return_value = "Real"
561-
563+
562564
mock_layer_def.GetFieldDefn.side_effect = [mock_field1, mock_field2]
563565
mock_layer.GetLayerDefn.return_value = mock_layer_def
564-
566+
565567
# Configure the datasource
566568
mock_datasource.GetLayerCount.return_value = 1
567569
mock_datasource.GetLayer.return_value = mock_layer
568-
570+
569571
# Patch ogr.Open to return our mock datasource
570572
with patch("rok4.vector.ogr.Open", return_value=mock_datasource):
571573
vector = Vector.from_file("test_with_fid.gpkg")
572-
574+
573575
# Verify vector was created
574576
assert isinstance(vector, Vector)
575577
assert len(vector.tables) == 1
576578
assert "layer_with_fid" in vector.tables
577-
579+
578580
# Verify the FID column was added to attributes (line 225)
579581
table = vector.tables["layer_with_fid"]
580582
assert "fid" in table.attributes
581583
assert table.attributes["fid"] == "Integer"
582-
584+
583585
# Verify other fields were also added
584586
assert "name" in table.attributes
585587
assert table.attributes["name"] == "String"
@@ -592,51 +594,51 @@ def test_vector_from_file_without_fid_column() -> None:
592594
# Create a mock datasource and layer
593595
mock_datasource = MagicMock()
594596
mock_layer = MagicMock()
595-
597+
596598
# Configure the mock layer
597599
mock_layer.GetName.return_value = "layer_no_fid"
598600
mock_layer.GetFeatureCount.return_value = 25
599601
mock_layer.GetGeometryColumn.return_value = "geometry"
600-
602+
601603
# Mock spatial reference
602604
mock_srs = MagicMock()
603605
mock_srs.GetAuthorityName.return_value = "EPSG"
604606
mock_srs.GetAuthorityCode.return_value = "4326"
605607
mock_layer.GetSpatialRef.return_value = mock_srs
606-
608+
607609
# Mock extent
608610
mock_layer.GetExtent.return_value = (0.0, 10.0, 0.0, 10.0)
609-
611+
610612
# Mock FID column - empty string (no FID column)
611613
mock_layer.GetFIDColumn.return_value = ""
612-
614+
613615
# Mock layer definition with one field
614616
mock_layer_def = MagicMock()
615617
mock_layer_def.GetFieldCount.return_value = 1
616-
618+
617619
mock_field = MagicMock()
618620
mock_field.GetName.return_value = "id"
619621
mock_field.GetTypeName.return_value = "Integer"
620-
622+
621623
mock_layer_def.GetFieldDefn.return_value = mock_field
622624
mock_layer.GetLayerDefn.return_value = mock_layer_def
623-
625+
624626
# Configure the datasource
625627
mock_datasource.GetLayerCount.return_value = 1
626628
mock_datasource.GetLayer.return_value = mock_layer
627-
629+
628630
# Patch ogr.Open to return our mock datasource
629631
with patch("rok4.vector.ogr.Open", return_value=mock_datasource):
630632
vector = Vector.from_file("test_no_fid.geojson")
631-
633+
632634
# Verify vector was created
633635
assert isinstance(vector, Vector)
634636
assert len(vector.tables) == 1
635-
637+
636638
# Verify NO FID column was added to attributes
637639
table = vector.tables["layer_no_fid"]
638640
assert "fid" not in table.attributes
639-
641+
640642
# Verify only the regular field was added
641643
assert "id" in table.attributes
642644
assert table.attributes["id"] == "Integer"
@@ -777,65 +779,65 @@ def test_table_serializable() -> None:
777779
def test_vectorset_write_descriptor_with_path() -> None:
778780
"""Test that write_descriptor correctly writes JSON to the provided path."""
779781
vectorset = VectorSet()
780-
782+
781783
# Create a simple vector with mock serializable data
782784
mock_vector = MagicMock()
783785
mock_vector.serializable = {"path": "test.geojson", "tables": []}
784786
vectorset.vectors = [mock_vector]
785-
787+
786788
with patch("rok4.vector.put_data_str") as mock_put_data_str:
787789
vectorset.write_descriptor("s3://bucket/descriptor.json")
788-
790+
789791
# Verify put_data_str was called with correct arguments
790792
mock_put_data_str.assert_called_once()
791793
args = mock_put_data_str.call_args[0]
792-
794+
793795
# Check the JSON content
794796
json_content = args[0]
795797
assert json.loads(json_content) == {"vectors": [{"path": "test.geojson", "tables": []}]}
796-
798+
797799
# Check the path
798800
assert args[1] == "s3://bucket/descriptor.json"
799801

800802

801803
def test_vectorset_write_descriptor_without_path() -> None:
802804
"""Test that write_descriptor does nothing when path is None."""
803805
vectorset = VectorSet()
804-
806+
805807
# Create a simple vector with mock serializable data
806808
mock_vector = MagicMock()
807809
mock_vector.serializable = {"path": "test.geojson", "tables": []}
808810
vectorset.vectors = [mock_vector]
809-
811+
810812
with patch("rok4.vector.put_data_str") as mock_put_data_str:
811813
vectorset.write_descriptor(None)
812-
814+
813815
# Verify put_data_str was NOT called
814816
mock_put_data_str.assert_not_called()
815817

816818

817819
def test_vectorset_write_descriptor_json_format() -> None:
818820
"""Test that write_descriptor produces correctly formatted JSON."""
819821
vectorset = VectorSet()
820-
822+
821823
# Create vectors with realistic data
822824
v1 = Vector()
823825
v1.path = "file1.geojson"
824826
v1.tables = {}
825-
827+
826828
v2 = Vector()
827829
v2.path = "file2.geojson"
828830
v2.tables = {}
829-
831+
830832
vectorset.vectors = [v1, v2]
831-
833+
832834
with patch("rok4.vector.put_data_str") as mock_put_data_str:
833835
vectorset.write_descriptor("/tmp/output.json")
834-
836+
835837
# Get the JSON content that was written
836838
json_content = mock_put_data_str.call_args[0][0]
837839
parsed = json.loads(json_content)
838-
840+
839841
# Verify structure
840842
assert "vectors" in parsed
841843
assert len(parsed["vectors"]) == 2
@@ -849,9 +851,9 @@ def test_vectorset_write_descriptor_storage_error() -> None:
849851
"""Test that write_descriptor propagates StorageError when put_data_str fails."""
850852
vectorset = VectorSet()
851853
vectorset.vectors = []
852-
854+
853855
with patch("rok4.vector.put_data_str") as mock_put_data_str:
854856
mock_put_data_str.side_effect = StorageError("S3", "Failed to write")
855-
857+
856858
with pytest.raises(StorageError):
857859
vectorset.write_descriptor("/tmp/output.json")

0 commit comments

Comments
 (0)