Beispiel #1
0
    def test(self):

        # MOOSEDOCS:example-begin
        # Load the packages
        from moosetools import pyhit
        from moosetools import moosetree

        # Read the file
        root = pyhit.load(os.path.join(os.path.dirname(__file__), 'input.i'))

        # Locate and modify "x_max" parameter for the mesh
        mesh = moosetree.find(root, func=lambda n: n.fullpath == '/Mesh/gen')
        mesh["x_max"] = 4

        # Set the comment on altered parameter
        mesh.setComment("x_max", "Changed from 3 to 4")

        # Write the modified file
        pyhit.write("input_modified.i", root)

        # MOOSEDOCS:example-end
        self.assertEqual(mesh["x_max"], 4)
        self.assertEqual(mesh.comment("x_max"), "Changed from 3 to 4")

        out = mesh.render()
        self.assertIn("x_max = 4", out)
        self.assertIn("Changed from 3 to 4", out)
Beispiel #2
0
def _create_runners(root_dir, filename, spec_file_blocks, obj_factory):
    """
    Return the `Runner` objects, with attached `Differ` objects, as defined in HIT file given in
    *filename*.

    The *root_dir* is the starting location provided to the `discover` function. Objects are
    only extracted from the HIT blocks in *spec_file_blocks*. The *obj_factory* is used to by the
    HIT parser to create the desired object type.

    TODO: This should return a list of lists and allow for each `Runner` to optionally, have a
          separate entry in the outer list. This will allow handling of intra-file dependencies
          if needed or the ability to run without any dependencies. For example, the `Runner`
          could have a `depends_on`, that defaults to the previously defined runner. Supply `None`
          would put it in its own entry in the outer list.
    """
    root = pyhit.load(filename)
    wh = MooseTestWarehouse(root_dir=root_dir, specfile=filename)
    parser = factory.Parser(obj_factory, wh)
    for node in moosetree.findall(root,
                                  func=lambda n: n.name in spec_file_blocks):
        parser.parse(
            filename,
            node,
        )
    return wh.objects, max(parser.status(), wh.status())
Beispiel #3
0
    def parse(self, filename, root=None):
        """
        Instantiate the `MooseObjects` in the supplied *filename* or in the `pyhit.Node` tree with
        a *root* node. If the *root* is supplied, the *filename* is only used for error reporting, if
        it is omitted then the file is opened to create the *root*.

        This method should not raise exceptions. It reports all problems with logging errors. Prior
        to running it resets the error counts (see `core.MooseObject.reset()`). As such the
        `status` method (see `core.MooseObject.status()`) will return a non-zero code if an
        error occurred.
        """
        if root is None:
            if not os.path.isfile(filename):
                self.error(
                    "The filename '{}' does not exist.".format(filename))
                return 1
            try:
                root = pyhit.load(filename)
            except Exception as err:
                self.exception("Failed to load filename with pyhit: {}",
                               filename)
                return 1

        # Iterate of all nodes with "type = ..."
        paths = set()
        for node in moosetree.findall(
                root,
                func=lambda n: 'type' in n,
                method=self.getParam('iteration_method')):
            self._checkDuplicates(filename, paths, node)
            self._parseNode(filename, node)
        return self.status()
Beispiel #4
0
def _load_config(filename):
    """
    Load the supplied HIT *filename* using the `pyhit.load` function and return the root node.
    """
    if not os.path.isfile(filename):
        msg = "The configuration file, '{}', does not exist."
        raise RuntimeError(msg.format(filename))
    return pyhit.load(filename)
Beispiel #5
0
    def _setParallel(self):
        """ Read the test spec file and determine if parallel_scheduling is set. """
        if self.__parallel_scheduling is not None:
            return self.__parallel_scheduling
        self.__parallel_scheduling = False

        job = self.getJob()
        if job:
            # We only need a single tester so we know what spec file to load.
            # TODO: would be nice to have access to this without needing tester.specs
            tester = job[0].getTester()
            root = pyhit.load(
                os.path.join(tester.specs['test_dir'],
                             tester.specs['spec_file']))
            self.__parallel_scheduling = root.children[0].get(
                'parallel_scheduling', False)

        return self.__parallel_scheduling