Esempio n. 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)
Esempio n. 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, ())
Esempio n. 3
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
Esempio n. 4
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 == ()
Esempio n. 5
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'})
Esempio n. 6
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")
Esempio n. 7
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 == ()
Esempio n. 8
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"}
Esempio n. 9
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'))