コード例 #1
0
def test_main_failure(monkeypatch, caplog, fake_opts):
    monkeypatch.setattr(optparse, 'OptionParser', fake_opts)

    caplog.set_level(logging.WARN)

    def fake_find_missing_reqs(options, requirements_filename):
        return [('missing', [
            common.FoundModule(
                'missing',
                'missing.py',
                [('location.py', 1)],
            )
        ])]

    monkeypatch.setattr(
        find_missing_reqs,
        'find_missing_reqs',
        fake_find_missing_reqs,
    )

    with pytest.raises(SystemExit) as excinfo:
        find_missing_reqs.main()

    assert excinfo.value.code == 1

    assert caplog.records[0].message == \
        'Missing requirements:'
    assert caplog.records[1].message == \
        'location.py:1 dist=missing module=missing'
コード例 #2
0
def test_main_version(monkeypatch, caplog, fake_opts):
    fake_opts.options.version = True
    monkeypatch.setattr(optparse, 'OptionParser', fake_opts)

    with pytest.raises(SystemExit) as excinfo:
        find_missing_reqs.main()
        assert excinfo.value == 'version'
コード例 #3
0
def test_main_version(monkeypatch, caplog, fake_opts):
    fake_opts.options.version = True
    monkeypatch.setattr(optparse, "OptionParser", fake_opts)

    with pytest.raises(SystemExit) as excinfo:
        find_missing_reqs.main()
        assert excinfo.value == "version"
コード例 #4
0
def test_logging_config(monkeypatch, caplog, verbose_cfg, debug_cfg, result):
    class options:
        paths = ["dummy"]
        verbose = verbose_cfg
        debug = debug_cfg
        version = False
        ignore_files = []
        ignore_mods = []

    options = options()

    class FakeOptParse:
        def __init__(self, usage):
            pass

        def add_option(*args, **kw):
            pass

        def parse_args(self):
            return (options, ["ham.py"])

    monkeypatch.setattr(optparse, "OptionParser", FakeOptParse)

    monkeypatch.setattr(find_missing_reqs, "find_missing_reqs", lambda x: [])
    find_missing_reqs.main()

    for event in [(logging.DEBUG, "debug"), (logging.INFO, "info"), (logging.WARN, "warn")]:
        find_missing_reqs.log.log(*event)

    messages = [r.message for r in caplog.records()]
    # first message is always the usage message
    if verbose_cfg or debug_cfg:
        assert messages[1:] == result
    else:
        assert messages == result
コード例 #5
0
def test_main_no_spec(monkeypatch, caplog, fake_opts):
    fake_opts.args = []
    monkeypatch.setattr(optparse, "OptionParser", fake_opts)
    monkeypatch.setattr(fake_opts, "error", pretend.call_recorder(lambda s, e: None), raising=False)

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

    assert fake_opts.error.calls
コード例 #6
0
def test_pip_compatibility(tmpdir, monkeypatch):
    with open(os.path.join(tmpdir, "requirements.txt"), "w") as ff:
        ff.write("pytest\n")

    with open(os.path.join(tmpdir, "sample.py"), "w") as ff:
        ff.write("import pytest\n")

    monkeypatch.chdir(str(tmpdir))
    monkeypatch.setattr(sys, "argv", ["a", "."])
    find_missing_reqs.main()
コード例 #7
0
def test_main_no_spec(monkeypatch, caplog, fake_opts):
    fake_opts.args = []
    monkeypatch.setattr(optparse, 'OptionParser', fake_opts)
    monkeypatch.setattr(fake_opts,
                        'error',
                        pretend.call_recorder(lambda s, e: None),
                        raising=False)

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

    assert fake_opts.error.calls
コード例 #8
0
def test_main_failure(monkeypatch, caplog, fake_opts):
    monkeypatch.setattr(optparse, "OptionParser", fake_opts)

    caplog.setLevel(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"
コード例 #9
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'
コード例 #10
0
def test_logging_config(monkeypatch, caplog, verbose_cfg, debug_cfg, result):
    class options:
        paths = ['dummy']
        verbose = verbose_cfg
        debug = debug_cfg
        version = False
        ignore_files = []
        ignore_mods = []
        requirements_filename = "prod_requirements.txt.txt"

    options = options()

    class FakeOptParse:
        def __init__(self, usage):
            pass

        def add_option(*args, **kw):
            pass

        def parse_args(self):
            return (options, ['ham.py'])

    monkeypatch.setattr(optparse, 'OptionParser', FakeOptParse)

    monkeypatch.setattr(
        find_missing_reqs,
        'find_missing_reqs',
        lambda options, requirements_filename: [],
    )
    find_missing_reqs.main()

    for event in [(logging.DEBUG, 'debug'), (logging.INFO, 'info'),
                  (logging.WARN, 'warn')]:
        find_missing_reqs.log.log(*event)

    messages = [r.message for r in caplog.records]
    # first message is always the usage message
    if verbose_cfg or debug_cfg:
        assert messages[1:] == result
    else:
        assert messages == result