class EscdfFortranModule(object): def __init__(self, group, yaml_doc, template=None): # Init self.group = group self.specs = EscdfSpecs(self.group, yaml_doc) if template: self.template = EscdfTemplate(template) else: self.template = EscdfTemplate(f03_mod_default) # Build Fortran interfaces f03_interfaces = [] for elem in self.specs.get_elements(): spec = self.specs.get_spec(elem) for action in ["read", "write"]: spec["action"] = action f03_interfaces.append("%s" % EscdfFortranInterface(spec)) # Substitute patterns self.patterns = {} self.patterns["group"] = self.group self.patterns["interfaces"] = "\n".join(f03_interfaces) self.f03_module = self.template.substitute(self.patterns) def __str__(self): return self.f03_module
def test_is_ref_detects_refs(self): specs = EscdfSpecs("basic", escdf_basic_specs) assert ( (not specs.is_ref("metadata1")) and \ (specs.is_ref("@metadata1")) and \ (specs.is_ref("@dataset2(?)")) and \ (not specs.is_ref("@wrong_ref")) )
def __init__(self, group, yaml_doc, template=None): # Init self.group = group self.specs = EscdfSpecs(self.group, yaml_doc) if ( template ): self.template = EscdfTemplate(template) else: self.template = EscdfTemplate(f03_mod_default) # Build Fortran interfaces f03_interfaces = [] for elem in self.specs.get_elements(): spec = self.specs.get_spec(elem) for action in ["read", "write"]: spec["action"] = action f03_interfaces.append("%s" % EscdfFortranInterface(spec)) # Build Fortran wrappers f03_wrappers = [] # Substitute patterns self.patterns = {} self.patterns["group"] = self.group self.patterns["public_objects"] = "public :: &\n " + \ ", &\n ".join(self.specs.get_all_functions()) self.patterns["interfaces"] = "\n".join(f03_interfaces) self.f03_module = self.template.substitute(self.patterns)
def __init__(self, group, yaml_doc, template=None): # Init self.group = group self.specs = EscdfSpecs(self.group, yaml_doc) if ( template ): self.template = EscdfTemplate(template) else: self.template = EscdfTemplate(f03_glue_default) # Build Fortran wrappers f03_wrappers = [] for elem in self.specs.get_elements(): spec = self.specs.get_spec(elem) for action in ["read", "write"]: spec["action"] = action f03_wrappers.append("%s" % EscdfFortranWrapper(spec)) # Substitute patterns self.patterns = {} self.patterns["group"] = self.group self.patterns["wrappers"] = "\n".join(f03_wrappers) self.f03_glue = self.template.substitute(self.patterns)
def test_is_ref_varying_works(self): specs = EscdfSpecs("basic", escdf_basic_specs) assert ( (specs.is_ref_varying("@dataset2(?)")) and \ (not specs.is_ref_varying("@metadata1")) and \ (not specs.is_ref_varying("@wrong_ref")) )
def test_get_spec_sets_name(self): specs = EscdfSpecs("basic", escdf_basic_specs) assert ( "name" in specs.get_spec("metadata1") )
def test_elts_matches_yaml(self): specs = EscdfSpecs("basic", escdf_basic_specs) chk_elts = specs.get_elements() assert ( (len(chk_elts) == len(specs.elts)) and \ (len(chk_elts) == len(specs.yaml_data.keys())) )
def test_is_ref_fixed_works(self): specs = EscdfSpecs(escdf_basic_specs) assert ( (specs.is_ref_fixed("@metadata1")) and \ (not specs.is_ref_fixed("@dataset2(?)")) and \ (not specs.is_ref_fixed("@wrong_ref")) )