示例#1
0
 def test_should_match_with_utf8_string(self):
     """ Scenario: match with utf8 string """
     # Arrange
     predicate = u'zażółć gęślą jaźń'
     augmented_predicate = u'zażółć gęślą jaźń'
     method_name = 'step_utf8_match'
     docstring = r'zażółć gęślą jaźń'
     method = Mock(__doc__=docstring)
     methods = {method_name: method}
     suite = Mock(**methods)
     obj = RegexpStepMatcher(suite)
     # Act
     result_method, result_args, result_kwargs = obj.match(
         predicate, augmented_predicate, methods.keys())
     # Assert
     self.assertEqual(result_method, method)
示例#2
0
 def test_should_return_none_if_no_docstring(self):
     """ Scenario: no match by docstring """
     # Arrange
     predicate = 'my milkshake brings all the boys to the yard'
     augmented_predicate = 'my milkshake brings all the boys to the yard'
     method_name = 'step_%s' % predicate
     method = Mock(__doc__='')
     methods = {method_name: method}
     suite = Mock(**methods)
     obj = RegexpStepMatcher(suite)
     # Act
     result_method, result_args, result_kwargs = obj.match(
         predicate, augmented_predicate, methods.keys())
     # Assert
     self.assertTrue(result_method is None)
     self.assertEqual(result_args, ())
示例#3
0
 def test_should_return_suggested_method(self):
     """ Scenariusz: suggest """
     # Arrange
     obj = RegexpStepMatcher(sentinel.suite)
     # Act
     pattern = "    def step_%(method_name)s(self%(args)s):\n        %(docstring)s\n\n        raise NotImplementedError('%(predicate)s')\n\n"
     test_data = [
         ("tastes great", "tastes_great", r"r'tastes great'", ""),
         ("less filling", "less_filling", r"r'less filling'", ""),
         ("line\nfeed", "line_feed", r"r'line\nfeed'", ""),
         ("tick'ed'", "tick_ed", r"r'tick\'ed\''", ""),
         ("tastes   great", "tastes_great", r"r'tastes\s+great'", ""),
         ("argu<ment>al", "argu_ment_al", r"r'argu(.+)al'", ", ment"),
         ("arg<u>ment<al>", "arg_u_ment_al", r"r'arg(.+)ment(.+)'", ", u, al"),
         ('str"ing"', "str_ing", 'r\'str"([^"]+)"\'', ", ing"),
         ('"str"i"ngs"', "str_i_ngs", 'r\'"([^"]+)"i"([^"]+)"\'', ", str, ngs"),
         (
             'enter "10" into',
             "enter_number_into",
             'r\'enter "([^"]+)" into\'',
             ", number",
         ),
         (
             'enter "10" and "20" into',
             "enter_number_and_number_into",
             'r\'enter "([^"]+)" and "([^"]+)" into\'',
             ", number1, number2",
         ),
         (
             '''some'quote' and "double quote"''',
             "some_quote_and_double_quote",
             "r'some\\'quote\\' and \"([^\"]+)\"'",
             ", double_quote",
         ),
     ]
     for predicate, method, docstring, args in test_data:
         suggest, suggest_method, suggest_docstring = obj.suggest(predicate)
         # Assert
         expected = pattern % {
             "method_name": method,
             "docstring": docstring,
             "args": args,
             "predicate": predicate.replace("'", r"\'"),
         }
         assert suggest == expected
         assert suggest_method == method
         assert suggest_docstring == docstring
示例#4
0
 def test_should_match_with_utf8_string(self):
     """ Scenario: match with utf8 string """
     # Arrange
     predicate = "zażółć gęślą jaźń"
     augmented_predicate = "zażółć gęślą jaźń"
     method_name = "step_utf8_match"
     docstring = r"zażółć gęślą jaźń"
     method = Mock(__doc__=docstring)
     methods = {method_name: method}
     suite = Mock(**methods)
     obj = RegexpStepMatcher(suite)
     # Act
     result_method, result_args, result_kwargs = obj.match(
         predicate, augmented_predicate, methods.keys()
     )
     # Assert
     assert result_method == method
示例#5
0
 def test_should_return_none_if_no_docstring(self):
     """ Scenario: no match by docstring """
     # Arrange
     predicate = "my milkshake brings all the boys to the yard"
     augmented_predicate = "my milkshake brings all the boys to the yard"
     method_name = "step_%s" % predicate
     method = Mock(__doc__="")
     methods = {method_name: method}
     suite = Mock(**methods)
     obj = RegexpStepMatcher(suite)
     # Act
     result_method, result_args, result_kwargs = obj.match(
         predicate, augmented_predicate, methods.keys()
     )
     # Assert
     assert result_method is None
     assert result_args == ()
示例#6
0
 def test_should_return_method_and_kwargs(self):
     """ Scenario: match by docstring with named groups """
     # Arrange
     predicate = 'my milkshake brings all the boys to the yard'
     augmented_predicate = 'my milkshake brings all the boys to the yard'
     method_name = 'step_%s' % predicate
     docstring = r'my milkshake brings all the (?P<who>boys|girls) to (?P<other>.*) yard'
     method = Mock(__doc__=docstring)
     methods = {method_name: method}
     suite = Mock(**methods)
     obj = RegexpStepMatcher(suite)
     # Act
     result_method, result_args, result_kwargs = obj.match(
         predicate, augmented_predicate, methods.keys())
     # Assert
     self.assertEqual(result_method, method)
     self.assertEqual(result_kwargs, {'who': 'boys', 'other': 'the'})
示例#7
0
 def test_should_return_second_method_and_matches(self):
     """ Scenario: many methods """
     # Arrange
     predicate = "my milkshake brings all the boys to the yard"
     augmented_predicate = "my milkshake brings all the boys to the yard"
     method_name = "step_%s" % predicate
     docstring = r"my milkshake brings all the (boys|girls) to (.*) yard"
     method = Mock(__doc__=docstring)
     methods = {method_name: method, "step_other": sentinel.method}
     suite = Mock(**methods)
     obj = RegexpStepMatcher(suite)
     # Act
     result_method, result_args, result_kwargs = obj.match(
         predicate, augmented_predicate, [method_name, "step_other"]
     )
     # Assert
     assert result_method == method
     assert result_args == ("boys", "the")
示例#8
0
 def test_should_return_none_if_docstring_not_mached(self):
     """ Scenario: no match by docstring """
     # Arrange
     predicate = "not there"
     augmented_predicate = "not there"
     method_name = "step_%s" % predicate
     docstring = r"my milkshake brings all the (boys|girls) to (.*) yard"
     method = Mock(__doc__=docstring)
     methods = {method_name: method}
     suite = Mock(**methods)
     obj = RegexpStepMatcher(suite)
     # Act
     result_method, result_args, result_kwargs = obj.match(
         predicate, augmented_predicate, methods.keys()
     )
     # Assert
     assert result_method is None
     assert result_args == ()
示例#9
0
 def test_should_return_method_and_kwargs_with_mixed_groups(self):
     """ Scenario: match by docstring with named and not named groups """
     # Arrange
     predicate = "my milkshake brings all the boys to the yard"
     augmented_predicate = "my milkshake brings all the boys to the yard"
     method_name = "step_%s" % predicate
     docstring = r"my milkshake brings all the (?P<who>boys|girls) to (.*) yard"
     method = Mock(__doc__=docstring)
     methods = {method_name: method}
     suite = Mock(**methods)
     obj = RegexpStepMatcher(suite)
     # Act
     result_method, result_args, result_kwargs = obj.match(
         predicate, augmented_predicate, methods.keys()
     )
     # Assert
     assert result_method == method
     assert result_args == ()
     assert result_kwargs == {"who": "boys"}
示例#10
0
 def test_should_return_second_method_and_matches(self):
     """ Scenario: many methods """
     # Arrange
     predicate = 'my milkshake brings all the boys to the yard'
     augmented_predicate = 'my milkshake brings all the boys to the yard'
     method_name = 'step_%s' % predicate
     docstring = r'my milkshake brings all the (boys|girls) to (.*) yard'
     method = Mock(__doc__=docstring)
     methods = {
         method_name: method,
         'step_other': sentinel.method,
     }
     suite = Mock(**methods)
     obj = RegexpStepMatcher(suite)
     # Act
     result_method, result_args, result_kwargs = obj.match(
         predicate, augmented_predicate, [method_name, 'step_other'])
     # Assert
     self.assertEqual(result_method, method)
     self.assertEqual(result_args, ('boys', 'the'))
示例#11
0
文件: test_row.py 项目: depop/Morelia
 def test_evaluate_permuted_schedule(self):
     self.assemble_scene_table("Step flesh is weak\n")
     scenario = self.table_scene.steps[0]
     matcher = RegexpStepMatcher(self).add_matcher(
         MethodNameStepMatcher(self))
     visitor = TestVisitor(self, matcher, re.compile(".*"))
     self.crunks = []
     self.zones = []
     scenario.row_indices = [1, 0, 2]
     scenario.accept(visitor)
     assert "hotel" == self.got_party_zone
     assert "jail" == self.got_crunk
示例#12
0
    def test_handle_exceptions(self):
        s = Step('Given', 'exceptional')
        s.line_number = 42
        matcher = RegexpStepMatcher(self).add_matcher(
            MethodNameStepMatcher(self))
        visitor = TestVisitor(self, matcher, NullFormatter())
        matcher = self._get_default_machers()

        try:
            visitor.visit(s)
            assert False  # should raise!  # pragma: nocover
        except ZeroDivisionError as e:
            assert 'Given: exceptional' in str(e)
示例#13
0
 def test_evaluate_permuted_schedule(self):
     self.assemble_scene_table('Step flesh is weak\n')
     scenario = self.table_scene.steps[0].steps[0]
     matcher = RegexpStepMatcher(self).add_matcher(
         MethodNameStepMatcher(self))
     visitor = TestVisitor(self, matcher, NullFormatter())
     global crunks, zones
     crunks = []
     zones = []
     scenario.row_indices = [1, 0, 2]
     scenario.accept(visitor)
     self.assertEqual('hotel', visitor._suite.got_party_zone)
     self.assertEqual('jail', visitor._suite.got_crunk)
示例#14
0
 def test_should_return_suggested_method(self):
     """ Scenariusz: suggest """
     # Arrange
     obj = RegexpStepMatcher(sentinel.suite)
     # Act
     pattern = u'    def step_%(method_name)s(self%(args)s):\n        %(docstring)s\n\n        raise NotImplementedError(\'%(predicate)s\')\n\n'
     test_data = [
         ('tastes great', 'tastes_great', r"r'tastes great'", ''),
         ('less filling', 'less_filling', r"r'less filling'", ''),
         ('line\nfeed', 'line_feed', r"r'line\nfeed'", ''),
         ('tick\'ed\'', 'tick_ed', r"r'tick\'ed\''", ''),
         ('tastes   great', 'tastes_great', r"r'tastes\s+great'", ''),
         ('argu<ment>al', 'argu_ment_al', r"r'argu(.+)al'", ', ment'),
         ('arg<u>ment<al>', 'arg_u_ment_al', r"r'arg(.+)ment(.+)'",
          ', u, al'),
         ('str"ing"', 'str_ing', 'r\'str"([^"]+)"\'', ', ing'),
         ('"str"i"ngs"', 'str_i_ngs', 'r\'"([^"]+)"i"([^"]+)"\'',
          ', str, ngs'),
         ('enter "10" into', 'enter_number_into',
          'r\'enter "([^"]+)" into\'', ', number'),
         ('enter "10" and "20" into', 'enter_number_and_number_into',
          'r\'enter "([^"]+)" and "([^"]+)" into\'', ', number1, number2'),
         ('''some'quote' and "double quote"''',
          'some_quote_and_double_quote',
          'r\'some\\\'quote\\\' and "([^"]+)"\'', ', double_quote'),
     ]
     for predicate, method, docstring, args in test_data:
         suggest, suggest_method, suggest_docstring = obj.suggest(predicate)
         # Assert
         expected = pattern % {
             'method_name': method,
             'docstring': docstring,
             'args': args,
             'predicate': predicate.replace("'", r"\'"),
         }
         self.assertEqual(suggest, expected)
         self.assertEqual(suggest_method, method)
         self.assertEqual(suggest_docstring, docstring)
示例#15
0
 def _get_default_machers(self):
     docstring_matcher = RegexpStepMatcher(self)
     method_name_matcher = MethodNameStepMatcher(self)
     docstring_matcher.add_matcher(method_name_matcher)
     return docstring_matcher
示例#16
0
 def _get_default_machers(self):
     docstring_matcher = RegexpStepMatcher(self)
     method_name_matcher = MethodNameStepMatcher(self)
     docstring_matcher.add_matcher(method_name_matcher)
     return docstring_matcher