|
20 | 20 | # |
21 | 21 | # Copyright (c) 2015 Government of Canada |
22 | 22 | # Copyright (c) 2016 ERT Inc. |
23 | | -# Copyright (c) 2024 Tom Kralidis |
| 23 | +# Copyright (c) 2025 Tom Kralidis |
24 | 24 | # |
25 | 25 | # Permission is hereby granted, free of charge, to any person |
26 | 26 | # obtaining a copy of this software and associated documentation |
|
54 | 54 | import yaml |
55 | 55 |
|
56 | 56 | from pygeometa.core import (read_mcf, pretty_print, render_j2_template, |
57 | | - get_charstring, normalize_datestring, |
58 | | - prune_distribution_formats, |
| 57 | + get_charstring, import_metadata, |
| 58 | + normalize_datestring, prune_distribution_formats, |
59 | 59 | prune_transfer_option, MCFReadError, |
60 | | - MCFValidationError, SCHEMAS, validate_mcf) |
| 60 | + MCFValidationError, SCHEMAS, transform_metadata, |
| 61 | + validate_mcf) |
61 | 62 | from pygeometa.helpers import json_dumps |
62 | 63 | from pygeometa.schemas import (get_supported_schemas, InvalidSchemaError, |
63 | 64 | load_schema) |
@@ -229,10 +230,16 @@ def test_get_supported_schemas(self): |
229 | 230 | 'Expected specific number of supported schemas') |
230 | 231 | self.assertEqual(sorted(schemas), |
231 | 232 | sorted(['dcat', 'iso19139', 'iso19139-2', |
232 | | - 'iso19139-hnap', 'oarec-record', 'stac-item', |
233 | | - 'wmo-cmp', 'wmo-wcmp2', 'wmo-wigos']), |
| 233 | + 'iso19139-hnap', 'oarec-record', |
| 234 | + 'stac-item', 'wmo-cmp', 'wmo-wcmp2', |
| 235 | + 'wmo-wigos']), |
234 | 236 | 'Expected exact list of supported schemas') |
235 | 237 |
|
| 238 | + schemas = get_supported_schemas(include_autodetect=True) |
| 239 | + self.assertEqual(len(schemas), 10, |
| 240 | + 'Expected specific number of supported schemas') |
| 241 | + self.assertIn('autodetect', schemas, 'Expected autodetect in list') |
| 242 | + |
236 | 243 | def test_render_j2_template(self): |
237 | 244 | """test template rendering""" |
238 | 245 |
|
@@ -397,8 +404,8 @@ def test_validate_mcf(self): |
397 | 404 | with self.assertRaises(MCFValidationError): |
398 | 405 | is_valid = validate_mcf({'foo': 'bar'}) |
399 | 406 |
|
400 | | - def test_import(self): |
401 | | - """test metadata import""" |
| 407 | + def test_schema_import(self): |
| 408 | + """test direct metadata schema import""" |
402 | 409 |
|
403 | 410 | schema = ISO19139OutputSchema() |
404 | 411 |
|
@@ -434,6 +441,46 @@ def test_import(self): |
434 | 441 | self.assertEqual(expected_bbox, result_bbox, |
435 | 442 | 'Expected specific BBOX') |
436 | 443 |
|
| 444 | + def test_import_metadata(self): |
| 445 | + """test metadata import""" |
| 446 | + |
| 447 | + with open(get_abspath('md-SMJP01RJTD-gmd.xml')) as fh: |
| 448 | + mcf = import_metadata('iso19139', fh.read()) |
| 449 | + |
| 450 | + self.assertEqual( |
| 451 | + mcf['identification']['title'], |
| 452 | + 'WIS/GTS bulletin SMJP01 RJTD in FM12 SYNOP', |
| 453 | + 'Expected specific title') |
| 454 | + |
| 455 | + with open(get_abspath('md-SMJP01RJTD-gmd.xml')) as fh: |
| 456 | + mcf = import_metadata('autodetect', fh.read()) |
| 457 | + |
| 458 | + self.assertEqual( |
| 459 | + mcf['identification']['title'], |
| 460 | + 'WIS/GTS bulletin SMJP01 RJTD in FM12 SYNOP', |
| 461 | + 'Expected specific title') |
| 462 | + |
| 463 | + def test_transform_metadata(self): |
| 464 | + """test metadata transform""" |
| 465 | + |
| 466 | + with open(get_abspath('md-SMJP01RJTD-gmd.xml')) as fh: |
| 467 | + m = transform_metadata('iso19139', 'oarec-record', fh.read()) |
| 468 | + |
| 469 | + m = json.loads(m) |
| 470 | + self.assertEqual( |
| 471 | + m['properties']['title'], |
| 472 | + 'WIS/GTS bulletin SMJP01 RJTD in FM12 SYNOP', |
| 473 | + 'Expected specific title') |
| 474 | + |
| 475 | + with open(get_abspath('md-SMJP01RJTD-gmd.xml')) as fh: |
| 476 | + m = transform_metadata('autodetect', 'oarec-record', fh.read()) |
| 477 | + |
| 478 | + m = json.loads(m) |
| 479 | + self.assertEqual( |
| 480 | + m['properties']['title'], |
| 481 | + 'WIS/GTS bulletin SMJP01 RJTD in FM12 SYNOP', |
| 482 | + 'Expected specific title') |
| 483 | + |
437 | 484 |
|
438 | 485 | def get_abspath(filepath): |
439 | 486 | """helper function absolute file access""" |
|
0 commit comments