def test_html_to_yw7(self): """Use YwCnv class. """ copyfile(REFERENCE_HTML, TEST_HTML) yw7File = Yw7File(TEST_YW7) documentFile = importClass(TEST_HTML) converter = YwCnv() self.assertEqual(converter.convert( documentFile, yw7File), 'SUCCESS: "' + os.path.normpath(TEST_YW7) + '" written.') self.assertEqual(read_file(TEST_YW7), read_file(REFERENCE_YW7))
def make_file_objects(self, sourcePath, **kwargs): """Instantiate a source and a target object for creation of a new yWriter project. Positional arguments: sourcePath -- string; path to the source file to convert. Return a tuple with three elements: - A message string starting with 'SUCCESS' or 'ERROR' - sourceFile: a Novel subclass instance - targetFile: a Novel subclass instance """ if not self._canImport(sourcePath): return 'ERROR: This document is not meant to be written back.', None, None fileName, fileExtension = os.path.splitext(sourcePath) targetFile = Yw7File(fileName + Yw7File.EXTENSION, **kwargs) if sourcePath.endswith('.html'): # The source file might be an outline or a "work in progress". result = read_html_file(sourcePath) if result[0].startswith('SUCCESS'): if "<h3" in result[1].lower(): sourceFile = HtmlOutline(sourcePath, **kwargs) else: sourceFile = HtmlImport(sourcePath, **kwargs) return 'SUCCESS', sourceFile, targetFile else: return 'ERROR: Cannot read "' + os.path.normpath( sourcePath) + '".', None, None else: for fileClass in self.fileClasses: if fileClass.SUFFIX is not None: if sourcePath.endswith(fileClass.SUFFIX + fileClass.EXTENSION): sourceFile = fileClass(sourcePath, **kwargs) return 'SUCCESS', sourceFile, targetFile return 'ERROR: File type of "' + os.path.normpath( sourcePath) + '" not supported.', None, None
def test_yw7_to_exp(self): """Use YwCnv class. """ yw7File = Yw7File(TEST_YW7) documentFile = exportClass(TEST_EXP) converter = YwCnv() self.assertEqual(converter.convert( yw7File, documentFile), 'SUCCESS: "' + os.path.normpath(TEST_EXP) + '" written.') with zipfile.ZipFile(TEST_EXP, 'r') as myzip: myzip.extract(ODF_CONTENT, EXEC_PATH) myzip.close self.assertEqual(read_file(EXEC_PATH + ODF_CONTENT), read_file(DATA_PATH + ODF_CONTENT))
def test_yw7_to_odt_ui(self): """Use YwCnvUi class. """ yw7File = Yw7File(TEST_YW7) converter = Yw7Converter() kwargs = {'suffix': exportClass.SUFFIX} converter.run(TEST_YW7, **kwargs) self.assertEqual( converter.ui.infoHowText, 'SUCCESS: "' + os.path.normpath(TEST_ODT) + '" written.') with zipfile.ZipFile(TEST_ODT, 'r') as myzip: myzip.extract(ODT_CONTENT, EXEC_PATH) myzip.close self.assertEqual(read_file(EXEC_PATH + ODT_CONTENT), read_file(DATA_PATH + ODT_CONTENT))