class TextEditorController(object): def __init__(self): self.document = Document() def open(self, path): try: self.document.open(path) except IOError: success = False else: success = True return success, self.document def save(self, text, path=None): self.document.text = text if path is not None: self.document.path = path try: self.document.save() except IOError: return False else: return True
def test_open_blank_file(self): document = Document() text_file = open("test_file", "w") text_file.close() document.open("test_file") self.assertEquals("test_file", document.path) self.assertEquals("", document.text)
def test_open_text_file(self): document = Document() text_file = open("test_file", "w") text_file.write("this is only a test") text_file.close() document.open("test_file") self.assertEquals("test_file", document.path) self.assertEquals("this is only a test", document.text)