def test_set_enormous_max_index(self): """The FileSet should be able to fix itself even if it has a max index greater than 1000.""" test_files = [ 'test (234).jpg', 'test (346).jpg', 'test (934).jpg', 'test (1038).jpg' ] test_set = FileSet(self.pattern, test_files) mock_find_flaws.side_effect = FileSet.TooManyFilesError() try: test_set.fix() except FileSet.TooManyFilesError: self.fail( "The FileSet raises a TooManyFilesError even though it could have fixed the set of only four files." ) assertion_calls = [(mock_change_index.assert_any_call, [234, 0]), (mock_change_index.assert_any_call, [346, 1]), (mock_change_index.assert_any_call, [934, 2]), (mock_change_index.assert_any_call, [1038, 3])] mock_assert_many_msg( assertion_calls, "The FileSet fails to fix the gaps of a file set with a max_index above 1000." ) mock_assert_msg( mock_move_range.assert_not_called, [], "The FileSet tries to move ranges even though there is no reason to make any space." )
def mock_find_flaws_side_effect(): global mock_find_flaws_call_count if mock_find_flaws_call_count == 0: mock_find_flaws_call_count += 1 test_set.max_index = 2 raise FileSet.TooManyFilesError() elif mock_find_flaws_call_count == 1: flaws = ([], [(0, ['jpg', 'png'])]) return flaws
def test_set_enormous_amount_of_files_auto_fix_multi_indexes(self): """The FileSet should raise an error if requested to fix multi-assigned indexes in a set of more than 1000 files.""" test_set = FileSet(self.pattern, []) test_set.files = EnormousDict() test_set.max_index = 1234 mock_find_flaws.side_effect = FileSet.TooManyFilesError() with self.assertRaises( FileSet.TooManyFilesError, msg= "The FileSet fails to recognize when there are too many files to auto-fix multi-assigned indexes." ): test_set.fix(True)
def test_set_enormous_amount_of_files_no_multi_index_auto_fix(self): """Even if the file set contains more than 1000 files, the file set should fix possible gaps.""" test_set = FileSet(self.pattern, []) test_set.files = EnormousDict() test_set.max_index = 1234 mock_find_flaws.side_effect = FileSet.TooManyFilesError() try: test_set.fix() except FileSet.TooManyFilesError: self.fail( "The FileSet raises an exception when there's more than 1000 files, even though auto-fix multi-assigned indexes was not requested and thus there should be no problem." )
def test_set_with_too_many_files(self): """The method should raise a CLIRuntimeError if the file set has too many files to perform 'fix all'.""" test_args = ['fix', 'all'] mock_fix.side_effect = FileSet.TooManyFilesError("Too many files.") with self.assertRaises( CLI.CLIRuntimeError, msg= "The method fails to react correctly when the file set contains too many files to fix all." ): CLI.fix(self.test_set, test_args) mock_assert_msg( mock_fix.assert_called_once_with, [True], "The method doesn't actually try to perform the fix operation.")