2017-10-20 18:48:26 +00:00
|
|
|
import inspect
|
2017-11-11 22:59:38 +00:00
|
|
|
|
2017-11-12 12:42:27 +00:00
|
|
|
import unittest2
|
2017-10-20 18:48:26 +00:00
|
|
|
|
2017-10-01 09:59:04 +00:00
|
|
|
import mitogen.master
|
|
|
|
|
2017-10-02 08:24:01 +00:00
|
|
|
import testlib
|
2017-10-01 09:59:04 +00:00
|
|
|
|
|
|
|
|
2017-10-02 08:24:01 +00:00
|
|
|
class ConstructorTest(testlib.TestCase):
|
|
|
|
klass = mitogen.master.ModuleFinder
|
2017-10-01 09:59:04 +00:00
|
|
|
|
|
|
|
def test_simple(self):
|
2017-10-02 08:24:01 +00:00
|
|
|
self.klass()
|
|
|
|
|
|
|
|
|
|
|
|
class ReprTest(testlib.TestCase):
|
|
|
|
klass = mitogen.master.ModuleFinder
|
|
|
|
|
|
|
|
def test_simple(self):
|
|
|
|
self.assertEquals('ModuleFinder()', repr(self.klass()))
|
|
|
|
|
|
|
|
|
|
|
|
class IsStdlibNameTest(testlib.TestCase):
|
|
|
|
klass = mitogen.master.ModuleFinder
|
|
|
|
|
|
|
|
def call(self, fullname):
|
|
|
|
return self.klass().is_stdlib_name(fullname)
|
|
|
|
|
|
|
|
def test_builtin(self):
|
|
|
|
import sys
|
|
|
|
self.assertTrue(self.call('sys'))
|
|
|
|
|
|
|
|
def test_stdlib_1(self):
|
|
|
|
import logging
|
|
|
|
self.assertTrue(self.call('logging'))
|
|
|
|
|
|
|
|
def test_stdlib_2(self):
|
|
|
|
# virtualenv only symlinks some paths to its local site-packages
|
|
|
|
# directory. Ensure both halves of the search path return the correct
|
|
|
|
# result.
|
|
|
|
import email
|
|
|
|
self.assertTrue(self.call('email'))
|
|
|
|
|
|
|
|
def test_mitogen_core(self):
|
|
|
|
import mitogen.core
|
|
|
|
self.assertFalse(self.call('mitogen.core'))
|
|
|
|
|
|
|
|
def test_mitogen_fakessh(self):
|
|
|
|
import mitogen.fakessh
|
|
|
|
self.assertFalse(self.call('mitogen.fakessh'))
|
|
|
|
|
|
|
|
|
|
|
|
class GetModuleViaPkgutilTest(testlib.TestCase):
|
|
|
|
klass = mitogen.master.ModuleFinder
|
|
|
|
|
|
|
|
def call(self, fullname):
|
|
|
|
return self.klass()._get_module_via_pkgutil(fullname)
|
|
|
|
|
|
|
|
def test_empty_source_pkg(self):
|
|
|
|
path, src, is_pkg = self.call('module_finder_testmod')
|
|
|
|
self.assertEquals(path,
|
|
|
|
testlib.data_path('module_finder_testmod/__init__.py'))
|
|
|
|
self.assertEquals('', src)
|
|
|
|
self.assertTrue(is_pkg)
|
|
|
|
|
|
|
|
def test_empty_source_module(self):
|
|
|
|
path, src, is_pkg = self.call('module_finder_testmod.empty_mod')
|
|
|
|
self.assertEquals(path,
|
|
|
|
testlib.data_path('module_finder_testmod/empty_mod.py'))
|
|
|
|
self.assertEquals('', src)
|
|
|
|
self.assertFalse(is_pkg)
|
|
|
|
|
|
|
|
def test_regular_mod(self):
|
|
|
|
from module_finder_testmod import regular_mod
|
|
|
|
path, src, is_pkg = self.call('module_finder_testmod.regular_mod')
|
|
|
|
self.assertEquals(path,
|
|
|
|
testlib.data_path('module_finder_testmod/regular_mod.py'))
|
2017-10-20 18:48:26 +00:00
|
|
|
self.assertEquals(src, inspect.getsource(regular_mod))
|
2017-10-02 08:24:01 +00:00
|
|
|
self.assertFalse(is_pkg)
|
|
|
|
|
|
|
|
|
|
|
|
class GetModuleViaSysModulesTest(testlib.TestCase):
|
|
|
|
klass = mitogen.master.ModuleFinder
|
|
|
|
|
|
|
|
def call(self, fullname):
|
|
|
|
return self.klass()._get_module_via_sys_modules(fullname)
|
|
|
|
|
|
|
|
def test_main(self):
|
|
|
|
import __main__
|
|
|
|
path, src, is_pkg = self.call('__main__')
|
|
|
|
self.assertEquals(path, __main__.__file__)
|
2017-11-11 23:36:54 +00:00
|
|
|
self.assertEquals(src, open(path).read())
|
2017-10-02 08:24:01 +00:00
|
|
|
self.assertFalse(is_pkg)
|
|
|
|
|
|
|
|
def test_dylib_fails(self):
|
|
|
|
# _socket comes from a .so
|
|
|
|
import _socket
|
|
|
|
tup = self.call('_socket')
|
2017-11-11 23:08:08 +00:00
|
|
|
self.assertIsNone(tup)
|
2017-10-02 08:24:01 +00:00
|
|
|
|
|
|
|
def test_builtin_fails(self):
|
|
|
|
# sys is built-in
|
|
|
|
tup = self.call('sys')
|
2017-11-11 23:08:08 +00:00
|
|
|
self.assertIsNone(tup)
|
2017-10-02 08:24:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ResolveRelPathTest(testlib.TestCase):
|
|
|
|
klass = mitogen.master.ModuleFinder
|
|
|
|
|
|
|
|
def call(self, fullname, level):
|
|
|
|
return self.klass().resolve_relpath(fullname, level)
|
|
|
|
|
|
|
|
def test_empty(self):
|
|
|
|
self.assertEquals('', self.call('', 0))
|
|
|
|
self.assertEquals('', self.call('', 1))
|
|
|
|
self.assertEquals('', self.call('', 2))
|
|
|
|
|
|
|
|
def test_absolute(self):
|
|
|
|
self.assertEquals('', self.call('email.utils', 0))
|
|
|
|
|
|
|
|
def test_rel1(self):
|
2018-02-19 21:05:00 +00:00
|
|
|
self.assertEquals('email', self.call('email.utils', 1))
|
2017-10-02 08:24:01 +00:00
|
|
|
|
|
|
|
def test_rel2(self):
|
|
|
|
self.assertEquals('', self.call('email.utils', 2))
|
|
|
|
|
|
|
|
def test_rel_overflow(self):
|
|
|
|
self.assertEquals('', self.call('email.utils', 3))
|
|
|
|
|
|
|
|
|
2018-02-19 20:58:22 +00:00
|
|
|
class FindRelatedImportsTest(testlib.TestCase):
|
|
|
|
klass = mitogen.master.ModuleFinder
|
|
|
|
|
|
|
|
def call(self, fullname):
|
|
|
|
return self.klass().find_related_imports(fullname)
|
|
|
|
|
|
|
|
def test_simple(self):
|
|
|
|
import mitogen.fakessh
|
|
|
|
related = self.call('mitogen.fakessh')
|
|
|
|
self.assertEquals(related, [
|
|
|
|
'mitogen',
|
|
|
|
'mitogen.core',
|
|
|
|
'mitogen.master',
|
|
|
|
'mitogen.parent',
|
|
|
|
])
|
|
|
|
|
|
|
|
def test_django_pkg(self):
|
|
|
|
import django
|
|
|
|
related = self.call('django')
|
|
|
|
self.assertEquals(related, [
|
|
|
|
'django.utils.version',
|
|
|
|
])
|
|
|
|
|
|
|
|
def test_django_db(self):
|
|
|
|
import django.db
|
|
|
|
related = self.call('django.db')
|
|
|
|
self.assertEquals(related, [
|
|
|
|
'django',
|
|
|
|
'django.core',
|
|
|
|
'django.core.signals',
|
|
|
|
'django.db.utils',
|
|
|
|
])
|
|
|
|
|
|
|
|
def test_django_db_models(self):
|
|
|
|
import django.db.models
|
|
|
|
related = self.call('django.db.models')
|
|
|
|
self.maxDiff=None
|
|
|
|
self.assertEquals(related, [
|
|
|
|
'django',
|
|
|
|
'django.core.exceptions',
|
|
|
|
'django.db',
|
|
|
|
'django.db.models',
|
|
|
|
'django.db.models.aggregates',
|
|
|
|
'django.db.models.base',
|
|
|
|
'django.db.models.deletion',
|
|
|
|
'django.db.models.expressions',
|
|
|
|
'django.db.models.fields',
|
|
|
|
'django.db.models.fields.files',
|
|
|
|
'django.db.models.fields.proxy',
|
|
|
|
'django.db.models.fields.related',
|
|
|
|
'django.db.models.indexes',
|
|
|
|
'django.db.models.lookups',
|
|
|
|
'django.db.models.manager',
|
|
|
|
'django.db.models.query',
|
|
|
|
'django.db.models.signals',
|
|
|
|
])
|
|
|
|
|
|
|
|
|
2018-02-19 20:53:41 +00:00
|
|
|
class FindRelatedTest(testlib.TestCase):
|
2017-10-02 08:24:01 +00:00
|
|
|
klass = mitogen.master.ModuleFinder
|
|
|
|
|
|
|
|
def call(self, fullname):
|
2018-02-19 20:53:41 +00:00
|
|
|
return self.klass().find_related(fullname)
|
2017-10-02 08:24:01 +00:00
|
|
|
|
|
|
|
def test_simple(self):
|
|
|
|
import mitogen.fakessh
|
|
|
|
related = self.call('mitogen.fakessh')
|
|
|
|
self.assertEquals(related, [
|
|
|
|
'mitogen',
|
|
|
|
'mitogen.core',
|
|
|
|
'mitogen.master',
|
2018-02-19 21:01:04 +00:00
|
|
|
'mitogen.parent',
|
2017-10-02 08:24:01 +00:00
|
|
|
])
|
2017-10-01 09:59:04 +00:00
|
|
|
|
2018-02-10 22:37:24 +00:00
|
|
|
def test_django_pkg(self):
|
|
|
|
import django
|
|
|
|
related = self.call('django')
|
|
|
|
self.assertEquals(related, [
|
|
|
|
'django.utils',
|
|
|
|
'django.utils.lru_cache',
|
|
|
|
'django.utils.version',
|
|
|
|
])
|
|
|
|
|
|
|
|
def test_django_db(self):
|
|
|
|
import django.db
|
|
|
|
related = self.call('django.db')
|
|
|
|
self.assertEquals(related, [
|
|
|
|
'django',
|
|
|
|
'django.conf',
|
|
|
|
'django.conf.global_settings',
|
|
|
|
'django.core',
|
|
|
|
'django.core.exceptions',
|
|
|
|
'django.core.signals',
|
|
|
|
'django.db.utils',
|
|
|
|
'django.dispatch',
|
|
|
|
'django.dispatch.dispatcher',
|
|
|
|
'django.dispatch.weakref_backports',
|
|
|
|
'django.utils',
|
|
|
|
'django.utils._os',
|
|
|
|
'django.utils.deprecation',
|
|
|
|
'django.utils.encoding',
|
|
|
|
'django.utils.functional',
|
|
|
|
'django.utils.inspect',
|
|
|
|
'django.utils.lru_cache',
|
|
|
|
'django.utils.module_loading',
|
|
|
|
'django.utils.six',
|
|
|
|
'django.utils.version',
|
|
|
|
])
|
|
|
|
|
|
|
|
def test_django_db_models(self):
|
|
|
|
import django.db.models
|
2018-02-14 22:54:00 +00:00
|
|
|
related = self.call('django.db.models')
|
|
|
|
self.assertEquals(related, [
|
2018-02-10 22:37:24 +00:00
|
|
|
'django',
|
|
|
|
'django.apps',
|
2018-02-19 21:01:04 +00:00
|
|
|
'django.apps.config',
|
|
|
|
'django.apps.registry',
|
2018-02-10 22:37:24 +00:00
|
|
|
'django.conf',
|
|
|
|
'django.conf.global_settings',
|
|
|
|
'django.core',
|
|
|
|
'django.core.cache',
|
|
|
|
'django.core.cache.backends',
|
|
|
|
'django.core.cache.backends.base',
|
|
|
|
'django.core.checks',
|
|
|
|
'django.core.checks.caches',
|
|
|
|
'django.core.checks.compatibility',
|
|
|
|
'django.core.checks.compatibility.django_1_10',
|
|
|
|
'django.core.checks.compatibility.django_1_8_0',
|
|
|
|
'django.core.checks.database',
|
2018-02-19 21:01:04 +00:00
|
|
|
'django.core.checks.messages',
|
2018-02-10 22:37:24 +00:00
|
|
|
'django.core.checks.model_checks',
|
2018-02-19 21:01:04 +00:00
|
|
|
'django.core.checks.registry',
|
2018-02-10 22:37:24 +00:00
|
|
|
'django.core.checks.security',
|
|
|
|
'django.core.checks.security.base',
|
|
|
|
'django.core.checks.security.csrf',
|
|
|
|
'django.core.checks.security.sessions',
|
|
|
|
'django.core.checks.templates',
|
|
|
|
'django.core.checks.urls',
|
|
|
|
'django.core.checks.utils',
|
|
|
|
'django.core.exceptions',
|
|
|
|
'django.core.files',
|
|
|
|
'django.core.files.base',
|
|
|
|
'django.core.files.images',
|
|
|
|
'django.core.files.locks',
|
|
|
|
'django.core.files.move',
|
|
|
|
'django.core.files.storage',
|
|
|
|
'django.core.files.utils',
|
|
|
|
'django.core.signals',
|
|
|
|
'django.core.validators',
|
|
|
|
'django.db',
|
|
|
|
'django.db.backends',
|
|
|
|
'django.db.backends.utils',
|
|
|
|
'django.db.models.aggregates',
|
|
|
|
'django.db.models.base',
|
|
|
|
'django.db.models.constants',
|
|
|
|
'django.db.models.deletion',
|
|
|
|
'django.db.models.expressions',
|
|
|
|
'django.db.models.fields',
|
|
|
|
'django.db.models.fields.files',
|
|
|
|
'django.db.models.fields.proxy',
|
|
|
|
'django.db.models.fields.related',
|
|
|
|
'django.db.models.fields.related_descriptors',
|
|
|
|
'django.db.models.fields.related_lookups',
|
|
|
|
'django.db.models.fields.reverse_related',
|
|
|
|
'django.db.models.functions',
|
2018-02-19 21:01:04 +00:00
|
|
|
'django.db.models.functions.base',
|
|
|
|
'django.db.models.functions.datetime',
|
2018-02-10 22:37:24 +00:00
|
|
|
'django.db.models.indexes',
|
|
|
|
'django.db.models.lookups',
|
|
|
|
'django.db.models.manager',
|
|
|
|
'django.db.models.options',
|
|
|
|
'django.db.models.query',
|
|
|
|
'django.db.models.query_utils',
|
|
|
|
'django.db.models.signals',
|
|
|
|
'django.db.models.sql',
|
|
|
|
'django.db.models.sql.constants',
|
|
|
|
'django.db.models.sql.datastructures',
|
|
|
|
'django.db.models.sql.query',
|
|
|
|
'django.db.models.sql.subqueries',
|
|
|
|
'django.db.models.sql.where',
|
|
|
|
'django.db.models.utils',
|
|
|
|
'django.db.transaction',
|
|
|
|
'django.db.utils',
|
|
|
|
'django.dispatch',
|
|
|
|
'django.dispatch.dispatcher',
|
|
|
|
'django.dispatch.weakref_backports',
|
|
|
|
'django.forms',
|
|
|
|
'django.forms.boundfield',
|
|
|
|
'django.forms.fields',
|
|
|
|
'django.forms.forms',
|
|
|
|
'django.forms.formsets',
|
|
|
|
'django.forms.models',
|
|
|
|
'django.forms.renderers',
|
|
|
|
'django.forms.utils',
|
|
|
|
'django.forms.widgets',
|
|
|
|
'django.template',
|
|
|
|
'django.template.backends',
|
|
|
|
'django.template.backends.base',
|
|
|
|
'django.template.backends.django',
|
|
|
|
'django.template.backends.jinja2',
|
|
|
|
'django.template.base',
|
|
|
|
'django.template.context',
|
|
|
|
'django.template.engine',
|
|
|
|
'django.template.exceptions',
|
|
|
|
'django.template.library',
|
|
|
|
'django.template.loader',
|
|
|
|
'django.template.utils',
|
|
|
|
'django.templatetags',
|
|
|
|
'django.templatetags.static',
|
|
|
|
'django.utils',
|
|
|
|
'django.utils._os',
|
|
|
|
'django.utils.crypto',
|
|
|
|
'django.utils.datastructures',
|
|
|
|
'django.utils.dateformat',
|
|
|
|
'django.utils.dateparse',
|
|
|
|
'django.utils.dates',
|
|
|
|
'django.utils.datetime_safe',
|
|
|
|
'django.utils.deconstruct',
|
|
|
|
'django.utils.decorators',
|
|
|
|
'django.utils.deprecation',
|
|
|
|
'django.utils.duration',
|
|
|
|
'django.utils.encoding',
|
|
|
|
'django.utils.formats',
|
|
|
|
'django.utils.functional',
|
|
|
|
'django.utils.html',
|
|
|
|
'django.utils.html_parser',
|
|
|
|
'django.utils.http',
|
|
|
|
'django.utils.inspect',
|
|
|
|
'django.utils.ipv6',
|
|
|
|
'django.utils.itercompat',
|
|
|
|
'django.utils.lru_cache',
|
|
|
|
'django.utils.module_loading',
|
|
|
|
'django.utils.numberformat',
|
|
|
|
'django.utils.safestring',
|
|
|
|
'django.utils.six',
|
|
|
|
'django.utils.text',
|
|
|
|
'django.utils.timezone',
|
|
|
|
'django.utils.translation',
|
|
|
|
'django.utils.tree',
|
|
|
|
'django.utils.version',
|
|
|
|
'pytz',
|
|
|
|
'pytz.exceptions',
|
|
|
|
'pytz.lazy',
|
|
|
|
'pytz.tzfile',
|
|
|
|
'pytz.tzinfo',
|
|
|
|
])
|
2017-10-01 09:59:04 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2017-11-12 12:42:27 +00:00
|
|
|
unittest2.main()
|