예제 #1
0
 def test_isModule_skips_egginfo_files(self):
     egginfo = os.path.join(here, 'tests', 'sample-tree', 'snake.egg-info')
     mg = findimports.ModuleGraph()
     mg.path = [egginfo]
     mg.warn = self.warn
     mg.isModule('nosuchmodule')
     self.assertEqual(self.warnings, [])
예제 #2
0
 def test_filenameToModname(self):
     mg = findimports.ModuleGraph()
     if '.x86_64-linux-gnu.so' not in mg._exts:
         mg._exts += ('.x86_64-linux-gnu.so', )
     self.assertEqual(mg.filenameToModname('foo.py'), 'foo')
     self.assertEqual(mg.filenameToModname('foo.so'), 'foo')
     self.assertEqual(mg.filenameToModname('foo.x86_64-linux-gnu.so'),
                      'foo')
예제 #3
0
 def test_packageOf(self):
     mg = findimports.ModuleGraph()
     mg.isPackage = lambda x: x in ['pkg', 'pkg.subpkg']
     self.assertEqual(mg.packageOf('foo'), 'foo')
     self.assertEqual(mg.packageOf('pkg'), 'pkg')
     self.assertEqual(mg.packageOf('pkg.foo'), 'pkg')
     self.assertEqual(mg.packageOf('pkg.subpkg'), 'pkg.subpkg')
     self.assertEqual(mg.packageOf('pkg.subpkg.mod'), 'pkg.subpkg')
     self.assertEqual(mg.packageOf('pkg.subpkg.mod', 1), 'pkg')
예제 #4
0
 def test_isModule_warns_about_bad_zip_files(self):
     # anything that's a regular file but isn't a valid zip file
     # (oh and it shouldn't end in .egg-info)
     badzipfile = __file__
     mg = findimports.ModuleGraph()
     mg.path = [badzipfile]
     mg.warn = self.warn
     mg.isModule('nosuchmodule')
     self.assertEqual(self.warnings,
                      ['%s: not a directory or zip file' % badzipfile])
예제 #5
0
import warnings
import pytest
import findimports

parametrize = pytest.mark.parametrize

# The CLI equivalent to find the DIRAC imports is
# findimports -p --level=1 -T DIRAC/


# Use the environment variable to make it easy with pytest (it does not like cli arguments)
diracRoot = os.environ['DIRAC']
diracPath = diracRoot + "/src/DIRAC"

# Find all the packages used by DIRAC
g = findimports.ModuleGraph()
directories = next(os.walk(diracPath))[1]

for dir in directories:
  g.parsePathname('%s/%s' % (diracPath, dir))

g.parseFile('%s/%s' % (diracPath, '__init__.py'))
g.parseFile('%s/%s' % (diracRoot, 'setup.py'))

g = g.packageGraph(packagelevel=1).collapseTests()
moduleNames = set([i for m in g.listModules() for i in m.imports])

# some imports in DIRAC are fake, and are just for doc
# or formating example
# Ignore these
FAKE_MODULES = [
예제 #6
0
 def test_isModule(self):
     mg = findimports.ModuleGraph()
     self.assertTrue(mg.isModule('os'))
     self.assertTrue(mg.isModule('sys'))
     self.assertTrue(mg.isModule('datetime'))
     self.assertFalse(mg.isModule('nosuchmodule'))
예제 #7
0
 def test_filenameToModname_warns(self):
     mg = findimports.ModuleGraph()
     mg.warn = self.warn
     mg.filenameToModname('foo.xyz')
     self.assertEqual(self.warnings,
                      ['foo.xyz: unknown file name extension'])
예제 #8
0
 def test_parsePathname_regular_file(self):
     mg = findimports.ModuleGraph()
     mg.warn = self.warn
     mg.parsePathname(__file__.rstrip('co'))  # .pyc -> .py
     self.assertTrue('unittest' in mg.modules[__name__].imports)
예제 #9
0
 def test_warn_suppresses_duplicates(self):
     mg = findimports.ModuleGraph()
     mg._stderr = StringIO()
     mg.warn('foo', 'no module foo')
     mg.warn('foo', 'no module foo (again)')
     self.assertEqual(mg._stderr.getvalue(), 'no module foo\n')
예제 #10
0
 def test_warn(self):
     mg = findimports.ModuleGraph()
     mg._stderr = StringIO()
     mg.warn('foo', 'no module %s', 'foo')
     self.assertEqual(mg._stderr.getvalue(), 'no module foo\n')