Exemplo n.º 1
0
def test_renaming_file_in_fixed(sub_open, mount):
    fname = join(sub_open, 'new_test_file')
    fname2 = join(sub_open, 'new_test_file2')
    fname3 = join(sub_open, 'new_test_file3')

    # 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 pytest.raises(PermissionError):
        rename([fname], [fname2])

    del fname

    assert not isfile(fname2)
    with open(fname2, 'w') as f:
        f.write('Hello thomas\n')
    assert isfile(fname2)
    rename([fname2], [fname3])

    assert not isfile(fname2)
    assert isfile(fname3)
    with open(fname3, 'r') as f:
        assert f.read() == 'Hello thomas\n'

    mount(fixed=True)
    assert not isfile(fname3)
Exemplo n.º 2
0
def test_deleting_directory_in_fixed(sub_open, mount):
    fdir = join(sub_open, 'new_test_file')
    fdir2 = join(sub_open, 'new_test_file2')
    fdir3 = join(sub_open, 'new_test_file3')

    # Make sure we cannot delete existing files in fixed mode
    assert not isdir(fdir)
    mkdir(fdir)
    assert isdir(fdir)

    mount(fixed=True)

    assert isdir(fdir)
    with pytest.raises(PermissionError):
        rmdir(fdir)
    assert isdir(fdir)

    del fdir

    assert not isdir(fdir2)
    mkdir(fdir2)
    assert isdir(fdir2)
    rename([fdir2], [fdir3])

    assert not isdir(fdir2)
    assert isdir(fdir3)

    mount(fixed=True)
    assert not isdir(fdir3)
Exemplo n.º 3
0
def _rename(src, dest):
    status = _remove(dest)
    if status:
        try:
            rename(src, dest)
        except:
            err('failed attempting to rename %s to %s\n' %
                (_nice(src), _nice(dest)))
            raise
    return status
Exemplo n.º 4
0
def test_illegal_rename(mount_dir, sub_done, sub_open):
    assert isdir(sub_done, 'dir')
    assert not isdir(sub_done, 'dir33')
    mkdir(sub_done, 'dir33')
    assert isdir(sub_done, 'dir33')

    with pytest.raises(FileNotFoundError):
        rename([sub_done, 'dir33'], [sub_done, 'dir', 'non_existing', 'dir33'])

    with pytest.raises(FileExistsError):
        rename([sub_done, 'dir33'], [sub_done, 'dir'])
Exemplo n.º 5
0
def test_non_exising_submission(assig_done):
    with pytest.raises(FileNotFoundError):
        open(join(assig_done, 'NON EXISTING', 'file'), 'x').close()

    with pytest.raises(FileNotFoundError):
        mkdir(assig_done, 'NON EXISTING', 'file')

    with pytest.raises(FileNotFoundError):
        rename(
            [assig_done, 'NON EXISTING', 'file'],
            [assig_done, 'NON EXISTING', 'file2']
        )

    with pytest.raises(FileNotFoundError):
        ls(assig_done, 'NON EXISTING')
Exemplo n.º 6
0
def test_rename(mount_dir, sub_done, sub_open):
    assert isdir(sub_done, 'dir')
    assert not isdir(sub_done, 'dir33')

    assert isdir(sub_done, 'dir')
    assert not isdir(sub_done, 'dir33')
    mkdir(sub_done, 'dir33')
    mkdir(sub_done, 'dir', 'sub_dir')
    assert isdir(sub_done, 'dir33')
    with open(join(sub_done, 'dir33', 'new_file'), 'w') as f:
        f.write('bye\n')

    rename([sub_done, 'dir33'], [sub_done, 'dir', 'sub_dir', 'dir33'])
    with open(join(sub_done, 'dir', 'sub_dir', 'dir33', 'new_file'), 'r') as f:
        assert f.read() == 'bye\n'
Exemplo n.º 7
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))
Exemplo n.º 8
0
def test_renaming_submission(sub_done, sub_done2, assig_done):
    with pytest.raises(FileExistsError):
        rename([sub_done], [sub_done2])

    with pytest.raises(PermissionError):
        rename([sub_done], [assig_done, 'NEW AND WRONG'])

    open(join(sub_done, 'hello'), 'w').close()

    with pytest.raises(PermissionError):
        rename([sub_done, 'hello'], [sub_done2, 'hello'])

    with pytest.raises(PermissionError):
        new = [x for x in sub_done.split('/')]
        new[-1] += new[-1]
        rename([sub_done], ['/'.join(new)])
Exemplo n.º 9
0
def test_renaming_submission(sub_done, sub_done2, assig_done):
    with pytest.raises(FileExistsError):
        rename([sub_done], [sub_done2])

    with pytest.raises(PermissionError):
        rename([sub_done], [assig_done, 'NEW AND WRONG'])

    open(join(sub_done, 'hello'), 'w').close()

    with pytest.raises(PermissionError):
        rename([sub_done, 'hello'], [sub_done2, 'hello'])