예제 #1
0
파일: cache.py 프로젝트: s1shed/dnuos
def test():
    """Verify caching functionality"""

    old =  sys.stderr, sys.stdout
    tmpdir = tempfile.mkdtemp()
    cache_file = dnuos.appdata.user_data_file('dirs', tmpdir)
    argv = ['dnuos', '-q', '--cache-dir=' + tmpdir, os.environ['DATA_DIR']]
    try:
        output = StringIO()
        sys.stderr = sys.stdout = output
        try:
            dnuos.main(argv=argv, locale='C')
        finally:
            sys.stderr, sys.stdout = old
        cache = dnuos.setup_cache(cache_file)
        assert cache.version == dnuos.audiodir.Dir.__version__
        for path, adir in cache.iteritems():
            assert dnuos.path.isdir(path)
            adir2 = dnuos.audiodir.Dir(path)
            assert adir.albums == adir2.albums
            assert adir.artists == adir2.artists
            assert adir._audio_files == adir2._audio_files
            assert adir._bad_files == adir2._bad_files
            assert adir._bitrates == adir2._bitrates
            assert adir._lengths == adir2._lengths
            assert adir._types == adir2._types
            m1 = datetime.fromtimestamp(adir.modified).strftime('%x')
            m2 = datetime.fromtimestamp(adir2.modified).strftime('%x')
            assert m1 == m2
            assert adir.path == adir2.path
            assert adir._profiles == adir2._profiles
            assert adir.sizes == adir2.sizes
            assert adir._vendors == adir2._vendors
    finally:
        shutil.rmtree(tmpdir, True)
예제 #2
0
파일: functest.py 프로젝트: shenal/dotfiles
def write_dnuos_diff(args, expected, no_glob=False):
    """Compares an expected result with dnuos output on given parameters"""

    old = sys.stderr, sys.stdout
    old_cwd = os.getcwd()
    os.chdir(os.environ['DATA_DIR'])
    try:
        output = StringIO()
        argv = ['dnuos', '--disable-cache'] + process_args(args, no_glob)
        sys.stderr = sys.stdout = output
        try:
            try:
                dnuos.main(argv, locale='C')
            except SystemExit:
                pass
        finally:
            sys.stderr, sys.stdout = old
        output = output.getvalue()
        try:
            assert output == expected
        except AssertionError:
            sys.stdout.write(get_unified_diff(expected, output))
    finally:
        os.chdir(old_cwd)
예제 #3
0
def write_dnuos_diff(args, expected, no_glob=False):
    """Compares an expected result with dnuos output on given parameters"""

    old = sys.stderr, sys.stdout
    old_cwd = os.getcwd()
    os.chdir(os.environ['DATA_DIR'])
    try:
        output = StringIO()
        argv = ['dnuos', '--disable-cache'] + process_args(args, no_glob)
        sys.stderr = sys.stdout = output
        try:
            try:
                dnuos.main(argv, locale='C')
            except SystemExit:
                pass
        finally:
            sys.stderr, sys.stdout = old
        output = output.getvalue()
        try:
            assert output == expected
        except AssertionError:
            sys.stdout.write(get_unified_diff(expected, output))
    finally:
        os.chdir(old_cwd)