def test_Pmwiki2MdUnderscoreConversion(self): from lib.pmwiki2md import Conversions, Pmwiki2MdUnderscoreBeginConversion, Pmwiki2MdUnderscoreEndConversion original = Content("Cucumbers {+might+} be tomatoes.") shouldLookLike = ["Cucumbers ", "''", "might", "''", " be tomatoes."] conversions = Conversions(Pmwiki2MdUnderscoreBeginConversion, Pmwiki2MdUnderscoreEndConversion) self.compareMultiConverted(original, shouldLookLike, conversions)
def test_Pmwiki2MdSuperscriptConversion(self): from lib.pmwiki2md import Pmwiki2MdSuperscriptConversion as Conversion original = Content("Cucumbers '^might^' be tomatoes.") shouldLookLike = [ "Cucumbers ", "<sup>", "might", "</sup>", " be tomatoes." ] self.compareConverted(original, shouldLookLike, Conversion)
def test_Pmwiki2MdStrikethroughConversion(self): from lib.pmwiki2md import Conversions, Pmwiki2MdStrikethroughBeginConversion, Pmwiki2MdStrikethroughEndConversion original = Content("Cucumbers {-might-} be tomatoes.") shouldLookLike = ["Cucumbers ", "~~", "might", "~~", " be tomatoes."] conversions = Conversions(Pmwiki2MdStrikethroughBeginConversion, Pmwiki2MdStrikethroughEndConversion) self.compareMultiConverted(original, shouldLookLike, conversions)
def test_Pmwiki2MdImageUrlConversion(self): from lib.pmwiki2md import Pmwiki2MdImageUrlConversion as Conversion original = Content("[[http://example.com/example.png]]") shouldLookLike = [ "![", "Example", "]", "(", "http://example.com/example.png", ")" ] cdprint(Conversion().convert(original)) self.compareConverted(original, shouldLookLike, Conversion)
def test_Pmwiki2MdSmallSmallConversion(self): from lib.pmwiki2md import Conversions, Pmwiki2MdSmallSmallBeginConversion, Pmwiki2MdSmallSmallEndConversion original = Content("Cucumbers [--might--] be tomatoes.") shouldLookLike = [ "Cucumbers ", "<sub>", "might", "</sub>", " be tomatoes." ] conversions = Conversions(Pmwiki2MdSmallSmallBeginConversion, Pmwiki2MdSmallSmallEndConversion) self.compareMultiConverted(original, shouldLookLike, conversions)
def test_Pmwiki2MdBigBigsConversion(self): from lib.pmwiki2md import Conversions, Pmwiki2MdBigBigBeginConversion, Pmwiki2MdBigBigEndConversion original = Content("Cucumbers [++might++] be tomatoes.") shouldLookLike = [ "Cucumbers ", "<sup>", "might", "</sup>", " be tomatoes." ] conversions = Conversions(Pmwiki2MdBigBigBeginConversion, Pmwiki2MdBigBigEndConversion) self.compareMultiConverted(original, shouldLookLike, conversions)
def test_ConversionOfBeginEndDelimitedToSomething(self): from lib.pmwiki2md import ConversionOfBeginEndDelimitedToSomething class Conversion(ConversionOfBeginEndDelimitedToSomething): BEGIN = "[[" END = "]]" original = Content("[[a]] [[b]]") shouldLookLike = ["[[", "a", "]]", " ", "[[", "b", "]]"] self.compareConverted(original, shouldLookLike, Conversion)
def test_ConversionByIterativeSingleCodeReplacementAtBeginOfLine_highestLevel( self): from lib.pmwiki2md import ConversionByIterativeSingleCodeReplacementAtBeginOfLine class __Test(ConversionByIterativeSingleCodeReplacementAtBeginOfLine): OLD = "*" NEW = "-" toBeCounted = Content( "\n*X\n**XXXX\n*\n*******XXX\n**XXXXXXXX\n****XX") countShouldBe = 7 count = __Test().highestLevel(toBeCounted) self.assertEqual(count, countShouldBe)
def _runOneFileTest(self, filePair): from lib.pmwiki2md import AllConversions as Conversions, Content as Content conversions = Conversions() pmwikiFilePath = os.path.join(self.pmwikiConversionsBaseDir, "testTest.pmwiki") mdFilePath = self.getMatchingMdFilePathForPmwikiFilePath( pmwikiFilePath) testFilePair = TestFilePair(pmwikiFilePath, mdFilePath) dprint("testFilePair", testFilePair.pmwikiFilePath, testFilePair.mdFilePath) return self.assertEqual( conversions.convert(Content(testFilePair.pmwiki)).string, testFilePair.md)
def test_ContentCopy(self): from lib.pmwiki2md import Content content1 = Content() content1.append("a") content1Copy = content1.copy() content2 = Content() self.assertEqual(content1, ["a"]) self.assertEqual(content2, [])
def convert(self): for pair in self.filePairs: converted = self.conversions().convert(Content(pair.source.read())) pair.target.write(converted.string)
def test_Pmwiki2MdTitle3Conversion(self): from lib.pmwiki2md import Pmwiki2MdTitle3Conversion as Conversion original = Content("\n!!!Cucumbers might be tomatoes.") shouldLookLike = ["", "\n### ", "Cucumbers might be tomatoes."] self.compareConverted(original, shouldLookLike, Conversion)
def test_Pmwiki2Md3LevelBulletListConversion(self): from lib.pmwiki2md import Pmwiki2MdBulletListConversion as Conversion original = Content("\n***Cucumbers might be tomatoes.") shouldLookLike = ["", "\n - ", "Cucumbers might be tomatoes."] self.compareConverted(original, shouldLookLike, Conversion)
def test_Pmwiki2MdNamelessLinkPointyBracketsConversion(self): from lib.pmwiki2md import Pmwiki2MdLinkConversion as Conversion original = Content("[[http://example.com]]") shouldLookLike = ["<", "http://example.com", ">"] self.compareConverted(original, shouldLookLike, Conversion)
def test_Pmwiki2MdNamedLinkConversion(self): from lib.pmwiki2md import Pmwiki2MdLinkConversion as Conversion original = Content("[[http://example.com | Example]]") shouldLookLike = ["[", "Example", "]", "(", "http://example.com", ")"] cdprint(Conversion().convert(original)) self.compareConverted(original, shouldLookLike, Conversion)
def test_Pmwiki2MdBoldConversion(self): from lib.pmwiki2md import Pmwiki2MdBoldConversion as Conversion original = Content("Cucumbers '''might''' be tomatoes.") shouldLookLike = ["Cucumbers ", "__", "might", "__", " be tomatoes."] self.compareConverted(original, shouldLookLike, Conversion)
def test_Pmwiki2MdPreFormattedInlineConversion(self): from lib.pmwiki2md import Pmwiki2MdPreFormattedInlineConversion as Conversion original = Content("[@Cucumbers *might* be tomatoes.@]") shouldLookLike = ["`", "Cucumbers *might* be tomatoes.", "`"] cdprint(Conversion().convert(original)) self.compareConverted(original, shouldLookLike, Conversion)
def runOneFileTest(self, pmwikiFileTestName): from lib.pmwiki2md import AllConversions as Conversions, Content as Content testFilePair = self.filePairs[pmwikiFileTestName] conversions = Conversions() content = Content(testFilePair.pmwiki) return self.convertAndCompare(conversions, content, testFilePair)