def test_no_fitting_files(self): """The FileSet should find no fitting files if there indeed are only unrelated files in the directory.""" test_files = [('this.mp3', True), ('is', True), ('a.test', True)] mock_scandir.return_value = mock_scandir_gen(test_files) test_set = FileSet.files_detected(self.pattern) self.assertEqual( test_set.files, {}, "The FileSet falsely identifies files in a directory which doesn't contain fitting files at all." )
def test_empty_directory(self): """The FileSet should be able to deal with being created in an empty directory and thus finding no files.""" test_files = [] mock_scandir.return_value = mock_scandir_gen(test_files) test_set = FileSet.files_detected(self.pattern) self.assertEqual( test_set.files, {}, "The FileSet fails when instructed to look for files in an empty directory." )
def test_hidden_file_set(self): """The CLI should correctly identify a hidden set that starts with a dot.""" test_files = [('.hidden0.jpg', True), ('.hidden1.jpg', True), ('.hidden2.jpg', True), ('.hidden3.jpg', True), ('.hidden4.jpg', True)] mock_scandir.return_value = mock_scandir_gen(test_files) detect_file_sets() mock_assert_msg( mock_FileSet.assert_called_once_with, [('.hidden', ''), ['.hidden0.jpg', '.hidden1.jpg', '.hidden2.jpg', '.hidden3.jpg', '.hidden4.jpg']], "The CLI fails to detect and create a hidden file set (i.e. one which's pattern starts with a dot)." )
def test_multi_extension_types(self): """The CLI should correctly identify a set's pattern even if it's files contain multiple extensions (e.g. .tar.gz).""" test_files = [('test (0).mp4', True), ('test (1).png', True), ('test (2).gif', True), ('test (3).tar.gz', True), ('test (4).p.n.g', True), ('test (5).jp.gz', True)] mock_scandir.return_value = mock_scandir_gen(test_files) detect_file_sets() mock_assert_msg( mock_FileSet.assert_called_once_with, [('test (', ')'), ['test (0).mp4', 'test (1).png', 'test (2).gif', 'test (3).tar.gz', 'test (4).p.n.g', 'test (5).jp.gz']], "The CLI fails to deal with files that have a multi-extension." )
def test_simple_set_alone(self): """The CLI should be able to recognize and create a simple file set sitting alone in the directory.""" test_files = [('test (0).jpg', True), ('test (1).jpg', True), ('test (2).jpg', True), ('test (3).jpg', True), ('test (4).jpg', True)] mock_scandir.return_value = mock_scandir_gen(test_files) detect_file_sets() mock_assert_msg( mock_FileSet.assert_called_once_with, [('test (', ')'), ['test (0).jpg', 'test (1).jpg', 'test (2).jpg', 'test (3).jpg', 'test (4).jpg']], "The CLI fails to find a lonely file set in a directory.""" )
def test_simple_set_dirt_files(self): """The CLI should be able to recognize and create a simple file set even if it's surrounded in unrelated files.""" test_files = [('TEPPYZGM.png', True), ('test (0).gif', True), ('dirt.gif', True), ('test (1).mp4', True), ('VzC.pdf', True), ('test (2).pdf', True), ('dirt.m4a', True), ('test (3).gif', True), ('test (4).m4a', True), ('test (5).jpg', True), ('test (6).m4a', True), ('test (7).mp4', True)] mock_scandir.return_value = mock_scandir_gen(test_files) detect_file_sets() mock_assert_msg( mock_FileSet.assert_called_once_with, [('test (', ')'), ['test (0).gif', 'test (1).mp4', 'test (2).pdf', 'test (3).gif', 'test (4).m4a', 'test (5).jpg', 'test (6).m4a', 'test (7).mp4']], "The CLI fails to find the correct files and the correct file set if there are dirt files around." )
def test_simple_coherent_file_set(self): """The FileSet should be able to detect its files if they are coherent.""" test_files = [('test (0).jpg', True), ('test (1).jpg', True), ('test (2).jpg', True), ('test (3).jpg', True)] mock_scandir.return_value = mock_scandir_gen(test_files) test_set = FileSet.files_detected(self.pattern) self.assertEqual( test_set.files, { 0: ['jpg'], 1: ['jpg'], 2: ['jpg'], 3: ['jpg'] }, "The FileSet fails to auto-detect and compile the files.")
def test_no_extension_files(self): """The FileSet should be able to auto-detect and deal with files that don't have an extension.""" test_files = [('test (0).jpg', True), ('test (1)', True), ('test (2).jpg', True), ('test (2)', True)] mock_scandir.return_value = mock_scandir_gen(test_files) test_set = FileSet.files_detected(self.pattern) self.assertEqual( test_set.files, { 0: ['jpg'], 1: [''], 2: ['jpg', ''] }, "The FileSet fails to auto-detect and process files that do not have a file extension." )
def test_detect_remove_file_set(self): """The CLI should correctly identify a file set that is used for the remove operation by default and set it as a global attribute accordingly.""" test_files = [('test (0).jpg', True), ('test (1).jpg', True), ('test (2).jpg', True), ('test (3).jpg', True), ('RMVD0.jpg', True), ('RMVD1.jpg', True), ('RMVD2.jpg', True), ('RMVD3.jpg', True)] mock_scandir.return_value = mock_scandir_gen(test_files) detect_file_sets() assertion_calls = [ (mock_FileSet.assert_any_call, [('test (', ')'), ['test (0).jpg', 'test (1).jpg', 'test (2).jpg', 'test (3).jpg']]), (mock_FileSet.assert_any_call, [('RMVD', ''), ['RMVD0.jpg', 'RMVD1.jpg', 'RMVD2.jpg', 'RMVD3.jpg']]) ] mock_assert_many_msg(assertion_calls, "The CLI fails to recognize and create the two file sets.") self.assertNotEqual(CLI.default_remove_set, None, "The CLI fails to recognize and set the default remove set after stumbling upon it.")
def test_various_sets(self): """The CLI should be able to recognize and create all available file sets in the directory.""" test_files = [('TEPPYZG09M.png', True), ('test (0).gif', True), ('dirt41.gif', True), ('test (1).mp4', True), ('V57zC.pdf', True), ('test (2).pdf', True), ('dirt90.m4a', True), ('test (3).gif', True), ('test (4).m4a', True), ('test (5).jpg', True), ('test (6).m4a', True), ('test (7).mp4', True)] mock_scandir.return_value = mock_scandir_gen(test_files) detect_file_sets() assertion_calls = [ (mock_FileSet.assert_any_call, [('test (', ')'), ['test (0).gif', 'test (1).mp4', 'test (2).pdf', 'test (3).gif', 'test (4).m4a', 'test (5).jpg', 'test (6).m4a', 'test (7).mp4']]), (mock_FileSet.assert_any_call, [('TEPPYZG', 'M'), ['TEPPYZG09M.png']]), (mock_FileSet.assert_any_call, [('dirt', ''), ['dirt41.gif', 'dirt90.m4a']]), (mock_FileSet.assert_any_call, [('V', 'zC'), ['V57zC.pdf']]) ] mock_assert_many_msg(assertion_calls, "The CLI fails to find all existent FileSets in a directory.")
def test_multi_assigned_indexes(self): """The FileSet should be able to detect its files even if there are multi-assigned indexes.""" test_files = [('test (0).jpg', True), ('test (1).jpg', True), ('test (2).jpg', True), ('test (2).png', True), ('test (3).jpg', True)] mock_scandir.return_value = mock_scandir_gen(test_files) test_set = FileSet.files_detected(self.pattern) self.assertEqual( test_set.files, { 0: ['jpg'], 1: ['jpg'], 2: ['jpg', 'png'], 3: ['jpg'] }, "The FileSet fails to correctly identify multi-assigned indexes.")
def test_multi_extension_files(self): """The FileSet should be able to auto-detect and deal with multi-extension files (e.g. tar.gz).""" test_files = [('test (0).jpg', True), ('test (1).jp.g', True), ('test (2).tar.gz', True), ('test (3).a.b.c.d.e', True)] mock_scandir.return_value = mock_scandir_gen(test_files) test_set = FileSet.files_detected(self.pattern) self.assertEqual( test_set.files, { 0: ['jpg'], 1: ['jp.g'], 2: ['tar.gz'], 3: ['a.b.c.d.e'] }, "The FileSet fails to auto-detect and process files with a multi-extension." )
def test_directories(self): """The FileSet should disregard directories, be they fitting to the pattern or not.""" test_files = [('test (0).jpg', True), ('test (1).jpg', True), ('test (2).jpg', True), ('folder', False), ('test (3).jpg', True), ('test (4)', False)] mock_scandir.return_value = mock_scandir_gen(test_files) test_set = FileSet.files_detected(self.pattern) self.assertEqual( test_set.files, { 0: ['jpg'], 1: ['jpg'], 2: ['jpg'], 3: ['jpg'] }, "The FileSet fails to correctly auto-detect its files if there are directories (that fit its pattern)." )
def test_find_extension_pattern_containing_dots(self): """The FileSet should be able to find the correct file extensions given that the pattern contains dots.""" test_files = [('.this.that0.jpg', True), ('.this.that1.jpg.gz', True), ('.this.that2', True), ('.this.that3.png', True)] mock_scandir.return_value = mock_scandir_gen(test_files) pattern = ('.this.that', '') test_set = FileSet.files_detected(pattern) self.assertEqual( test_set.files, { 0: ['jpg'], 1: ['jpg.gz'], 2: [''], 3: ['png'] }, "The FileSet fails to find the correct file extensions if the pattern contains dots and the files are auto-detected." )
def test_dirt_files(self): """The FileSet should be able to detect its files even if there are unrelated files in the directory.""" test_files = [('dirt16.mp4', True), ('test (0).jpg', True), ('tLfaqi60.m4a', True), ('test (1).jpg', True), ('test (2).jpg', True), ('dirt54.gif', True), ('test (3).jpg', True), ('test (4).jpg', True), ('test (5).jpg', True)] mock_scandir.return_value = mock_scandir_gen(test_files) test_set = FileSet.files_detected(self.pattern) self.assertEqual( test_set.files, { 0: ['jpg'], 1: ['jpg'], 2: ['jpg'], 3: ['jpg'], 4: ['jpg'], 5: ['jpg'] }, "The FileSet fails to filter files that do not belong to it.")