예제 #1
0
    def test_returns_arguments_based_on_groups(self):
        func = lambda x: -x
        matcher = matchers.RegexMatcher(func, 'foo')

        regex = Mock()
        regex.groupindex = {'foo': 4, 'baz': 5}

        match = Mock()
        match.groups.return_value = ('1', '2', '3', 'bar', '-45.3')
        positions = {
            1: (13, 14),
            2: (16, 17),
            3: (22, 23),
            4: (32, 35),
            5: (39, 44),
        }
        match.start.side_effect = lambda idx: positions[idx][0]
        match.end.side_effect = lambda idx: positions[idx][1]

        regex.match.return_value = match
        matcher.regex = regex

        expected = [
            (13, 14, '1', '1', None),
            (16, 17, '2', '2', None),
            (22, 23, '3', '3', None),
            (32, 35, 'bar', 'bar', 'foo'),
            (39, 44, '-45.3', '-45.3', 'baz'),
        ]

        m = matcher.match('some numbers 1, 2 and 3 and the bar is -45.3')
        assert m.func is func
        args = m.arguments
        have = [(a.start, a.end, a.original, a.value, a.name) for a in args]
        eq_(have, expected)
예제 #2
0
    def test_steps_with_same_prefix_are_not_ordering_sensitive(self):
        # -- RELATED-TO: issue #280
        def step_func1(context): pass
        def step_func2(context): pass
        matcher1 = matchers.RegexMatcher(step_func1, "I do something")
        matcher2 = matchers.RegexMatcher(step_func2, "I do something more")

        # -- CHECK: ORDERING SENSITIVITY
        matched1 = matcher1.match(matcher2.string)
        matched2 = matcher2.match(matcher1.string)
        assert matched1 is None
        assert matched2 is None

        # -- CHECK: Can match itself (if step text is simple)
        matched1 = matcher1.match(matcher1.string)
        matched2 = matcher2.match(matcher2.string)
        assert isinstance(matched1, model.Match)
        assert isinstance(matched2, model.Match)
예제 #3
0
 def test_returns_none_if_regex_does_not_match(self):
     matcher = matchers.RegexMatcher(None, 'a string')
     regex = Mock()
     regex.match.return_value = None
     matcher.regex = regex
     assert matcher.match('just a random step') is None
예제 #4
0
 def test_step_should_not_use_regex_begin_and_end_marker(self):
     matchers.RegexMatcher(None, "^I do something$")
예제 #5
0
 def get_matcher(func, string):
     if string[:1] == string[-1:] == '/':
         return matchers.RegexMatcher(func, string[1:-1])
     return matchers.current_matcher(func, string)