示例#1
0
def test_make_directories(mount_dir, sub_done, sub_open):
    with pytest.raises(FileExistsError):
        mkdir(sub_open, 'dir')
    assert isdir(sub_open, 'dir')

    with pytest.raises(PermissionError):
        rm_rf(sub_open, 'dir')

    assert isdir(sub_open, 'dir')
    assert isfile(sub_open, 'dir', 'single_file_work')
    assert isfile(sub_open, 'dir', 'single_file_work_copy')

    with pytest.raises(IsADirectoryError):
        rm(sub_done, 'dir')
    with pytest.raises(OSError):
        rmdir(sub_done, 'dir')
    assert isdir(sub_done, 'dir')

    rm_rf(sub_done, 'dir')

    assert 'dir' not in ls(sub_done)

    mkdir(sub_done, 'dir')
    assert isdir(sub_done, 'dir')

    rmdir(sub_done, 'dir')
    assert 'dir' not in ls(sub_done)
示例#2
0
def test_deleting_file_in_fixed(sub_open, mount):
    fname = join(sub_open, 'new_test_file')
    fname2 = join(sub_open, 'new_test_file2')

    # Make sure we cannot delete existing files in fixed mode
    assert not isfile(fname)
    with open(fname, 'w') as f:
        f.write('Hello thomas\n')
    assert isfile(fname)

    mount(fixed=True)

    assert isfile(fname)
    with open(fname, 'r') as f:
        assert f.read() == 'Hello thomas\n'
    with pytest.raises(PermissionError):
        with open(fname, 'w') as f:
            f.write('Hello thomas\n')
    with pytest.raises(PermissionError):
        rm(fname)

    del fname

    # Now make sure we can delete files that did not exist
    assert not isfile(fname2)
    with open(fname2, 'w') as f:
        f.write('Hello thomas2\n')
    with open(fname2, 'r') as f:
        assert f.read() == 'Hello thomas2\n'
    assert isfile(fname2)

    rm(fname2)

    assert not isfile(fname2)

    # Make sure files created in fixed mode are not visible after a remount
    assert not isfile(fname2)
    with open(fname2, 'w') as f:
        f.write('Hello thomas2\n')
    with open(fname2, 'r') as f:
        assert f.read() == 'Hello thomas2\n'
    assert isfile(fname2)

    mount(fixed=True)
    assert not isfile(fname2)
    with open(fname2, 'w') as f:
        f.write('Hello thomas2\n')
    with open(fname2, 'r') as f:
        assert f.read() == 'Hello thomas2\n'
    assert isfile(fname2)

    mount(fixed=True)

    assert not isfile(fname2)
示例#3
0
def test_delete_files(mount_dir, sub_open, sub_done):
    with open(join(sub_open, 'file1'), 'w') as f:
        f.write('abc\n')
    assert isfile(sub_open, 'file1')

    with open(join(sub_open, 'file1'), 'r') as f:
        assert f.read() == 'abc\n'

    rm(sub_open, 'file1')
    assert not isfile(sub_open, 'file1')

    with pytest.raises(FileNotFoundError):
        rm(sub_open, 'nonexisting')
示例#4
0
def test_quote_paths(sub_done, path):
    dirs = path.split('/')[:-1]
    if len(dirs):
        mkdir(join(sub_done, *dirs))

    f_path = join(sub_done, path)
    with open(join(sub_done, f_path), 'w') as f:
        assert f.write('abc') == 3

    tmp_path = join(sub_done, 'abc')
    rename([f_path], [tmp_path])
    assert not isfile(f_path)
    assert isfile(tmp_path)

    rename([tmp_path], [f_path])
    assert isfile(f_path)
    assert not isfile(tmp_path)

    rm(f_path)
    if len(dirs):
        rmdir(join(sub_done, *dirs))