예제 #1
0
    def test_2(self):
        """
        Initialize a simple worker with no idxids
        """
        func = None
        version = None
        cfg = {
            "path": "dummy",
            "func_name": "dummy",
            "provides_results": [
                {"name": "attr1", "path": "shared.results.attr1.path"},
                {"name": "attr2", "path": "shared.results.attr2.path"},
            ],
            "consumes_input": [{"name": "attr", "path": "shared.input.attr.path"}],
        }
        component = HubitModelComponent.from_cfg(cfg, 0)

        # No index IDs in model
        tree_for_idxcontext = {"": DummyLengthTree()}

        # Query something known to exist
        querystring = HubitQueryPath(component.provides_results[0].path)
        w = _Worker(
            lambda x: x,
            lambda x: x,
            component,
            querystring,
            func,
            version,
            tree_for_idxcontext,
            dryrun=True,
        )
예제 #2
0
    def test_1(self):
        """
        Fails since query does not match.
        """
        func = None
        version = None
        cfg = {
            "path": "dummy",
            "func_name": "dummy",
            "provides_results": [
                {"name": "attr1", "path": "shared.results.attr1.path"},
                {"name": "attr2", "path": "shared.results.attr2.path"},
            ],
            "consumes_input": [{"name": "attr", "path": "shared.input.attr.path"}],
        }
        component = HubitModelComponent.from_cfg(cfg, 0)

        # No index IDs in model
        tree = DummyLengthTree()

        querystring = HubitQueryPath("shared.attr.path")
        with self.assertRaises(HubitWorkerError) as context:
            w = _Worker(
                lambda x: x,
                lambda x: x,
                component,
                querystring,
                func,
                version,
                tree,
                dryrun=True,
            )
예제 #3
0
    def _make_worker():
        qrunner = Mock()
        qrunner.check_cache.return_value = None
        cname = None
        func = dummy_function
        version = None
        cfg = {
            "path": "dummy",
            "func_name": "dummy_fun",
            "provides_results": [
                {
                    "name": "attrs1",
                    "path": "items_outer[:@IDX_OUTER].attr.items_inner[:@IDX_INNER].path1",
                }
            ],
            "consumes_input": [
                {
                    "name": "attrs",
                    "path": "items_outer[:@IDX_OUTER].attr.items_inner[:@IDX_INNER].path",
                },
                {"name": "number", "path": "some_number"},
            ],
            "consumes_results": [
                {"name": "dependency", "path": "value"},
                {"name": "dependency2", "path": "items_outer[:@IDX_OUTER].value"},
            ],
        }
        component = HubitModelComponent.from_cfg(cfg, 0)

        # Required for shape inference. TODO: change when shapes are defined in model
        inputdata = {
            "items_outer": [
                {"attr": {"items_inner": [{"path": 2}, {"path": 1}]}},
                {"attr": {"items_inner": [{"path": 3}, {"path": 4}]}},
            ],
            "some_number": 33,
        }

        querystring = HubitQueryPath("items_outer[1].attr.items_inner[0].path1")
        _tree_for_idxcontext = tree_for_idxcontext([component], inputdata)

        w = _Worker(
            lambda x: x,
            lambda x: x,
            component,
            querystring,
            func,
            version,
            _tree_for_idxcontext,
            dryrun=True,  # Use dryrun to easily predict the result
        )

        return w
예제 #4
0
    def test_5(self):
        """
        Initialize worker with ILOC locations in
        query and ILOC wildcards in bindings
        """
        func = None
        version = None
        cfg = """
            path: dummy,
            func_name: dummy,
            provides_results: 
                - name: k_therm 
                  path: segments[IDX_SEG].layers[:@IDX_LAY].k_therm
            consumes_input:
                - name: material
                  path: segments[IDX_SEG].layers[:@IDX_LAY].material
        """
        component = HubitModelComponent.from_cfg(
            yaml.load(cfg, Loader=yaml.FullLoader), 0
        )

        # Query something known to exist
        querystr = HubitQueryPath("segments[0].layers[0].k_therm")

        seg_node = LengthNode(2)
        lay_nodes = LengthNode(2), LengthNode(2)
        seg_node.set_children(lay_nodes)
        nodes = [seg_node]
        nodes.extend(lay_nodes)
        level_names = "IDX_SEG", "IDX_LAY"
        tree = LengthTree(nodes, level_names)
        _tree_for_idxcontext = {tree.index_context: tree}

        querystr = HubitQueryPath(querystr)
        w = _Worker(
            lambda x: x,
            lambda x: x,
            component,
            querystr,
            func,
            version,
            _tree_for_idxcontext,
            dryrun=True,
        )
예제 #5
0
    def test_8(self):
        """
        Test compression of indices. The query does not include any indices
        """
        func = None
        version = None
        comp_yml = """
                    path: dummy,
                    func_name: dummy,
                    provides_results:
                        - name: mylist
                          path: factors
                    consumes_input: 
                          - name: factors
                            path: list[:@IDX1].some_attr.factors
                    """
        component = HubitModelComponent.from_cfg(
            yaml.load(comp_yml, Loader=yaml.FullLoader), 0
        )

        # Query something known to exist
        querystr = "factors"
        idx1_node = LengthNode(2)
        nodes = [idx1_node]
        level_names = ("IDX1",)
        tree = LengthTree(nodes, level_names)
        dummy_tree = DummyLengthTree()

        _tree_for_idxcontext = {"": dummy_tree, tree.index_context: tree}

        querystr = HubitQueryPath(querystr)
        w = _Worker(
            lambda x: x,
            lambda x: x,
            component,
            querystr,
            func,
            version,
            _tree_for_idxcontext,
            dryrun=True,
        )