@@ -923,34 +923,60 @@ def test_bbox_antimeridian():
923923 assert linter .check_bbox_antimeridian () == True
924924
925925
926+ # Check if stac-pydantic is available
927+ try :
928+ import importlib
929+
930+ importlib .import_module ("stac_pydantic" )
931+ PYDANTIC_AVAILABLE = True
932+ except ImportError :
933+ PYDANTIC_AVAILABLE = False
934+
935+ # Test decorator for pydantic tests
936+ pytest .mark .pydantic = pytest .mark .skipif (
937+ not PYDANTIC_AVAILABLE ,
938+ reason = "stac-pydantic is not installed. Run 'pip install -e .[dev]' to install test dependencies." ,
939+ )
940+
941+
942+ @pytest .mark .pydantic
926943def test_lint_pydantic_validation_valid ():
927944 """Test pydantic validation with a valid STAC item."""
928945 file = "sample_files/1.0.0/core-item.json"
929946 linter = Linter (file , pydantic = True )
930947
931- assert linter .valid_stac == True
948+ assert linter .valid_stac is True
932949 assert linter .asset_type == "ITEM"
933- assert "stac-pydantic Item model" in linter .message ["schema" ]
950+ assert any ( "stac-pydantic" in schema for schema in linter .message ["schema" ])
934951 assert linter .message ["validation_method" ] == "pydantic"
935952
936953
954+ @pytest .mark .pydantic
937955def test_lint_pydantic_validation_invalid ():
938956 """Test pydantic validation with an invalid STAC item (missing required fields)."""
939957 file = "sample_files/1.0.0/bad-item.json"
940958 linter = Linter (file , pydantic = True )
941959
942- assert linter .valid_stac == False
960+ assert linter .valid_stac is False
943961 assert "PydanticValidationError" in linter .message ["error_type" ]
944962 assert "id: Field required" in linter .message ["error_message" ]
945- assert linter .message ["validation_method" ] == "pydantic"
946963
947964
948- def test_lint_pydantic_validation_recursive ():
949- """Test pydantic validation with recursive option."""
950- file = "sample_files/1.0.0/collection.json"
951- linter = Linter (file , recursive = True , max_depth = 1 , pydantic = True )
965+ def test_pydantic_fallback_without_import (monkeypatch ):
966+ """Test that pydantic validation falls back to JSONSchema when stac-pydantic is not available."""
967+ # Skip this test if stac-pydantic is actually installed
968+ if PYDANTIC_AVAILABLE :
969+ pytest .skip ("stac-pydantic is installed, skipping fallback test" )
952970
953- assert linter .valid_stac == True
954- assert linter .asset_type == "COLLECTION"
955- assert "stac-pydantic Collection model" in linter .message ["schema" ]
956- assert linter .message ["validation_method" ] == "pydantic"
971+ # Test that pydantic=False works without stac-pydantic
972+ file = "sample_files/1.0.0/core-item.json"
973+ linter = Linter (file , pydantic = False )
974+ assert linter .valid_stac is True
975+ assert linter .asset_type == "ITEM"
976+ assert linter .message ["validation_method" ] == "default"
977+
978+ # Test that pydantic=True falls back to JSONSchema when stac-pydantic is not available
979+ linter = Linter (file , pydantic = True )
980+ assert linter .valid_stac is True
981+ assert linter .asset_type == "ITEM"
982+ assert linter .message ["validation_method" ] == "default"
0 commit comments