def test_scan_module(data): installed = data.copy_installed() data_dir = data.copy_data() module = data_dir.join('scripts/project/nested/scripts/testmodule') pkg = filesystem_scanner.scan(str(module), installed) assert pkg in installed assert pkg.name == 'testmodule' assert pkg.version == 'MODULE' assert utils.find_package('moult', installed, True) in pkg.dependencies assert utils.find_package('testpackage', installed, True) in pkg.dependencies
def test_bad_tabs(data): installed = data.copy_installed() data_dir = data.copy_data() bad_script = data_dir.join('scripts/loose/bad_tabs.py') mpkg1 = utils.find_package('moult', installed, True) mpkg2 = utils.find_package('testpackage', installed, True) pkg = filesystem_scanner.scan(str(bad_script), installed) assert pkg is not None assert mpkg1 in pkg.dependencies assert mpkg2 in pkg.dependencies data.verify_data()
def test_unicode_scan(data): installed = data.copy_installed() data_dir = data.copy_data() unicode_script = data_dir.join('scripts/loose/unicode.py') mpkg = utils.find_package('moult', installed, True) pkg = filesystem_scanner.scan(unicode_script.strpath, installed) assert pkg is not None assert mpkg in pkg.dependencies
def test_nested_directory(data): installed = data.copy_installed() data_dir = data.copy_data() nested = str(data_dir.join('scripts/project/nested')) pkg = filesystem_scanner.scan(nested, installed) assert pkg in installed assert pkg.location == nested assert pkg.name == 'nested' assert pkg.version == 'DIRECTORY' assert not pkg.frameworks packages = ('moult', 'setuptools', 'testpackage') for p in packages: dep = utils.find_package(p, installed, True) assert dep in pkg.dependencies
def test_scan_shell_scripts(data): installed = data.copy_installed() data_dir = data.copy_data() shell_scripts = data_dir.join('scripts/shell') assert filesystem_scanner.scan(str(shell_scripts.join('bash_script')), installed) is None pkg = filesystem_scanner.scan(str(shell_scripts.join('python_script')), installed) assert pkg in installed assert pkg.version == 'SCRIPT' mpkg = utils.find_package('moult', installed, True) assert mpkg in pkg.dependencies data.verify_data()
def test_scan_django(data): installed = data.copy_installed() data_dir = data.copy_data() django_project = str(data_dir.join('scripts/project/django_project')) pkg = filesystem_scanner.scan(django_project, installed) assert pkg in installed assert pkg.location == django_project assert pkg.name == 'django_project' assert pkg.version == 'DIRECTORY' assert 'django' in pkg.frameworks packages = ('django', 'testpackage', 'django-allauth', 'django-boto', 'django-mptt', 'boto') for p in packages: dep = utils.find_package(p, installed, True) assert dep in pkg.dependencies data.verify_data()
def test_scan_all(data): installed = data.copy_installed() data_dir = data.copy_data() # Fake package that's imported from a script that shouldn't be scanned fakepkg = PyModule('fake_package', 'FAKE', '/a/fake/location') fakepkg.set_import_names(['fake_package', 'fake_package.spam']) installed.append(fakepkg) pkg = filesystem_scanner.scan(str(data_dir), installed) assert pkg.version == 'DIRECTORY' assert fakepkg not in pkg.dependencies, 'Fake package should not be a dependency' packages = ('moult', 'django', 'testpackage', 'boto', 'setuptools', 'django-boto', 'django-allauth', 'django-mptt') for p in packages: dep = utils.find_package(p, installed, True) assert isinstance(dep, PyModule) assert dep in pkg.dependencies
def test_unicode_import_scan(data, capsys): installed = data.copy_installed() data_dir = data.copy_data() unicode_script = data_dir.join('scripts/loose/unicode_import.py') name = '\xe8\x84\xb1\xe7\x9a\xae' if sys.version_info[0] == 2: name = name.decode('utf8') japanesu = PyModule(name, '1.2.3', '/') installed.insert(0, japanesu) mpkg = utils.find_package('moult', installed, True) pkg = filesystem_scanner.scan(unicode_script.strpath, installed) assert pkg is not None assert mpkg in pkg.dependencies out, err = capsys.readouterr() if sys.version_info[0] == 2: assert japanesu not in pkg.dependencies assert japanesu.name in err elif sys.version_info[0] == 3: assert japanesu in installed
def test_find_package(data): installed = data.copy_installed() pkg = utils.find_package('moult', installed, package=True) assert pkg and pkg.name == 'moult' pkg = utils.find_package('moult.utils', installed, package=True) assert pkg is None pkg = utils.find_package('does.not.exist', installed) assert pkg is None pkg = utils.find_package('moult', installed) assert pkg and pkg.name == 'moult' # Searching for module imports should only match their top level # import names pkg = utils.find_package('moult.utils.does.not.exist', installed) assert pkg is None pkg = utils.find_package('pkg_resources', installed) assert pkg and pkg.name == 'setuptools'