Skip to content

Commit c7d845f

Browse files
author
Jon Duckworth
authored
Merge pull request #352 from gadomski/fix/issues/248-pointcloud-test-coverage
Add more pointcloud extension tests
2 parents 016e56c + 3e2d51c commit c7d845f

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Changed
88

99
- Split `DefaultStacIO`'s reading and writing into two methods to allow subclasses to use the default link resolution behavior ([#354](https://github.com/stac-utils/pystac/pull/354))
10+
- Increased test coverage for the pointcloud extension ([#352](https://github.com/stac-utils/pystac/pull/352))
1011

1112
### Fixed
1213

tests/extensions/test_pointcloud.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
# from copy import deepcopy
66

77
import pystac
8+
from pystac.asset import Asset
9+
from pystac.errors import ExtensionTypeError, STACError
810
from pystac.extensions.pointcloud import (
11+
AssetPointcloudExtension,
912
PointcloudExtension,
1013
PointcloudSchema,
1114
PointcloudStatistic,
@@ -178,6 +181,22 @@ def test_pointcloud_schema(self):
178181
setattr(schema, k, val)
179182
self.assertEqual(getattr(schema, k), val)
180183

184+
schema = PointcloudSchema.create("intensity", 16, "unsigned")
185+
self.assertEqual(schema.name, "intensity")
186+
self.assertEqual(schema.size, 16)
187+
self.assertEqual(schema.type, "unsigned")
188+
189+
with self.assertRaises(STACError):
190+
schema.size = 0.5 # type: ignore
191+
192+
empty_schema = PointcloudSchema({})
193+
with self.assertRaises(STACError):
194+
empty_schema.size
195+
with self.assertRaises(STACError):
196+
empty_schema.name
197+
with self.assertRaises(STACError):
198+
empty_schema.type
199+
181200
def test_pointcloud_statistics(self):
182201
props: Dict[str, Any] = {
183202
"average": 1,
@@ -201,6 +220,76 @@ def test_pointcloud_statistics(self):
201220
setattr(stat, k, val)
202221
self.assertEqual(getattr(stat, k), val)
203222

223+
stat = PointcloudStatistic.create("foo", 1, 2, 3, 4, 5, 6, 7)
224+
self.assertEqual(stat.name, "foo")
225+
self.assertEqual(stat.position, 1)
226+
self.assertEqual(stat.average, 2)
227+
self.assertEqual(stat.count, 3)
228+
self.assertEqual(stat.maximum, 4)
229+
self.assertEqual(stat.minimum, 5)
230+
self.assertEqual(stat.stddev, 6)
231+
self.assertEqual(stat.variance, 7)
232+
233+
stat.name = None # type: ignore
234+
self.assertNotIn("name", stat.properties)
235+
stat.position = None
236+
self.assertNotIn("position", stat.properties)
237+
stat.average = None
238+
self.assertNotIn("average", stat.properties)
239+
stat.count = None
240+
self.assertNotIn("count", stat.properties)
241+
stat.maximum = None
242+
self.assertNotIn("maximum", stat.properties)
243+
stat.minimum = None
244+
self.assertNotIn("minimum", stat.properties)
245+
stat.stddev = None
246+
self.assertNotIn("stddev", stat.properties)
247+
stat.variance = None
248+
self.assertNotIn("variance", stat.properties)
249+
250+
empty_stat = PointcloudStatistic({})
251+
with self.assertRaises(STACError):
252+
empty_stat.name
253+
204254
def test_statistics_accessor_when_no_stats(self):
205255
pc_item = pystac.Item.from_file(self.example_uri_no_statistics)
206256
self.assertEqual(PointcloudExtension.ext(pc_item).statistics, None)
257+
258+
def test_asset_extension(self):
259+
asset = Asset(
260+
"https://github.com/PDAL/PDAL/blob"
261+
"/a6c986f68458e92414a66c664408bee4737bbb08/test/data/laz"
262+
"/autzen_trim.laz",
263+
"laz file",
264+
"The laz data",
265+
"application/octet-stream",
266+
["data"],
267+
{"foo": "bar"},
268+
)
269+
pc_item = pystac.Item.from_file(self.example_uri_no_statistics)
270+
pc_item.add_asset("data", asset)
271+
ext = AssetPointcloudExtension(asset)
272+
self.assertEqual(ext.asset_href, asset.href)
273+
self.assertEqual(ext.properties, asset.properties)
274+
self.assertEqual(ext.additional_read_properties, [pc_item.properties])
275+
276+
def test_ext(self):
277+
pc_item = pystac.Item.from_file(self.example_uri_no_statistics)
278+
PointcloudExtension.ext(pc_item)
279+
asset = Asset(
280+
"https://github.com/PDAL/PDAL/blob"
281+
"/a6c986f68458e92414a66c664408bee4737bbb08/test/data/laz"
282+
"/autzen_trim.laz",
283+
"laz file",
284+
"The laz data",
285+
"application/octet-stream",
286+
["data"],
287+
{"foo": "bar"},
288+
)
289+
PointcloudExtension.ext(asset)
290+
291+
class RandomObject:
292+
pass
293+
294+
with self.assertRaises(ExtensionTypeError):
295+
PointcloudExtension.ext(RandomObject()) # type: ignore

0 commit comments

Comments
 (0)