Пример #1
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_extra_reqs.main()
        assert excinfo.value == 'version'
Пример #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_extra_reqs.main()
        assert excinfo.value == 'version'
Пример #3
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_extra_reqs.main()
        assert excinfo.value == 2

    assert fake_opts.error.calls
Пример #4
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_extra_reqs.main()
        assert excinfo.value == 2

    assert fake_opts.error.calls
Пример #5
0
def test_main_failure(monkeypatch, caplog, fake_opts):
    monkeypatch.setattr(optparse, 'OptionParser', fake_opts)

    caplog.set_level(logging.WARN)

    monkeypatch.setattr(find_extra_reqs, 'find_extra_reqs',
                        lambda x: ['extra'])

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

    assert caplog.records[0].message == \
        'Extra requirements:'
    assert caplog.records[1].message == \
        'extra in requirements.txt'
Пример #6
0
def test_main_failure(monkeypatch, caplog, fake_opts):
    monkeypatch.setattr(optparse, 'OptionParser', fake_opts)

    caplog.setLevel(logging.WARN)

    monkeypatch.setattr(find_extra_reqs, 'find_extra_reqs', lambda x: [
        'extra'
    ])

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

    assert caplog.records()[0].message == \
        'Extra requirements:'
    assert caplog.records()[1].message == \
        'extra in requirements.txt'
Пример #7
0
def test_logging_config(monkeypatch, caplog, verbose_cfg, debug_cfg, result):
    class options:
        requirements_filename = ''
        paths = ['dummy']
        verbose = verbose_cfg
        debug = debug_cfg
        version = False
        ignore_files = []
        ignore_mods = []
        ignore_reqs = []

    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_extra_reqs,
        'find_extra_reqs',
        lambda options, requirements_filename: [],
    )
    find_extra_reqs.main()

    for event in [(logging.DEBUG, 'debug'), (logging.INFO, 'info'),
                  (logging.WARN, 'warn')]:
        find_extra_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
Пример #8
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 = []
        ignore_reqs = []
    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_extra_reqs, 'find_extra_reqs', lambda x: [])
    find_extra_reqs.main()

    for event in [(logging.DEBUG, 'debug'), (logging.INFO, 'info'),
            (logging.WARN, 'warn')]:
        find_extra_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