def test_text_is_memoized(self): dir = new_dir(TMP_DIR_PATH) file = TextFile('file.txt', dir) # We call text() two times and check that the text was read only once. file.text file.text dir.read_text_file.assert_called_once_with('file.txt')
def test_text_calls_read_text_file_on_its_directory_and_returns_result( self): dir = new_dir(TMP_DIR_PATH) FILE_TEXT = 'text of the file' dir.read_text_file.return_value = FILE_TEXT file = TextFile('file.txt', dir) self.assertEqual(file.text, FILE_TEXT) dir.read_text_file.assert_called_once_with('file.txt')
def _file_named(self, name): """Returns a file with the given name.""" if name.endswith('.c'): return CFile(name, self) elif name.endswith('.config.json'): return ConfigFile(name, self) elif name.endswith('.yara'): return YaraFile(name, self) # We assume that other files are text files by default. return TextFile(name, self)
def test_calls_shutil_copyfile_with_correct_arguments_and_returns_correct_file( self, copyfile_mock): input_file = TextFile('test.txt', self.directory) copied_file = self.directory.copy_file(input_file) copyfile_mock.assert_called_once_with( input_file.path, os.path.join(self.directory.path, input_file.name)) self.assertEqual(copied_file.dir, self.directory) self.assertEqual(copied_file.name, input_file.name)
def test_renamed_returns_file_with_new_class(self): dir = new_dir(TMP_DIR_PATH) file = TextFile('file.txt', dir) renamed_file = file.renamed('new.txt') self.assertEqual(renamed_file.__class__, TextFile)