예제 #1
0
def test_main(mocker):
    mocker.patch('ldap2pg.script.logging.config.dictConfig', autospec=True)
    mocker.patch('ldap2pg.script.wrapped_main', autospec=True)

    from ldap2pg.script import main

    with pytest.raises(SystemExit) as ei:
        main()

    assert 0 == ei.value.code
예제 #2
0
def test_main(mocker):
    mocker.patch('ldap2pg.script.Configuration')
    s = mocker.patch('ldap2pg.script.synchronize', autospec=True)
    s.return_value = 0

    from ldap2pg.script import main

    with pytest.raises(SystemExit) as ei:
        main()

    assert 0 == ei.value.code
예제 #3
0
def test_user_error(mocker):
    mocker.patch('ldap2pg.script.Configuration')
    s = mocker.patch('ldap2pg.script.synchronize')

    from ldap2pg.script import main, UserError

    s.side_effect = UserError("Test message.", exit_code=0xCAFE)

    with pytest.raises(SystemExit) as ei:
        main()

    assert 0xCAFE == ei.value.code
예제 #4
0
def test_unhandled_error(mocker):
    mocker.patch('ldap2pg.script.Configuration')
    s = mocker.patch('ldap2pg.script.synchronize')

    from ldap2pg.script import main

    s.side_effect = Exception()

    with pytest.raises(SystemExit) as ei:
        main()

    assert os.EX_SOFTWARE == ei.value.code
예제 #5
0
def test_bdb_quit(mocker):
    mocker.patch('ldap2pg.script.Configuration')
    s = mocker.patch('ldap2pg.script.synchronize')

    from ldap2pg.script import main, pdb

    s.side_effect = pdb.bdb.BdbQuit()

    with pytest.raises(SystemExit) as ei:
        main()

    assert os.EX_SOFTWARE == ei.value.code
예제 #6
0
def test_user_error(mocker):
    mocker.patch('ldap2pg.script.logging.config.dictConfig', autospec=True)
    w = mocker.patch('ldap2pg.script.wrapped_main')

    from ldap2pg.script import main, UserError

    w.side_effect = UserError("Test message.", exit_code=0xCAFE)

    with pytest.raises(SystemExit) as ei:
        main()

    assert 0xCAFE == ei.value.code
예제 #7
0
def test_unhandled_error(mocker):
    mocker.patch('ldap2pg.script.logging.config.dictConfig', autospec=True)
    w = mocker.patch('ldap2pg.script.wrapped_main')

    from ldap2pg.script import main

    w.side_effect = Exception()

    with pytest.raises(SystemExit) as ei:
        main()

    assert os.EX_SOFTWARE == ei.value.code
예제 #8
0
def test_bdb_quit(mocker):
    mocker.patch('ldap2pg.script.logging.config.dictConfig', autospec=True)
    w = mocker.patch('ldap2pg.script.wrapped_main')

    from ldap2pg.script import main, pdb

    w.side_effect = pdb.bdb.BdbQuit()

    with pytest.raises(SystemExit) as ei:
        main()

    assert os.EX_SOFTWARE == ei.value.code
예제 #9
0
def test_pdb(mocker):
    mocker.patch('ldap2pg.script.Configuration')
    mocker.patch('ldap2pg.script.os.environ', {'DEBUG': '1'})
    isatty = mocker.patch('ldap2pg.script.sys.stdout.isatty')
    isatty.return_value = True
    s = mocker.patch('ldap2pg.script.synchronize')
    s.side_effect = Exception()
    pm = mocker.patch('ldap2pg.script.pdb.post_mortem')

    from ldap2pg.script import main

    with pytest.raises(SystemExit) as ei:
        main()

    assert pm.called is True
    assert os.EX_SOFTWARE == ei.value.code
예제 #10
0
def test_pdb(mocker):
    mocker.patch('ldap2pg.script.logging.config.dictConfig', autospec=True)
    mocker.patch('ldap2pg.script.os.environ', {'DEBUG': '1'})
    isatty = mocker.patch('ldap2pg.script.sys.stdout.isatty')
    isatty.return_value = True
    w = mocker.patch('ldap2pg.script.wrapped_main')
    w.side_effect = Exception()
    pm = mocker.patch('ldap2pg.script.pdb.post_mortem')

    from ldap2pg.script import main

    with pytest.raises(SystemExit) as ei:
        main()

    assert pm.called is True
    assert os.EX_SOFTWARE == ei.value.code