예제 #1
0
def test_main(monkeypatch, config, errmsg):
    """Check that the arg parsing all works."""
    c = [False]

    def set_clear(*a):
        """Remember that clear was run."""
        c[0] = True

    def my_expanduser(path):
        if path == '~/.wallsrc':
            return config
        return path

    monkeypatch.setattr('os.path.expanduser', my_expanduser)
    monkeypatch.setattr('flickrapi.FlickrAPI.walk', lambda self, **kw: [])
    monkeypatch.setattr('walls.clear_dir', set_clear)

    with errmsg('No matching photos found.\n'):
        walls.main(['walls'])
    assert not c[0]

    for args in [['-c'], ['--clear'], ['-c', config], [config, '-c'],
                 ['--clear', config], [config, '--clear']]:
        with errmsg('No matching photos found.\n'):
            walls.main(['walls'] + args)
        assert c[0]
        # Reset clear
        c[0] = False
예제 #2
0
def test_default_config(config, monkeypatch):
    """Override expanduser to point to our temporary config file."""
    def my_expanduser(path):
        if path == '~/.wallsrc':
            return config
        return path
    monkeypatch.setattr('os.path.expanduser', my_expanduser)
    monkeypatch.setattr('walls.run', lambda *a: None)
    walls.main(['walls'])
예제 #3
0
def test_usage(errmsg):
    """Make sure we print out the usage if the arguments are invalid."""
    with errmsg('Usage: walls [-c] [config_file]\n'):
        walls.main(['walls', 'config_file', 'blah'])