Skip to content

Commit 6e8f56b

Browse files
committed
simplify pytest plugin example handling
1 parent d616fbb commit 6e8f56b

1 file changed

Lines changed: 6 additions & 24 deletions

File tree

pytest_asdf/plugin.py

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import io
21
import os
32
import pathlib
43
from dataclasses import dataclass
@@ -199,43 +198,26 @@ def from_parent(
199198
return result
200199

201200
def runtest(self):
202-
from asdf import AsdfFile, _block, generic_io
201+
import asdf
202+
from asdf import _block, generic_io
203203
from asdf.testing import helpers
204204

205205
# Make sure that the examples in the schema files (and thus the
206206
# ASDF standard document) are valid.
207207
buff = helpers.yaml_to_asdf("example: " + self.example.example.strip(), version=self.example.version)
208208

209-
ff = AsdfFile(
210-
uri=pathlib.Path(self.filename).expanduser().absolute().as_uri(),
211-
ignore_unrecognized_tag=self.ignore_unrecognized_tag,
212-
)
213-
214-
# Fake an external file
215-
ff2 = AsdfFile({"data": np.empty((1024 * 1024 * 8), dtype=np.uint8)})
216-
217-
ff._external_asdf_by_uri[
218-
(pathlib.Path(self.filename).expanduser().absolute().parent / "external.asdf").as_uri()
219-
] = ff2
220-
209+
# add a few blocks
210+
# make a block and write it out to the above generated buffer/example
221211
wb = _block.writer.WriteBlock(np.zeros(1024 * 1024 * 8, dtype=np.uint8))
222212
with generic_io.get_file(buff, mode="rw") as f:
223213
f.seek(0, 2)
224214
_block.writer.write_blocks(f, [wb, wb], streamed_block=wb)
225215
f.seek(0)
226216

227-
try:
228-
ff._open_impl(ff, buff, mode="rw")
229-
except Exception:
230-
print(f"Example: {self.example.description}\n From file: {self.filename}")
231-
raise
217+
af = asdf.loads(buff.getvalue())
232218

233-
# Just test we can write it out. A roundtrip test
234-
# wouldn't always yield the correct result, so those have
235-
# to be covered by "real" unit tests.
236219
if b"external.asdf" not in buff.getvalue():
237-
buff = io.BytesIO()
238-
ff.write_to(buff)
220+
asdf.dumps(af)
239221

240222
def reportinfo(self):
241223
return self.fspath, 0, ""

0 commit comments

Comments
 (0)