def test_move_home(): home = Folder('home') working_dir = Folder('working_dir') working_dir = home request = 'mv home domek'.split() with pytest.raises(CannotCopyHomeError): mv(working_dir, request, home)
def test_folder_find_folder(): home = Folder('home') file1 = File(home, 'file1', 'txt', 1000) folder1 = Folder('folder1', home) file2 = File(folder1, 'file2', 'txt', 1000) wanted = home.find('folder1') assert wanted == folder1
def test_folder_count_elements(): pictures = Folder('pictures') pic_1 = File(pictures, 'pic_1', 'jpg', 999) pic_2 = File(pictures, 'pic_2', 'jpg', 999) pic_3 = File(pictures, 'pic_3', 'jpg', 999) pic_4 = File(pictures, 'pic_4', 'jpg', 999) assert pictures.count_elements() == 4
def test_folder_find_no_matches(): home = Folder('home') file1 = File(home, 'file1', 'txt', 1000) folder1 = Folder('folder1', home) file2 = File(folder1, 'file2', 'txt', 1000) wanted = home.find('fileX') assert wanted is None
def test_cat_folder(): home = Folder('home') working_dir = Folder('working_dir') working_dir = home folder1 = Folder('folder1', home) file1 = File(folder1, 'file1', 'txt', 1000) assert cat(working_dir, 'folder1') == str(folder1)
def test_folder_count_only_files(): pictures = Folder('pictures') pic_1 = File(pictures, 'pic_1', 'jpg', 999) pic_2 = File(pictures, 'pic_2', 'jpg', 999) pic_3 = File(pictures, 'pic_3', 'jpg', 999) holiday = Folder('holiday', pictures) assert pictures.count_only_files() == 3
def test_get_path_typical(): home = Folder('home') pictures = Folder('pictures', home) holiday = Folder('holiday', pictures) working_dir = holiday path = get_path(working_dir, home) assert path == "~/home/pictures/holiday "
def test_folder_list_elements(): home = Folder('home') file1 = File(home, 'file1', 'txt', 1000) folder1 = Folder('folder1', home) file2 = File(folder1, 'file2', 'txt', 1000) tree = "home\n -file1\n folder1\n -file2" assert tree == home.list_elements()
def test_command_cd_without_slash(): home = Folder('home') working_dir = Folder('working_dir') working_dir = home Folder('folder1', home) answer = "cd folder1".split() working_dir = cd(answer, working_dir, home) assert working_dir.name == 'folder1'
def test_folder_delete_element(): home = Folder('home') file = File(home, 'file', 'exe', 1510) assert home.size == 1510 assert len(home.content) == 1 home.delete_element(file) assert home.size == 0 assert home.content == []
def test_create_folder_with_content(): laby = Folder('laby') lab10 = File(laby, 'lab10', 'py', 100) laby_copy = Folder('laby_copy', None, [lab10], laby.size) assert laby_copy.name == 'laby_copy' assert laby_copy.directory is None assert laby_copy.content[0] == lab10 assert laby_copy.size == 100
def test_copy_file(): home = Folder('home') movies = Folder('movies') movie = File(movies, 'movie', 'mp4', 1510) assert home.content == [] movies.copy(home, 'movies_copy') assert len(home.content) == 1 assert home.content[0].name == 'movies_copy'
def test_folder_count_size_recursive(): home = Folder('home') lab10 = File(home, 'lab10', 'py', 100) lab11 = File(home, 'lab11', 'py', 200) project = Folder('project', home) file1 = File(project, 'file1', 'py', 100) file2 = File(project, 'file2', 'py', 150) size = home.count_size_recursive() assert size == 550
def test_folder_add_element(): home = Folder('home') user_one = Folder('user_one') file = File(user_one, 'file', 'exe', 1510) assert home.size == 0 assert home.content == [] home.add_element(file) assert len(home.content) == 1 assert home.size == 1510
def test_command_wc_only_files(): pictures = Folder('pictures') pic_1 = File(pictures, 'pic_1', 'jpg', 999) pic_2 = File(pictures, 'pic_2', 'jpg', 999) pic_3 = File(pictures, 'pic_3', 'jpg', 999) holiday = Folder("holiday", pictures) request = "wc -f pictures".split() num_of_elements = wc(pictures, request) assert num_of_elements == 3
def test_count_only_files_recursive(): pictures = Folder('pictures') pic_1 = File(pictures, 'pic_1', 'jpg', 999) pic_2 = File(pictures, 'pic_2', 'jpg', 999) pic_3 = File(pictures, 'pic_3', 'jpg', 999) holiday = Folder('holiday', pictures) pic_4 = File(holiday, 'pic_4', 'jpg', 999) pic_5 = File(holiday, 'pic_5', 'jpg', 999) assert pictures.count_only_files_recursive() == 5
def test_copy_file_to_working_dir(): home = Folder('home') working_dir = Folder('working_dir') working_dir = home folder1 = Folder('folder1', home) File(folder1, 'file1', 'txt', 10) request = 'cp file1 file1_copy'.split() assert len(home.content) == 1 cp(working_dir, request, home) assert len(home.content) == 2 assert home.content[1].name == "file1_copy"
def test_copy_folder_to_another_folder_with_path(): home = Folder('home') working_dir = Folder('working_dir') working_dir = home folder1 = Folder('folder1', home) folder2 = Folder("folder2", home) request = 'cp folder1 home/folder2 folder1_copy'.split() assert len(folder2.content) == 0 cp(working_dir, request, home) assert len(folder2.content) == 1 assert folder2.content[0].name == "folder1_copy"
def test_move_folder_to_working_dir(): home = Folder('home') working_dir = Folder('working_dir') working_dir = home folder1 = Folder('folder1', home) File(folder1, 'file1', 'txt', 10) request = 'mv folder1 folder1_copy'.split() assert len(home.content) == 1 mv(working_dir, request, home) assert len(home.content) == 1 assert home.content[0].name == "folder1_copy"
def test_command_wc_recursive_only_files(): pictures = Folder('pictures') pic_1 = File(pictures, 'pic_1', 'jpg', 999) pic_2 = File(pictures, 'pic_2', 'jpg', 999) pic_3 = File(pictures, 'pic_3', 'jpg', 999) holiday = Folder('holiday', pictures) pic_4 = File(holiday, 'pic_4', 'jpg', 999) pic_5 = File(holiday, 'pic_5', 'jpg', 999) request = "wc -r -f pictures".split() num_of_elements = wc(pictures, request) assert num_of_elements == 5
def test_command_rm(monkeypatch): home = Folder('home') working_dir = Folder('working_dir') working_dir = home folder1 = Folder('folder1', home) file1 = File(home, 'file1', 'txt', 1000) assert len(home.content) == 2 input_decision = StringIO('Y\n') monkeypatch.setattr('sys.stdin', input_decision) rm(file1, working_dir, home) assert len(home.content) == 1
def test_copy_file_to_another_dir(): home = Folder('home') new_folder = Folder('new_folder') lab10 = File(home, 'lab10', 'py', 100) assert len(new_folder.content) == 0 lab10.copy(new_folder, 'lab10_copy') if_copy_exists = True if len(new_folder.content) == 1 else False assert if_copy_exists is True assert new_folder.content[0].name == 'lab10_copy' assert new_folder.content[0].size == lab10.size assert new_folder.content[0]._type == lab10._type
def test_move_folder_to_another_folder(): home = Folder('home') working_dir = Folder('working_dir') working_dir = home folder1 = Folder('folder1', home) folder2 = Folder("folder2", home) request = 'mv folder1 folder2 folder1_copy'.split() assert len(folder2.content) == 0 assert len(home.content) == 2 mv(working_dir, request, home) assert len(folder2.content) == 1 assert len(home.content) == 1 assert folder2.content[0].name == "folder1_copy"
def test_create_file(): home = Folder('home') lab10 = File(home, 'lab10', 'py', 100) assert lab10.name == 'lab10' assert lab10._type == 'py' assert lab10.size == 100 assert lab10.directory == home
def test_command_cd_go_folder_up(): home = Folder('home') working_dir = Folder('working_dir') working_dir = home folder1 = Folder('folder1', home) folder2 = Folder('folder2', home) folder3 = Folder('folder3', folder1) answer = "cd folder1".split() working_dir = cd(answer, working_dir, home) assert working_dir.name == 'folder1' answer = "cd folder3".split() working_dir = cd(answer, working_dir, home) assert working_dir.name == 'folder3' answer = "cd ..".split() working_dir = cd(answer, working_dir, home) assert working_dir.name == 'folder1'
def test_command_wc(): pictures = Folder('pictures') pic_1 = File(pictures, 'pic_1', 'jpg', 999) pic_2 = File(pictures, 'pic_2', 'jpg', 999) pic_3 = File(pictures, 'pic_3', 'jpg', 999) request = "wc pictures".split() num_of_elements = wc(pictures, request) assert num_of_elements == 3
def test_ls(): pictures = Folder('pictures') pic_1 = File(pictures, 'pic_1', 'jpg', 999) pic_2 = File(pictures, 'pic_2', 'jpg', 999) pic_3 = File(pictures, 'pic_3', 'jpg', 999) holiday = Folder('holiday', pictures) pic_4 = File(holiday, 'pic_4', 'jpg', 999) pic_5 = File(holiday, 'pic_5', 'jpg', 999) tree = """pictures -pic_1 -pic_2 -pic_3 holiday -pic_4 -pic_5""" request = "ls pictures".split() assert tree == ls(pictures, request)
def test_copy_file_into_working_dir(): home = Folder('home') lab10 = File(home, 'lab10', 'py', 100) assert len(home.content) == 1 lab10.copy(home, 'lab10_copy') if_copy_exists = True if len(home.content) == 2 else False assert if_copy_exists is True assert home.content[1].name == 'lab10_copy' assert home.content[1].size == lab10.size assert home.content[1]._type == lab10._type
def test_str_file(): home = Folder('home') lab10 = File(home, 'lab10', 'py', 100) description = str(lab10) assert description == 'Name:lab10 Type:py Size:100 In directory: home'
def test_file_type(): home = Folder('home') file = File(home, 'file', 'txt', 1000) assert file.type() == 'txt'