def _assert_doc_content(doc, is_update): """Assert content information.""" tu.assert_iter(doc.content, 1, cim.v1.DataContent) c = doc.content[0] tu.assert_object(c.topic, cim.v1.DataTopic) tu.assert_str(c.topic.description, "missing CF name: tendency_of", True) tu.assert_str(c.topic.name, "fossil_fuel_organic_carbon")
def _test_create_02(): """Test creating documents - 2.""" for ontology, version, package, typeof in pyesdoc.list_types(): doc = _create_doc(ontology, version, package, typeof) _assert_doc(doc) type_key = "{0}.{1}.{2}.{3}".format(ontology, version, package, typeof) tu.assert_str(doc.__class__.type_key, type_key)
def assert_doc_updates(doc): """Asserts a document after being updated. :param object doc: Document being tested. """ tu.assert_str(doc.description, "X")
def _test_set_option_01(): """Test setting package options - positive.""" api_url = 'http://es-doc.org' api_url_old = pyesdoc.get_option('api_url') pyesdoc.set_option('api_url', api_url) tu.assert_str(api_url, pyesdoc.get_option('api_url')) pyesdoc.set_option('api_url', api_url_old)
def _assert_doc_hierarchy_level(doc, is_update): """Assert hierarchy level information.""" tu.assert_object(doc.hierarchy_level, cim.v1.DataHierarchyLevel) h = doc.hierarchy_level tu.assert_bool(h.is_open, True) tu.assert_str(h.name, "experiment") tu.assert_str(h.value, "HADGEM2_20C3M_1_D0_hus700")
def assert_doc_updates(doc): """Asserts a document after being updated. :param object doc: Document being tested. """ tu.assert_str(doc.long_name, "X")
def _assert_doc_tile_zcoords(doc, is_update): """Assert tile zcoords information.""" t = doc.esm_model_grids[0].tiles[0] tu.assert_object(t.zcoords, cim.v1.VerticalCoordinateList) z = t.zcoords tu.assert_str(z.form, "hybrid height") tu.assert_str(z.type, "hybrid") tu.assert_iter(z.properties, 1, cim.v1.GridProperty)
def _assert_doc_core(doc, is_update): """Assert core information.""" tu.assert_iter(doc.reports, 1) r = doc.reports[0] tu.assert_date(r.date, '2011-05-01 12:00:00') tu.assert_object(r.evaluator, cim.v1.ResponsibleParty) tu.assert_str(r.evaluator.individual_name, '*****@*****.**') tu.assert_str(r.evaluator.role, 'pointofContact')
def _assert_doc_core(doc, is_update): """Assert core information.""" tu.assert_str(doc.description, "AMIP (1979 - at least 2008)", True) tu.assert_str(doc.experiment_id, "3.3") tu.assert_str(doc.long_name, "AMIP") tu.assert_iter(doc.rationales, 1, str) tu.assert_str(doc.rationales[0], "AMIP. Baseline simulation for", True) tu.assert_str(doc.short_name, "amip")
def _test(mod): """Performs standard document extensions tests,""" doc = tu.get_doc(mod) # Note - returns an extended document tu.assert_object(doc.ext) tu.assert_str(doc.type_key, doc.meta.type) tu.assert_str(doc.type_key, doc.ext.type) if hasattr(mod, "assert_doc_extensions"): mod.assert_doc_extensions(doc)
def _assert_doc_core(doc, is_update): """Assert core information.""" tu.assert_str(doc.long_name, "Machine IBM Power 6 and compiler Other") tu.assert_str(doc.short_name, "IBM Power 6_Other") tu.assert_iter(doc.contacts, 1, cim.v1.ResponsibleParty) tu.assert_str(doc.contacts[0].abbreviation, "MOHC") tu.assert_str(doc.contacts[0].organisation_name, "UK Met Office Hadley Centre") tu.assert_str(doc.contacts[0].role, "contact") tu.assert_iter(doc.units, 1, cim.v1.MachineCompilerUnit)
def _assert_doc_tile_vertical_resolution(doc, is_update): """Assert tile vertical resolution.""" t = doc.esm_model_grids[0].tiles[0] tu.assert_object(t.vertical_resolution, cim.v1.GridTileResolutionType) vr = t.vertical_resolution tu.assert_iter(vr.properties, 4, cim.v1.GridProperty) p = vr.properties[0] tu.assert_str(p.name, "TopModelLevel") tu.assert_str(p.value, "39254.8")
def _assert_doc_core(doc, is_update): """Assert core information.""" tu.assert_str(doc.description, "The HadGEM2-A model", True) if not is_update: tu.assert_str(doc.long_name, "Hadley Global Environment Model 2 - Atmosphere") tu.assert_date(doc.release_date, "2009") tu.assert_str(doc.short_name, "HadGEM2-A") tu.assert_str(doc.type, "model") tu.assert_int(doc.types, 2) tu.assert_str(doc.types[1], "model")
def _assert_doc(doc, typeof=None): """Perform standard test document assertions.""" tu.assert_object(doc, typeof) if hasattr(doc, "meta"): tu.assert_str(doc.meta.institute, _INSTITUTE.lower()) tu.assert_str(doc.meta.language, pyesdoc.ESDOC_DEFAULT_LANGUAGE) tu.assert_str(doc.meta.project, _PROJECT.lower()) tu.assert_str(doc.meta.source, _INSTITUTE.lower()) if typeof is not None: tu.assert_str(doc.meta.type, typeof.type_key)
def _assert_doc(doc, typeof=None): """Perform standard test document assertions.""" tu.assert_object(doc, typeof) if hasattr(doc, 'meta'): tu.assert_str(doc.meta.institute, _INSTITUTE.lower()) tu.assert_str(doc.meta.language, pyesdoc.ESDOC_DEFAULT_LANGUAGE) tu.assert_str(doc.meta.project, _PROJECT.lower()) tu.assert_str(doc.meta.source, _INSTITUTE.lower()) if typeof is not None: tu.assert_str(doc.meta.type, typeof.type_key)
def _assert_doc_core(doc, is_update): """Assert core information.""" tu.assert_str(doc.acronym, "fossil_fuel_organic_carbon") tu.assert_str(doc.data_status, "complete") tu.assert_str(doc.description, "2D gridded monthly-mean", True) tu.assert_iter(doc.storage, 1) storage = doc.storage[0] tu.assert_object(storage, cim.v1.DataStorageIp) tu.assert_str(storage.format, "ASCII") tu.assert_str(storage.file_name, "emissions of organic", True)
def _test(mod, doc, encoding): """Perform encoding specific serialization tests.""" # Encode/decode and re-assert document. as_repr = tu.encode(doc, encoding) as_doc_1 = tu.decode(as_repr, encoding) tu.assert_doc(mod, as_doc_1) # Re-encode and assert encodings. as_repr_1 = tu.encode(as_doc_1, encoding) tu.assert_int(len(as_repr), len(as_repr_1)) tu.assert_str(as_repr, as_repr_1)
def assert_extension_info(ext): """Asserts a document's extension information. :param object ext: Document extension information. """ tu.assert_str(ext.display_name, "amip") tu.assert_str(ext.description, "AMIP (1979 - at least 2008)", True) tu.assert_str(ext.full_display_name, "CMIP5 Experiment : MOHC - amip") tu.assert_int(ext.summary_fields, 2) tu.assert_str(ext.summary_fields[0], "amip") tu.assert_str(ext.summary_fields[1], "AMIP")
def assert_extension_info(ext): """Asserts a document's extension information. :param object ext: Document extension information. """ tu.assert_str(ext.display_name, "HadGEM2-A") tu.assert_str(ext.description, "The HadGEM2-A model", True) tu.assert_str(ext.full_display_name, "CMIP5 Model : MOHC - HadGEM2-A") tu.assert_int(ext.summary_fields, 2) tu.assert_str(ext.summary_fields[0], "HadGEM2-A") tu.assert_str(ext.summary_fields[1], "Hadley Global Environment Model 2 - Atmosphere")
def assert_extension_info(ext): """Asserts a document's extension information. :param object ext: Document extension information. """ tu.assert_str(ext.display_name, "fossil_fuel_organic_carbon") tu.assert_str(ext.description, "2D gridded monthly-mean", True) tu.assert_str(ext.full_display_name, "CMIP5 Data Object : MOHC - fossil_fuel_organic_carbon") tu.assert_int(ext.summary_fields, 2) tu.assert_str(ext.summary_fields[0], "fossil_fuel_organic_carbon") tu.assert_str(ext.summary_fields[1], "2D gridded monthly-mean", True)
def assert_extension_info(ext): """Asserts a document's extension information. :param object ext: Document extension information. """ tu.assert_str(ext.display_name, "IBM Power 6_Other") tu.assert_str(ext.description, "Machine IBM Power 6", True) tu.assert_str(ext.full_display_name, "CMIP5 Platform : MOHC - IBM Power 6_Other") tu.assert_int(ext.summary_fields, 2) tu.assert_str(ext.summary_fields[0], "IBM Power 6_Other") tu.assert_str(ext.summary_fields[1], "Machine IBM Power 6", True)
def assert_extension_info(ext): """Asserts a document's extension information. :param object ext: Document extension information. """ tu.assert_str(ext.display_name, u"amip") tu.assert_str(ext.description, u"Six element ensemble", True) tu.assert_str(ext.full_display_name, u"CMIP5 Ensemble : MOHC - amip") tu.assert_int(ext.summary_fields, 2) tu.assert_str(ext.summary_fields[0], u"amip") tu.assert_str(ext.summary_fields[1], u"3.3 AMIP and AMIP Ensemble")
def assert_extension_info(ext): """Asserts a document's extension information. :param object ext: Document extension information. """ tu.assert_str(ext.display_name, "CMIP5 Quality Control Data Level 2") tu.assert_str(ext.description, "CMIP5 Quality Control", True) tu.assert_str(ext.full_display_name, "CMIP5 QC Record : MOHC - CMIP5 Quality Control Data Level 2") tu.assert_str(ext.type_display_name, "QC Record") tu.assert_int(ext.summary_fields, 1) tu.assert_str(ext.summary_fields[0], "cmip5.output1.", True)
def assert_extension_info(ext): """Asserts a document's extension information. :param object ext: Document extension information. """ tu.assert_str(ext.display_name, "amip") tu.assert_str(ext.description, "Main amip ensemble simulations", True) tu.assert_str(ext.full_display_name, "CMIP5 Simulation : MOHC - amip") tu.assert_int(ext.summary_fields, 2) tu.assert_str(ext.summary_fields[0], "amip") tu.assert_str(ext.summary_fields[1], "3.3 AMIP and AMIP Ensemble", True)
def assert_extension_info(ext): """Asserts a document's extension information. :param object ext: Document extension information. """ tu.assert_str(ext.display_name, "UM N96L38 ATM Grid System") tu.assert_str(ext.description, "Met Office Unified Model", True) tu.assert_str(ext.full_display_name, "CMIP5 Grid Spec : MOHC - UM N96L38 ATM Grid System") tu.assert_int(ext.summary_fields, 2) tu.assert_str(ext.summary_fields[0], "UM N96L38 ATM Grid System") tu.assert_str(ext.summary_fields[1], "Met Office Unified Model", True)
def _assert_doc_extent(doc, is_update): """Assert extent information.""" tu.assert_object(doc.extent, cim.v1.DataExtent) e = doc.extent tu.assert_object(e.geographical, cim.v1.DataExtentGeographical) tu.assert_float(e.geographical.east, 360.0) tu.assert_float(e.geographical.north, 90.0) tu.assert_float(e.geographical.south, -90.0) tu.assert_object(e.temporal, cim.v1.DataExtentTemporal) tu.assert_date(e.temporal.begin, "1859-12-01 00:00:00") tu.assert_date(e.temporal.end, "1999-12-30 00:00:00") tu.assert_object(e.temporal.time_interval, cim.v1.DataExtentTimeInterval) ti = e.temporal.time_interval tu.assert_int(ti.factor, -1) tu.assert_int(ti.radix, 50430) tu.assert_str(ti.unit, "day")
def _assert_doc(doc, typeof=None): """Perform standard test document assertions.""" tu.assert_object(doc, typeof) if hasattr(doc, 'meta'): tu.assert_str(doc.meta.institute, _INSTITUTE.lower()) tu.assert_str(doc.meta.project, _PROJECT.lower()) tu.assert_str(doc.meta.source, pyesdoc.DEFAULT_SOURCE) if typeof is not None: tu.assert_str(doc.meta.type, typeof.type_key)
def _assert_doc_core(doc, is_update): """Assert core information.""" if not is_update: tu.assert_str(doc.description, "Six element ensemble", True) tu.assert_iter(doc.members, 6, cim.v1.EnsembleMember) tu.assert_str(doc.long_name, "3.3 AMIP and AMIP Ensemble") tu.assert_str(doc.short_name, "amip") tu.assert_iter(doc.types, 1) tu.assert_str(doc.types[0], "Initial Condition")
def _assert_doc_citations(doc, is_update): """Assert citations.""" tu.assert_int(doc.citations, 2) c = doc.citations[0] tu.assert_str(c.collective_title, "Bellouin N., O. Boucher", True) tu.assert_str(c.location, "http://www.metoffice.gov.uk/publications/HCTN/HCTN_73.pdf") tu.assert_str(c.title, "Bellouin et al. 2007") tu.assert_str(c.type, "Online Other")
def _test_module_reset(mod): """Test that the test document modules are correctly reset.""" # Assert module state is cached. assert mod in tt.INITIAL_STATE # Update state. for field in tt.STATE_FIELDS: setattr(mod, field, 'XXX') tu.assert_str(getattr(mod, field), 'XXX') # Reset. tt.reset(mod) # Assert initial state. for field in tt.STATE_FIELDS: state = tt.INITIAL_STATE[mod][field] assert getattr(mod, field) == state
def _assert_doc_core(doc, is_update): """Assert core information.""" tu.assert_iter(doc.esm_model_grids, 1, cim.v1.GridMosaic) g = doc.esm_model_grids[0] tu.assert_iter(g.citations, 2, cim.v1.Citation) tu.assert_str(g.description, "Specification of the atmosphere", True) tu.assert_bool(g.is_leaf, True) tu.assert_str(g.long_name, "Met Office Unified Model 192", True) tu.assert_str(g.short_name, "UM N96L38 ATM Grid System") tu.assert_str(g.type, "regular_lat_lon")
def assert_meta_info(meta): """Asserts a document's meta-information. :param object meta: Document meta information. """ tu.assert_iter(meta.genealogy.relationships, 1, cim.v1.DocRelationship) r = meta.genealogy.relationships[0] tu.assert_str(r.description, "The HadGEM2-A model", True) tu.assert_str(r.direction, "toTarget") tu.assert_str(r.type, "previousVersionOf") tu.assert_str(r.target.reference.name, "HadGEM1")
def _assert_doc_deployments(doc, is_update): """Assert simulation deployments.""" tu.assert_iter(doc.deployments, 1, cim.v1.Deployment) dep = doc.deployments[0] tu.assert_str(dep.description, "The resources(deployment) on which", True) tu.assert_object(dep.platform_reference, cim.v1.DocReference) ref = dep.platform_reference tu.assert_str(ref.description, "Reference to a platform", True) tu.assert_uuid(ref.id, "b765775a-e2ac-11df-9efb-00163e9152a5") tu.assert_str(ref.name, "IBM Power 6") tu.assert_str(ref.type, "platform") tu.assert_int(ref.version, 1)
def _assert_doc_report_measure(doc, is_update): """Assert report measure information.""" r = doc.reports[0] tu.assert_object(r.measure, cim.v1.Measure) m = r.measure tu.assert_str(m.description, 'WDCC Conformance', True) tu.assert_str(m.identification, 'cmip5-qc-2d') tu.assert_str(m.name, 'CMIP5 Quality Control Data Level 2')
def _assert_doc_tile(doc, is_update): """Assert tile information.""" g = doc.esm_model_grids[0] tu.assert_int(g.tile_count, 1) tu.assert_iter(g.tiles, 1, cim.v1.GridTile) tu.assert_object(g.tiles[0], cim.v1.GridTile) t = g.tiles[0] tu.assert_str(t.description, "Horizontal properties: The N96", True) tu.assert_str(t.discretization_type, "logically_rectangular") tu.assert_str(t.mnemonic, "N96")
def _assert_doc_tile_horizontal_resolution(doc, is_update): """Assert tile horizontal resolution.""" t = doc.esm_model_grids[0].tiles[0] tu.assert_object(t.horizontal_resolution, cim.v1.GridTileResolutionType) hr = t.horizontal_resolution tu.assert_str(hr.description, "1.875 degrees in longitude", True) tu.assert_iter(hr.properties, 2, cim.v1.GridProperty) p = hr.properties[0] tu.assert_str(p.name, "NumberOfLatitudinalGridCells") tu.assert_str(p.value, "145")
def _assert_doc_member_change(doc, is_update): """Assert ensemble members information.""" member = doc.members[1] tu.assert_iter(member.simulation_reference.changes, 1, cim.v1.Change) c = member.simulation_reference.changes[0] tu.assert_str(c.name, "IC mod") tu.assert_str(c.type, "InitialCondition") tu.assert_date(c.date, "1850-01-01T00:00:00Z") tu.assert_iter(c.details, 1, cim.v1.ChangeProperty) cp = c.details[0] tu.assert_str(cp.description, "ICs come from different points in the control run")
def assert_meta_info(meta): """Asserts a document's meta-information. :param object meta: Document meta information. """ tu.assert_iter(meta.external_ids, 2, cim.v1.StandardName) id = meta.external_ids[0] tu.assert_bool(id.is_open, True) tu.assert_iter(id.standards, 1, cim.v1.Standard) tu.assert_str(id.value, "MOHC_HadGEM2-A_amip_r1i1p1_1978") std = id.standards[0] tu.assert_str(std.description, "The QN_DRS value allows", True) tu.assert_str(std.name, "QN_DRS")
def _assert_doc_conformances(doc, is_update): """Assert simulation conformances.""" tu.assert_iter(doc.conformances, 13, cim.v1.Conformance) c = doc.conformances[0] tu.assert_str(c.type, "standard config") tu.assert_iter(c.requirements_references, 1, cim.v1.DocReference) ref = c.requirements_references[0] tu.assert_str(ref.description, "Reference to a NumericalRequirement", True) tu.assert_uuid(ref.id, "9fa513fc-d3a5-11df-837f-00163e9152a5") tu.assert_str(ref.name, "ic.003") tu.assert_str(ref.type, "NumericalRequirement") tu.assert_int(ref.version, 1) c = doc.conformances[7] tu.assert_str(c.description, "Prescribed land use", True) tu.assert_bool(c.is_conformant, True) tu.assert_str(c.type, "via inputs")
def _assert_doc_references(doc, is_update): """Assert simulation references.""" # Model reference. tu.assert_object(doc.model_reference, cim.v1.DocReference) ref = doc.model_reference tu.assert_str(ref.description, "Reference to a modelComponent", True) tu.assert_uuid(ref.id, "7a2b64cc-03ca-11e1-a36a-00163e9152a5") tu.assert_str(ref.name, "HadGEM2-A") tu.assert_str(ref.type, "modelComponent") tu.assert_int(ref.version, 1) # Experiment reference. tu.assert_iter(doc.supports_references, 1, cim.v1.DocReference) ref = doc.supports_references[0] tu.assert_str(ref.description, "Reference to an Experiment", True) tu.assert_uuid(ref.id, "9fa513fc-d3a5-11df-837f-00163e9152a5") tu.assert_str(ref.name, "amip") tu.assert_str(ref.type, "experiment") tu.assert_int(ref.version, 1)
def assert_extension_info(ext): """Asserts a document's extension information. :param object ext: Document extension information. """ tu.assert_str(ext.display_name, "amip") tu.assert_str(ext.description, "Main amip ensemble simulations", True) tu.assert_str(ext.full_display_name, "CMIP5 Simulation : MOHC - amip") tu.assert_str(ext.type_display_name, "Simulation") tu.assert_int(ext.summary_fields, 2) tu.assert_str(ext.summary_fields[0], "amip") tu.assert_str(ext.summary_fields[1], "3.3 AMIP and AMIP Ensemble", True)
def _assert_doc_core(doc, is_update): """Assert core information.""" tu.assert_str(doc.authors, "C. Jones, J. Hughes", True) tu.assert_object(doc.date_range, cim.v1.ClosedDateRange) tu.assert_str(doc.date_range.duration, "P30Y") tu.assert_date(doc.date_range.start, "1978-12-01 00:00:00+00:00") tu.assert_str(doc.description, "Main amip ensemble simulations", True) tu.assert_str(doc.long_name, "3.3 AMIP and AMIP Ensemble", True) tu.assert_iter(doc.projects, 1, str) tu.assert_iter(doc.projects[0], "CMIP5") tu.assert_iter(doc.responsible_parties, 4, cim.v1.ResponsibleParty) tu.assert_str(doc.short_name, "amip") tu.assert_object(doc.spinup_date_range, cim.v1.ClosedDateRange) tu.assert_str(doc.spinup_date_range.duration, "P30Y") tu.assert_date(doc.spinup_date_range.start, "1978-12-01 00:00:00+00:00")