Пример #1
0
    def test_module_with_valid_header_for_init_module(self):
        module = ast.parse('''\
"""
====
spam
====
"""\
        ''')
        checker = FancyHeaderChecker(tree=module, filename='spam/__init__.py')
        self.assertEqual(len(list(checker.run())), 0)
Пример #2
0
    def test_valid_header_in_submodule(self):
        module = ast.parse('''\
"""
========
foo.spam
========
"""\
        ''')
        checker = FancyHeaderChecker(tree=module, filename='foo/spam.py')
        self.assertEqual(len(list(checker.run())), 0)
Пример #3
0
    def test_module_with_invalid_header(self):
        module = ast.parse('''\
"""
===
foo
===
"""\
        ''')
        checker = FancyHeaderChecker(tree=module, filename='spam.py')
        self.assertEqual(len(list(checker.run())), 1)
Пример #4
0
    def test_module_with_valid_header_and_leading_comment(self):
        module = ast.parse('''\
# coding: utf8
"""
====
spam
====
"""\
        ''')
        checker = FancyHeaderChecker(tree=module, filename='spam.py')
        self.assertEqual(len(list(checker.run())), 0)
Пример #5
0
    def test_module_with_valid_header_2(self):
        module = ast.parse('''\
"""
====
spam
====

Some more text after the header.
"""
        ''')
        checker = FancyHeaderChecker(tree=module, filename='spam.py')
        self.assertEqual(len(list(checker.run())), 0)
Пример #6
0
    def test_checker_with_absolute_filename_and_submodule(self):
        module = ast.parse('''\
"""
============
package.spam
============
"""\
        ''')
        checker = FancyHeaderChecker(
            tree=module,
            filename='/home/User/Project/package/spam.py',
        )
        self.assertEqual(len(list(checker.run())), 0)
Пример #7
0
    def test_module_with_relative_filename(self):
        module = ast.parse('''\
"""
====
spam
====
"""\
        ''')
        checker = FancyHeaderChecker(
            tree=module,
            filename='./spam.py',
        )
        self.assertEqual(len(list(checker.run())), 0)
Пример #8
0
    def test_checker_not_from_project_root(self, getcwd, exists):
        getcwd.return_value = '/home/User/Project/package/subpackage'
        # Pretend that project root marker was found in /home/User/Project
        exists.side_effect = lambda path: dirname(path) == '/home/User/Project'
        module = ast.parse('''\
"""
=========================
package.subpackage.module
=========================
"""
        ''')
        checker = FancyHeaderChecker(
            tree=module,
            filename='module.py',
        )
        self.assertEqual(len(list(checker.run())), 0)
Пример #9
0
    def test_empty_module(self):
        module = ast.parse('')
        checker = FancyHeaderChecker(tree=module, filename='spam.py')
        self.assertEqual(len(list(checker.run())), 0)

        module = ast.parse('\n\n\n')
        checker = FancyHeaderChecker(tree=module, filename='spam.py')
        self.assertEqual(len(list(checker.run())), 0)
Пример #10
0
 def test_module_without_docstring(self):
     module = ast.parse('class C: pass')
     checker = FancyHeaderChecker(tree=module, filename='spam.py')
     self.assertEqual(len(list(checker.run())), 1)