예제 #1
0
    def test_metasort(self):
        node = Node(mock.Mock(), None, meta={"templates": []})
        node._content_start = 0
        for i in [3, 5, 27, 2, 1]:
            new_node = Node(mock.Mock(), node, meta={"bob": i})
            new_node._content_start = 0
        result = jinja_filter(node, METASORT_TEMPLATE)

        self.assertEqual(result, "123527")
예제 #2
0
    def test_metaselect(self):
        node = Node(mock.Mock(),  None, meta={"templates": []})
        node._content_start = 0
        for i in [True, True, False, True, None]:
            new_node = Node(mock.Mock(), node, meta={"bob": i})
            new_node._content_start = 0
        result = jinja_filter(node, METASELECT_TEMPLATE)

        self.assertEqual(result, "TrueTrueTrue")
예제 #3
0
    def test_metareject(self):
        node = Node(mock.Mock(),  None, meta={"templates": []})
        node._content_start = 0
        for i in [True, True, False, True, None]:
            new_node = Node(mock.Mock(), node, meta={"bob": i})
            new_node._content_start = 0
        result = jinja_filter(node, METAREJECT_TEMPLATE)

        # dict key order isn't stable, but it'll be one of these
        self.assertIn(result, ["FalseNone", "NoneFalse"])
예제 #4
0
    def test_input_output(self):
        content = "hello, how are you?"
        node = Node(mock.Mock(), None, meta={"external_cmd": "cat {INPUT} | base64 > {OUTPUT}"})
        node._content_start = 0
        output = external_filter(node, content)

        expected_output = base64.b64encode(content.encode()).decode() + "\n"
        self.assertEqual(output, expected_output)
예제 #5
0
    def test_get_content(self):
        path = pathlib.Path(self.content_path.name, "blog")
        with path.open("w") as f:
            f.write("a" * 10)

        node = Node(path, None)
        self.assertEqual(node.get_content(), "a" * 10)
        self.assertEqual(node._content_start, 0)

        node._content = None
        node._content_start = 5
        node.get_content()
        self.assertEqual(node.get_content(), "a" * 5)
        self.assertEqual(node._content_start, 5)