Ejemplo n.º 1
0
def test_find_missing_reqs(monkeypatch):
    imported_modules = dict(spam=common.FoundModule('spam',
                                                    'site-spam/spam.py',
                                                    [('ham.py', 1)]),
                            shrub=common.FoundModule('shrub',
                                                     'site-spam/shrub.py',
                                                     [('ham.py', 3)]),
                            ignore=common.FoundModule('ignore', 'ignore.py',
                                                      [('ham.py', 2)]))
    monkeypatch.setattr(common, 'find_imported_modules',
                        pretend.call_recorder(lambda a: imported_modules))

    FakeDist = collections.namedtuple('FakeDist', ['project_name'])
    installed_distributions = map(FakeDist, ['spam', 'pass'])
    monkeypatch.setattr(find_missing_reqs, 'get_installed_distributions',
                        pretend.call_recorder(lambda: installed_distributions))
    packages_info = [
        dict(name='spam',
             location='site-spam',
             files=['spam/__init__.py', 'spam/shrub.py']),
        dict(name='shrub', location='site-spam', files=['shrub.py']),
        dict(name='pass', location='site-spam', files=['pass.py']),
    ]

    monkeypatch.setattr(find_missing_reqs, 'search_packages_info',
                        pretend.call_recorder(lambda x: packages_info))

    FakeReq = collections.namedtuple('FakeReq', ['name'])
    requirements = [FakeReq('spam')]
    monkeypatch.setattr(
        find_missing_reqs, 'parse_requirements',
        pretend.call_recorder(lambda a, session=None: requirements))

    result = list(find_missing_reqs.find_missing_reqs(None))
    assert result == [('shrub', [imported_modules['shrub']])]
 def fake_find_missing_reqs(options, requirements_filename):
     return [('missing', [
         common.FoundModule(
             'missing',
             'missing.py',
             [('location.py', 1)],
         )
     ])]
def test_find_extra_reqs(monkeypatch, tmp_path: Path):
    imported_modules = dict(spam=common.FoundModule('spam',
                                                    'site-spam/spam.py',
                                                    [('ham.py', 1)]),
                            shrub=common.FoundModule('shrub',
                                                     'site-spam/shrub.py',
                                                     [('ham.py', 3)]),
                            ignore=common.FoundModule('ignore', 'ignore.py',
                                                      [('ham.py', 2)]))
    monkeypatch.setattr(common, 'find_imported_modules',
                        pretend.call_recorder(lambda a: imported_modules))

    FakeDist = collections.namedtuple('FakeDist', ['project_name'])
    installed_distributions = map(FakeDist, ['spam', 'pass'])
    monkeypatch.setattr(find_extra_reqs, 'get_installed_distributions',
                        pretend.call_recorder(lambda: installed_distributions))
    packages_info = [
        dict(name='spam',
             location='site-spam',
             files=['spam/__init__.py', 'spam/shrub.py']),
        dict(name='shrub', location='site-spam', files=['shrub.py']),
        dict(name='pass', location='site-spam', files=['pass.py']),
    ]

    monkeypatch.setattr(find_extra_reqs, 'search_packages_info',
                        pretend.call_recorder(lambda x: packages_info))

    fake_requirements_file = tmp_path / 'prod_requirements.txt'
    fake_requirements_file.write_text('foobar==1')

    class options:
        def ignore_reqs(x, y):
            return False

        def requirements_filename():
            return "prod_requirements.txt"

    options = options()

    result = find_extra_reqs.find_extra_reqs(
        options=options,
        requirements_filename=str(fake_requirements_file),
    )
    assert result == ['foobar']
Ejemplo n.º 4
0
def test_main_failure(monkeypatch, caplog, fake_opts):
    monkeypatch.setattr(optparse, 'OptionParser', fake_opts)

    caplog.set_level(logging.WARN)

    monkeypatch.setattr(
        find_missing_reqs, 'find_missing_reqs', lambda x: [('missing', [
            common.FoundModule('missing', 'missing.py', [('location.py', 1)])
        ])])

    with pytest.raises(SystemExit) as excinfo:
        find_missing_reqs.main()
        assert excinfo.value == 1

    assert caplog.records[0].message == \
        'Missing requirements:'
    assert caplog.records[1].message == \
        'location.py:1 dist=missing module=missing'
Ejemplo n.º 5
0
def test_FoundModule():
    fm = common.FoundModule('spam', 'ham')
    assert fm.modname == 'spam'
    assert fm.filename == os.path.realpath('ham')
    assert fm.locations == []
    assert str(fm) == 'FoundModule("spam")'