def test_fragment_constraint():
    parser = build_parser()

    # Capture show name until we hit the identifier
    group = CaptureGroup(parser, parser.result)\
        .capture_fragment('show_name', single=False)\
        .until_fragment(node__re='identifier')

    # TODO test CaptureStep.__repr__ properly
    repr(group.steps)

    group.execute()

    # Build the result from tree
    parser.result.build()

    # Ensure result is valid
    assert_result(parser.result, (1.0, {'show_name': ['Show', 'Name']}))
示例#2
0
 def capture_closure(self,
                     tag,
                     regex=None,
                     func=None,
                     single=True,
                     **kwargs):
     return CaptureGroup(self, self.result).capture_closure(tag,
                                                            regex=regex,
                                                            func=func,
                                                            single=single,
                                                            **kwargs)
def test_invalid_attribute():
    parser = build_parser()

    # Capture show name until we hit the identifier
    with pytest.raises(ValueError) as exc:
        CaptureGroup(parser, parser.result) \
            .capture_fragment('show_name', single=False) \
            .until_fragment(blah__re='identifier') \
            .execute()

    assert_that(str(exc.value),
                equal_to("Unknown constraint match type 'blah'"))
def test_value_constraint():
    parser = build_parser()

    # Capture show name until we hit the identifier
    CaptureGroup(parser, parser.result) \
        .capture_fragment('show_name', single=False) \
        .until_fragment(value__re='identifier') \
        .execute()

    # Build the result from tree
    parser.result.build()

    # Ensure result is valid
    assert_result(parser.result, (1.0, {'show_name': ['Show', 'Name']}))