Exemple #1
0
 def test_should_not_split_letters_in_an_abbreviation(
         self, class_name, expected, patterns):
     formatted = formatters.format_class_name(class_name, patterns)
     assert formatted == expected
Exemple #2
0
 def test_should_add_spaces_before_upercased_letters(self, patterns):
     formatted = formatters.format_class_name('AThingBuilder', patterns)
     assert formatted == 'A Thing Builder'
Exemple #3
0
 def test_should_remove_test_pattern(self, patterns):
     assert formatters.format_class_name('TestAThing',
                                         patterns) == ('A Thing')
     assert formatters.format_class_name('AThingTest',
                                         patterns) == ('A Thing Test')
Exemple #4
0
class TestNode:
    def test_parse_should_return_a_node_instance(self, pattern_config):
        nodeid = 'tests/test_module.py::test_title'
        node = Node.parse(nodeid, pattern_config)

        assert isinstance(node, Node)

    def test_parse_should_parse_node_id_attributes(self, pattern_config):
        nodeid = 'tests/test_module.py::test_title'
        node = Node.parse(nodeid, pattern_config)

        assert node.title == formatters.format_title('test_title',
                                                     pattern_config.functions)
        assert node.module_name == (formatters.format_module_name(
            'tests/test_module.py', pattern_config.files))

    @pytest.mark.parametrize(('attribute,value'), (
        ('title', ' new title '),
        ('class_name', ' new class name '),
    ))
    def test_parse_should_use_overridden_attribute_instead_of_parse_node_id(
            self, attribute, value, pattern_config):
        nodeid = 'tests/test_module.py::test_title'

        node = Node.parse(nodeid, pattern_config, **{attribute: value})

        result = getattr(node, attribute)

        assert result == formatters.format_multi_line_text(value)

    @pytest.mark.parametrize(
        'nodeid,class_name',
        (('tests/test_module.py::test_title', None),
         ('tests/test_module.py::TestClassName::()::test_title',
          formatters.format_class_name('TestClassName', ['Test*'])),
         ('tests/test_module.py::TestClassName::test_title',
          formatters.format_class_name('TestClassName', ['Test*']))))
    def test_parse_with_class_name(self, pattern_config, nodeid, class_name):
        node = Node.parse(nodeid, pattern_config)

        assert node.class_name == class_name

    def test_repr_should_return_a_string_representation_of_itself(self, node):
        from_repr = eval(repr(node))

        assert from_repr.title == node.title
        assert from_repr.class_name == node.class_name
        assert from_repr.module_name == node.module_name

    def test_should_be_equal_when_objects_have_the_same_attributes(self, node):
        other = Node(title=node.title,
                     class_name=node.class_name,
                     module_name=node.module_name)

        assert node == other

    def test_should_not_be_equal_when_it_is_not_the_same_class(self, node):
        other = mock.Mock(title=node.title,
                          class_name=node.class_name,
                          module_name=node.module_name)

        assert node != other