Exemplo n.º 1
0
 def test_tokens_of_different_classes_are_not_equal(self):
     # see http://bugs.python.org/issue16279
     self.assertFalse(
         condent.NonDelimiter(content=12) == condent.RightDelimiter(
             delimiter=12))
     self.assertNotEqual(
         condent.NonDelimiter(content=12),
         condent.RightDelimiter(delimiter=12),
     )
Exemplo n.º 2
0
    def test_it_can_tokenize_repeated_right_delimiters(self):
        parsed = iter(["foo", "<", "bar, baz", "<", "quux", ">", ">"])

        tokens = condent.tokenize(parsed, self.left_delims, self.right_delims)

        self.assertEqual(
            list(tokens), [
                condent.LeftDelimiter(before="foo", delimiter="<"),
                condent.LeftDelimiter(before="bar, baz", delimiter="<"),
                condent.NonDelimiter(content="quux"),
                condent.RightDelimiter(delimiter=">"),
                condent.RightDelimiter(delimiter=">"),
            ]
        )
Exemplo n.º 3
0
    def test_it_creates_right_delimiter_tokens(self):
        one, another = mock.Mock(), mock.Mock()
        parsed = iter([one, ">", another])

        tokens = condent.tokenize(parsed, self.left_delims, self.right_delims)

        self.assertEqual(list(tokens), [
            condent.NonDelimiter(content=one),
            condent.RightDelimiter(delimiter=">"),
            condent.NonDelimiter(content=another),
        ])
Exemplo n.º 4
0
    def test_it_creates_left_delimiter_tokens_with_before_after_rights(self):
        before, content = mock.Mock(), mock.Mock()
        parsed = iter([before, "<", content, ">", before.another, "<"])

        tokens = condent.tokenize(parsed, self.left_delims, self.right_delims)

        self.assertEqual(
            list(tokens), [
                condent.LeftDelimiter(before=before, delimiter="<"),
                condent.NonDelimiter(content=content),
                condent.RightDelimiter(delimiter=">"),
                condent.LeftDelimiter(before=before.another, delimiter="<"),
            ]
        )
Exemplo n.º 5
0
    def test_it_empties_the_stack_when_partially_done(self):
        def side_effect(before, left, items, right):
            return before + left + "".join(items) + right
        self.builder.build.side_effect = side_effect

        tokens = [
            condent.LeftDelimiter(before="foo", delimiter="("),
            condent.NonDelimiter(content="bar"),
            condent.LeftDelimiter(before="", delimiter="("),
            condent.NonDelimiter(content="30"),
            condent.RightDelimiter(delimiter=")"),
        ]

        got = self.condenter.redent([tokens])

        self.assertEqual("".join(got), "foo(bar(30)")