@@ -33,33 +33,31 @@ def item() -> pystac.Item:
3333 GridExtension .add_to (item )
3434 return item
3535
36- def test_stac_extensions (self ) -> None :
37- assert GridExtension .has_extension (self . item )
36+ def test_stac_extensions (item : pystac . Item ) -> None :
37+ assert GridExtension .has_extension (item )
3838
39- def test_item_repr (self ) -> None :
40- grid_item_ext = GridExtension .ext (self .item )
41- self .assertEqual (
42- f"<ItemGridExtension Item id={ self .item .id } >" , grid_item_ext .__repr__ ()
43- )
39+ def test_item_repr (item : pystac .Item ) -> None :
40+ grid_item_ext = GridExtension .ext (item )
41+ assert f"<ItemGridExtension Item id={ item .id } >" == grid_item_ext .__repr__ ()
4442
4543@pytest .mark .vcr ()
46- def test_attributes (self ) -> None :
47- GridExtension .ext (self . item ).apply (code )
48- assert code == GridExtension .ext (self . item ).code
49- self . item .validate ()
44+ def test_attributes (item : pystac . Item ) -> None :
45+ GridExtension .ext (item ).apply (code )
46+ assert code == GridExtension .ext (item ).code
47+ item .validate ()
5048
51- def test_invalid_code_value (self ) -> None :
52- with self . assertRaises (ValueError ):
53- GridExtension .ext (self . item ).apply ("not_a_valid_code" )
49+ def test_invalid_code_value (item : pystac . Item ) -> None :
50+ with pytest . raises (ValueError ):
51+ GridExtension .ext (item ).apply ("not_a_valid_code" )
5452
5553@pytest .mark .vcr ()
56- def test_modify (self ) -> None :
57- GridExtension .ext (self . item ).apply (code )
58- GridExtension .ext (self . item ).apply (code + "a" )
59- assert code + "a" == GridExtension .ext (self . item ).code
60- self . item .validate ()
54+ def test_modify (item : pystac . Item ) -> None :
55+ GridExtension .ext (item ).apply (code )
56+ GridExtension .ext (item ).apply (code + "a" )
57+ assert code + "a" == GridExtension .ext (item ).code
58+ item .validate ()
6159
62- def test_from_dict (self ) -> None :
60+ def test_from_dict () -> None :
6361 d : dict [str , Any ] = {
6462 "type" : "Feature" ,
6563 "stac_version" : "1.1.0" ,
@@ -76,50 +74,50 @@ def test_from_dict(self) -> None:
7674 item = pystac .Item .from_dict (d )
7775 assert code == GridExtension .ext (item ).code
7876
79- def test_to_from_dict (self ) -> None :
80- GridExtension .ext (self . item ).apply (code )
81- d = self . item .to_dict ()
77+ def test_to_from_dict (item : pystac . Item ) -> None :
78+ GridExtension .ext (item ).apply (code )
79+ d = item .to_dict ()
8280 assert code == d ["properties" ][grid .CODE_PROP ]
8381
8482 item = pystac .Item .from_dict (d )
8583 assert code == GridExtension .ext (item ).code
8684
87- def test_clear_code (self ) -> None :
88- GridExtension .ext (self . item ).apply (code )
85+ def test_clear_code (item : pystac . Item ) -> None :
86+ GridExtension .ext (item ).apply (code )
8987
90- with self . assertRaises (ValueError ):
88+ with pytest . raises (ValueError ):
9189 # Ignore type errors because this test intentionally checks behavior
9290 # that does not conform to the type signature.
9391 # https://github.com/stac-utils/pystac/pull/878#discussion_r957352232
94- GridExtension .ext (self . item ).code = None # type: ignore
95- with self . assertRaises (ValueError ):
92+ GridExtension .ext (item ).code = None # type: ignore
93+ with pytest . raises (ValueError ):
9694 # First segment has to be all caps
9795 # https://github.com/stac-utils/pystac/pull/878#discussion_r957354927
98- GridExtension .ext (self . item ).code = "this-is-not-a-grid-code"
99- with self . assertRaises (ValueError ):
96+ GridExtension .ext (item ).code = "this-is-not-a-grid-code"
97+ with pytest . raises (ValueError ):
10098 # Folks might try to put an epsg code in
10199 # https://github.com/stac-utils/pystac/pull/878#discussion_r957355415
102- GridExtension .ext (self . item ).code = "4326"
103- with self . assertRaises (ValueError ):
100+ GridExtension .ext (item ).code = "4326"
101+ with pytest . raises (ValueError ):
104102 # Folks might try to put an epsg code in
105103 # https://github.com/stac-utils/pystac/pull/878#discussion_r957355415
106- GridExtension .ext (self . item ).code = "EPSG:4326"
104+ GridExtension .ext (item ).code = "EPSG:4326"
107105
108- def test_extension_not_implemented (self ) -> None :
106+ def test_extension_not_implemented () -> None :
109107 # Should raise exception if Item does not include extension URI
110108 item = pystac .Item .from_file (SENTINEL_EXAMPLE_URI )
111109 item .stac_extensions .remove (GridExtension .get_schema_uri ())
112110
113- with self . assertRaises (pystac .ExtensionNotImplemented ):
111+ with pytest . raises (pystac .ExtensionNotImplemented ):
114112 _ = GridExtension .ext (item )
115113
116114 # Should raise exception if owning Item does not include extension URI
117115 item .properties ["grid:code" ] = None
118116
119- with self . assertRaises (pystac .ExtensionNotImplemented ):
117+ with pytest . raises (pystac .ExtensionNotImplemented ):
120118 _ = GridExtension .ext (item )
121119
122- def test_item_ext_add_to (self ) -> None :
120+ def test_item_ext_add_to () -> None :
123121 item = pystac .Item .from_file (SENTINEL_EXAMPLE_URI )
124122 item .stac_extensions .remove (GridExtension .get_schema_uri ())
125123 assert GridExtension .get_schema_uri () not in item .stac_extensions
@@ -128,15 +126,12 @@ def test_item_ext_add_to(self) -> None:
128126
129127 assert GridExtension .get_schema_uri () in item .stac_extensions
130128
131- def test_should_raise_exception_when_passing_invalid_extension_object (
132- self ,
133- ) -> None :
134- self .assertRaisesRegex (
129+ def test_should_raise_when_passing_invalid_extension_object () -> None :
130+ with pytest .raises (
135131 ExtensionTypeError ,
136- r"^GridExtension does not apply to type 'object'$" ,
137- GridExtension .ext ,
138- object (),
139- )
132+ match = r"^GridExtension does not apply to type 'object'$" ):
133+ # intentionally calling it wrong so tell mypy to ignore this line:
134+ GridExtension .ext (object ()) # type: ignore
140135
141136
142137@pytest .fixture
0 commit comments