Ejemplo n.º 1
0
def test_delete(conn, tmp_path):
    a = tmp_path / 'a'
    b = a / 'b'
    c = a / 'c'
    d = a / 'd'
    for p in [a, b, c, d]:
        p.mkdir()
    scan(tmp_path, conn)
    q = sa.select([sa.func.count()]).select_from(model.paths)
    r = conn.execute(q).scalar()
    assert r == count_files(tmp_path)

    # Remove a file and scan it
    b.rmdir()
    scan(tmp_path, conn)
    q = sa.select([sa.func.count()]).select_from(model.paths)
    r = conn.execute(q).scalar()
    assert r == count_files(tmp_path)

    # Remove a file and don't scan it - doesn't update DB
    d.rmdir()
    scan(c, conn)
    q = sa.select([sa.func.count()]).select_from(model.paths)
    r = conn.execute(q).scalar()
    assert r != count_files(tmp_path)
Ejemplo n.º 2
0
def test_exclude(conn, sample_data, sample_db):
    # Find all files except those under 'a/c'
    q = find(conn, path=sample_data, exclude='c')
    results = [r.path for r in conn.execute(q)]
    assert 'a/c' not in results
    assert 'a/c/d/e' not in results
    assert len(results) == count_files(sample_data) - \
        count_files(sample_data / 'a' / 'c')
Ejemplo n.º 3
0
def test_scan_twice(conn, sample_db, sample_data):
    # Scanning the same directory twice should not change data
    q = sa.select([model.paths.c.id])
    r = conn.execute(q)
    assert len(list(r)) == count_files(sample_data)

    scan(sample_data, conn)

    q = sa.select([model.paths.c.id])
    r = conn.execute(q)
    assert len(list(r)) == count_files(sample_data)
Ejemplo n.º 4
0
def test_paths_count(conn, sample_db, sample_data):
    # There should be a paths and paths_fullpath row for each file
    q = sa.select([sa.func.count()]).select_from(model.paths)
    r = conn.execute(q).scalar()

    assert r == count_files(sample_data)

    q = sa.select([sa.func.count()]).select_from(model.paths_fullpath)
    r = conn.execute(q).scalar()

    assert r == count_files(sample_data)
Ejemplo n.º 5
0
def test_find_subtree(conn, sample_data, sample_db):
    # Find all files under 'a/c'
    q = find(path=sample_data / 'a' / 'c', connection=conn)
    results = [r.path for r in conn.execute(q)]
    assert str(sample_data / 'a/c/d/e') in results
    assert str(sample_data / 'a/b/f') not in results
    assert len(results) == count_files(sample_data / 'a' / 'c')
Ejemplo n.º 6
0
def test_find_all(conn, sample_db, sample_data):
    # Find all files in the DB
    q = find(path=None, connection=conn)
    results = conn.execute(q)

    paths = [r.path for r in results]

    assert len(paths) == count_files(sample_data)
Ejemplo n.º 7
0
def test_non_utf(conn, tmp_path):
    a = str(tmp_path / '\ud83d').encode('utf-8', 'surrogatepass')
    os.mkdir(a)

    scan(tmp_path, conn)

    q = sa.select([sa.func.count()]).select_from(model.paths)
    r = conn.execute(q).scalar()
    assert r == count_files(tmp_path)
Ejemplo n.º 8
0
def test_scan_sample(conn, sample_db, sample_data):
    # Check the scanned sample data
    q = sa.select([model.paths.c.inode])
    r = conn.execute(q)

    # Note the root path is not included in the scan
    assert len(list(r)) == count_files(sample_data)

    q = sa.select([model.paths.c.last_seen])
    for r in conn.execute(q):
        assert r.last_seen is not None