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)
def test_compiling_program(sub_done, mount, fixed): url = 'https://attach.libremail.nl/__test_codegra.fs__.tar.gz' fname = join(sub_done, '42.tar.gz') fdir = join(sub_done, '42sh/') urllib.request.urlretrieve(url, fname) tar = tarfile.open(fname, "r:gz") tar.extractall(sub_done) tar.close() print(subprocess.check_output(['make', '-C', fdir])) assert isdir(fdir) assert isfile(fname) assert subprocess.check_output( [join(fdir, '42sh'), '-c', 'echo hello from 42'] ).decode('utf-8') == 'hello from 42\n' mount() if fixed: assert not isdir(fdir) assert not isfile(fname) return assert isfile(fname) assert isdir(fdir) assert subprocess.check_output( [join(fdir, '42sh'), '-c', 'echo hello from 42'] ).decode('utf-8') == 'hello from 42\n' rm_rf(fdir) assert not isdir(fdir) mount() assert isfile(fname) assert not isdir(fdir)
def test_delete_invalid_file(mount_dir): with pytest.raises(PermissionError): top = [l for l in ls(mount_dir) if isdir(mount_dir, l)][0] rm_rf(mount_dir, top) with pytest.raises(PermissionError): top = [l for l in ls(mount_dir) if isdir(mount_dir, l)][0] f = [l for l in ls(mount_dir, top) if isdir(mount_dir, top, l)][0] rm_rf(mount_dir, top, f)