Beispiel #1
0
 def test_filter_by_child(self):
     """Tests filter_by_child."""
     root = create_expression.create_expression_from_prensor(
         prensor_test_util.create_big_prensor())
     root_2 = filter_expression.filter_by_child(root,
                                                path.create_path("doc"),
                                                "keep_me", "new_doc")
     [result] = calculate.calculate_prensors([root_2])
     self.assertAllEqual(
         result.get_descendant_or_error(path.Path(["new_doc"
                                                   ])).node.parent_index,
         [1])
     self.assertAllEqual(
         result.get_descendant_or_error(path.Path(["new_doc", "keep_me"
                                                   ])).node.parent_index,
         [0])
     self.assertAllEqual(
         result.get_descendant_or_error(path.Path(["new_doc",
                                                   "keep_me"])).node.values,
         [True])
     self.assertAllEqual(
         result.get_descendant_or_error(path.Path(["new_doc", "bar"
                                                   ])).node.parent_index,
         [0, 0])
     self.assertAllEqual(
         result.get_descendant_or_error(path.Path(["new_doc",
                                                   "bar"])).node.values,
         [b"b", b"c"])
Beispiel #2
0
    def test_filter_by_child_create_nested_prensor_2(self):
        """Tests filter_by_child.

    In particular, it checks for the case where parent_index != self index.
    """
        root = create_expression.create_expression_from_prensor(
            _create_nested_prensor_2())
        root_2 = filter_expression.filter_by_child(root,
                                                   path.create_path("doc"),
                                                   "keep_me", "new_doc")
        [result] = calculate.calculate_prensors([root_2])
        self.assertAllEqual(
            result.get_descendant_or_error(path.Path(["new_doc"
                                                      ])).node.parent_index,
            [1])
        self.assertAllEqual(
            result.get_descendant_or_error(path.Path(["new_doc", "keep_me"
                                                      ])).node.parent_index,
            [0])
        self.assertAllEqual(
            result.get_descendant_or_error(path.Path(["new_doc",
                                                      "keep_me"])).node.values,
            [True])
        self.assertAllEqual(
            result.get_descendant_or_error(path.Path(["new_doc", "bar"
                                                      ])).node.parent_index,
            [0, 0])
        self.assertAllEqual(
            result.get_descendant_or_error(path.Path(["new_doc",
                                                      "bar"])).node.values,
            [b"b", b"c"])
 def test_filter_by_child_create_nested_prensor(self):
     """Tests filter_by_child."""
     with self.session(use_gpu=False) as sess:
         root = create_expression.create_expression_from_prensor(
             _create_nested_prensor())
         root_2 = filter_expression.filter_by_child(root,
                                                    path.create_path("doc"),
                                                    "keep_me", "new_doc")
         result = prensor_value.materialize(
             calculate.calculate_prensors([root_2])[0], sess)
         self.assertAllEqual(
             result.get_descendant_or_error(path.Path(
                 ["new_doc"])).node.parent_index, [1])
         self.assertAllEqual(
             result.get_descendant_or_error(
                 path.Path(["new_doc", "keep_me"])).node.parent_index, [0])
         self.assertAllEqual(
             result.get_descendant_or_error(
                 path.Path(["new_doc", "keep_me"])).node.values, [True])
         self.assertAllEqual(
             result.get_descendant_or_error(path.Path(
                 ["new_doc", "bar"])).node.parent_index, [0, 0])
         self.assertAllEqual(
             result.get_descendant_or_error(path.Path(["new_doc",
                                                       "bar"])).node.values,
             [b"b", b"c"])