Exemplo n.º 1
0
 def test_singleFile(self):
     """
     If the directory contains one Python file, C{iterSourceCode} will find
     it.
     """
     childpath = self.makeEmptyFile('foo.py')
     self.assertEqual(list(iterSourceCode([self.tempdir])), [childpath])
Exemplo n.º 2
0
 def test_explicitFiles(self):
     """
     If one of the paths given to L{iterSourceCode} is not a directory but
     a file, it will include that in its output.
     """
     epath = self.makeEmptyFile("e.py")
     self.assertEqual(list(iterSourceCode([epath])), [epath])
Exemplo n.º 3
0
    def test_shebang(self):
        """
        Find Python files that don't end with `.py`, but contain a Python
        shebang.
        """
        python = os.path.join(self.tempdir, 'a')
        with open(python, 'w') as fd:
            fd.write('#!/usr/bin/env python\n')

        self.makeEmptyFile('b')

        with open(os.path.join(self.tempdir, 'c'), 'w') as fd:
            fd.write('hello\nworld\n')

        python2 = os.path.join(self.tempdir, 'd')
        with open(python2, 'w') as fd:
            fd.write('#!/usr/bin/env python2\n')

        python3 = os.path.join(self.tempdir, 'e')
        with open(python3, 'w') as fd:
            fd.write('#!/usr/bin/env python3\n')

        pythonw = os.path.join(self.tempdir, 'f')
        with open(pythonw, 'w') as fd:
            fd.write('#!/usr/bin/env pythonw\n')

        self.assertEqual(
            sorted(iterSourceCode([self.tempdir])),
            sorted([python, python2, python3, pythonw]))
Exemplo n.º 4
0
def _check_recursive(paths, reporter):
    """
    The builtin recursive checker tries to check .pyc files.
    """
    num_warnings = 0
    for path in api.iterSourceCode(paths):
        if path.endswith('.py'):
            num_warnings += api.checkPath(path, reporter)
    return num_warnings
Exemplo n.º 5
0
    def run(self):
        reporter = ProspectorReporter(ignore=self.ignore_codes)

        for filepath in iterSourceCode(self._paths):
            if any([ip.search(filepath) for ip in self._ignores]):
                continue

            checkPath(filepath, reporter)

        return reporter.get_messages()
Exemplo n.º 6
0
 def test_recurses(self):
     """
     If the Python files are hidden deep down in child directories, we will
     find them.
     """
     os.mkdir(os.path.join(self.tempdir, "foo"))
     apath = self.makeEmptyFile("foo", "a.py")
     os.mkdir(os.path.join(self.tempdir, "bar"))
     bpath = self.makeEmptyFile("bar", "b.py")
     cpath = self.makeEmptyFile("c.py")
     self.assertEqual(sorted(iterSourceCode([self.tempdir])), sorted([apath, bpath, cpath]))
Exemplo n.º 7
0
 def test_multipleDirectories(self):
     """
     L{iterSourceCode} can be given multiple directories.  It will recurse
     into each of them.
     """
     foopath = os.path.join(self.tempdir, "foo")
     barpath = os.path.join(self.tempdir, "bar")
     os.mkdir(foopath)
     apath = self.makeEmptyFile("foo", "a.py")
     os.mkdir(barpath)
     bpath = self.makeEmptyFile("bar", "b.py")
     self.assertEqual(sorted(iterSourceCode([foopath, barpath])), sorted([apath, bpath]))
Exemplo n.º 8
0
 def test_recurses(self):
     """
     If the Python files are hidden deep down in child directories, we will
     find them.
     """
     os.mkdir(os.path.join(self.tempdir, 'foo'))
     apath = self.makeEmptyFile('foo', 'a.py')
     os.mkdir(os.path.join(self.tempdir, 'bar'))
     bpath = self.makeEmptyFile('bar', 'b.py')
     cpath = self.makeEmptyFile('c.py')
     self.assertEqual(
         sorted(iterSourceCode([self.tempdir])),
         sorted([apath, bpath, cpath]))
Exemplo n.º 9
0
 def test_emptyDirectory(self):
     """
     There are no Python files in an empty directory.
     """
     self.assertEqual(list(iterSourceCode([self.tempdir])), [])
Exemplo n.º 10
0
 def test_onlyPythonSource(self):
     """
     Files that are not Python source files are not included.
     """
     self.makeEmptyFile('foo.pyc')
     self.assertEqual(list(iterSourceCode([self.tempdir])), [])
Exemplo n.º 11
0
"""