def testDontUpdateSimplifiedTraditionalIfModifyingUnrelatedField(self): config = dict(simpgeneration = True, tradgeneration = True) self.assertProduces({ "audio" : u"[audio:meh.mp3]" }, config, lambda graph: "simp" not in graph, fact={ "expression" : u"个個" }) assert False fact = { 'trad': markgeneratedfield(u'\u66f8'), 'audio': markgeneratedfield(u'[sound:b4df1258ec41a790e745a934a1aa9cdf.ogg]'), 'color': markgeneratedfield(u'<span style="color:#ff0000;">\u4e66</span>'), 'mw': markgeneratedfield(u'<span style="color:#00aa00;">\u672c</span> - <span style="color:#00aa00;">b\u011bn</span>, <span style="color:#0000ff;">\u518c</span> - <span style="color:#0000ff;">c\xe8</span>, <span style="color:#0000ff;">\u90e8</span> - <span style="color:#0000ff;">b\xf9</span>', 'meaning': u'<a name="pinyin-toolkit"></a>book<br /><span style="font-size:small; color:#a4a4a4;">\u3281</span><span style="font-size:small;"> letter<br /></span><span style="font-size:small; color:#a4a4a4;">\u3282</span><span style="font-size:small;"> see also </span><span style="font-size:small; color:#a4a4a4;">\u32a5</span><span style="font-size:small; color:#ff0000;">\u7ecf</span><span style="font-size:small;"> Book of History</span>'), 'simp': u'', 'reading': u'<a name="pinyin-toolkit"></a><span style="color:#ff0000;">s</span><span style="color:#ff0000;">h\u016b</span>', 'expression': u'\u4e66' } self.assertProduces({}, config, fact, fact=fact)
def testAutoBlankingGenerated(self): self.assertUpdatesTo(u"", {}, { "reading" : markgeneratedfield("blather"), "meaning" : markgeneratedfield("junk"), "color" : markgeneratedfield("yes!"), "trad" : markgeneratedfield("meh"), "simp" : markgeneratedfield("yay"), "audio" : markgeneratedfield("moo"), "mwaudio" : markgeneratedfield("mehh"), "mw" : markgeneratedfield("a mw") }, { "reading" : "", "meaning" : "", "color" : "", "trad" : "", "simp" : "", "audio" : "", "mwaudio" : "", "mw" : "" })
def testReusesOldValueIfNoDelta(self): self.assertUpdatesTo( None, dict(colorizedpinyingeneration=False, tonedisplay="numeric", readinggeneration=True), { "expression": u"书", "reading": "" }, { "expression": u"书", "reading": markgeneratedfield("shu1") })
def testUpdateColor(self): config = dict(forcereadingtobeformatted=False, colorizedpinyingeneration=False, colorizedcharactergeneration=True, tonecolors=[ u"#111111", u"#222222", u"#333333", u"#444444", u"#555555" ]) for updatewith, old, new in [(u"hen3", u"", u"hen3"), (u"hěn", u"", u"hěn"), (None, markgeneratedfield(u"hěn"), markgeneratedfield(u"hěn"))]: yield (self.assertUpdatesTo, updatewith, config, { "reading": old, "expression": u"很", "color": u"" }, { "reading": new, "expression": u"很", "color": markgeneratedfield(u'<span style="color:#333333">很</span>') })
def testGenerateAllFieldsWhenEmptyOrGenerated(self): config = dict(colorizedpinyingeneration = True, colorizedcharactergeneration = True, meaninggeneration = True, detectmeasurewords = True, emphasisemainmeaning = False, tonedisplay = "tonified", meaningnumbering = "circledChinese", colormeaningnumbers = False, meaningseperator = "lines", prefersimptrad = "simp", audiogeneration = True, mwaudiogeneration = True, audioextensions = [".mp3"], tonecolors = [u"#ff0000", u"#ffaa00", u"#00aa00", u"#0000ff", u"#545454"], weblinkgeneration = False, hanzimasking = False, tradgeneration = True, simpgeneration = True, forceexpressiontobesimptrad = False) for default in ["", markgeneratedfield("Generated")]: expected = { "expression" : u"书", "reading" : markgeneratedfield(u'<span style="color:#ff0000">shū</span>'), "meaning" : markgeneratedfield(u'㊀ book<br />㊁ letter<br />㊂ see also <span style="color:#ff0000">\u4e66</span><span style="color:#ff0000">\u7ecf</span> Book of History'), "mw" : markgeneratedfield(u'<span style="color:#00aa00">本</span> - <span style="color:#00aa00">běn</span>, <span style="color:#0000ff">册</span> - <span style="color:#0000ff">cè</span>, <span style="color:#0000ff">部</span> - <span style="color:#0000ff">bù</span>'), "audio" : markgeneratedfield(u"[sound:" + os.path.join("Test", "shu1.mp3") + "]"), "mwaudio" : lambda mwaudio: assert_equal(sanitizequantitydigits(mwaudio), markgeneratedfield((u"[sound:" + os.path.join("Test", "X.mp3") + u"][sound:" + os.path.join("Test", "shu1.mp3") + "]") * 3)), "color" : markgeneratedfield(u'<span style="color:#ff0000">书</span>'), "trad" : markgeneratedfield(u"書"), "simp" : markgeneratedfield(u"书") } yield self.assertUpdatesTo, u"书", config, { "expression" : u"书", "reading" : default, "meaning" : default, "mw" : default, "audio" : default, "mwaudio" : default, "color" : default, "trad" : default, "simp" : default }, expected
def testAutoBlankingGenerated(self): self.assertUpdatesTo(u"", {}, { "reading": markgeneratedfield("blather"), "meaning": markgeneratedfield("junk"), "color": markgeneratedfield("yes!"), "trad": markgeneratedfield("meh"), "simp": markgeneratedfield("yay"), "audio": markgeneratedfield("moo"), "mwaudio": markgeneratedfield("mehh"), "mw": markgeneratedfield("a mw") }, { "reading": "", "meaning": "", "color": "", "trad": "", "simp": "", "audio": "", "mwaudio": "", "mw": "" })
def testUpdatingGeneratedVerison(self): self.assertUpdatesTo(None, {}, { "expression" : markgeneratedfield(u"书") }, { "expression" : markgeneratedfield(u"书") })
def testReusesOldValueIfNoDelta(self): self.assertUpdatesTo(None, dict(colorizedpinyingeneration = False, tonedisplay = "numeric", readinggeneration = True), { "expression" : u"书", "reading" : "" }, { "expression" : u"书", "reading" : markgeneratedfield("shu1") })
def testUpdatesBlankFieldsDependentOnNonDirtyInputs(self): updaters = [ ("intermediate", lambda _: "constant", ("input",)), ("output", lambda _: "modified output", ("intermediate",)) ] graph = filledgraphforupdaters(updaters, { "input" : "hello", "intermediate" : markgeneratedfield("constant"), "output" : "" }, { "input" : "goodbye" }) assert_equal(graph["output"][1](), "modified output")
def testUpdateColor(self): config = dict(forcereadingtobeformatted = False, colorizedpinyingeneration = False, colorizedcharactergeneration = True, tonecolors = [u"#111111", u"#222222", u"#333333", u"#444444", u"#555555"]) for updatewith, old, new in [(u"hen3", u"", u"hen3"), (u"hěn", u"", u"hěn"), (None, markgeneratedfield(u"hěn"), markgeneratedfield(u"hěn"))]: yield (self.assertUpdatesTo, updatewith, config, { "reading" : old, "expression" : u"很", "color" : u"" }, { "reading" : new, "expression" : u"很", "color" : markgeneratedfield(u'<span style="color:#333333">很</span>') })
def testUpdatingGeneratedVersion(self): self.assertUpdatesTo( None, dict(forcepinyininaudiotosoundtags=True), {"audio": markgeneratedfield(u"[sound:fake.mp3]")}, {"audio": markgeneratedfield(u"[sound:fake.mp3]")})
def testGenerateAllFieldsWhenEmptyOrGenerated(self): config = dict(colorizedpinyingeneration=True, colorizedcharactergeneration=True, meaninggeneration=True, detectmeasurewords=True, emphasisemainmeaning=False, tonedisplay="tonified", meaningnumbering="circledChinese", colormeaningnumbers=False, meaningseperator="lines", prefersimptrad="simp", audiogeneration=True, mwaudiogeneration=True, audioextensions=[".mp3"], tonecolors=[ u"#ff0000", u"#ffaa00", u"#00aa00", u"#0000ff", u"#545454" ], weblinkgeneration=False, hanzimasking=False, tradgeneration=True, simpgeneration=True, forceexpressiontobesimptrad=False) for default in ["", markgeneratedfield("Generated")]: expected = { "expression": u"书", "reading": markgeneratedfield(u'<span style="color:#ff0000">shū</span>'), "meaning": markgeneratedfield( u'㊀ book<br />㊁ letter<br />㊂ see also <span style="color:#ff0000">\u4e66</span><span style="color:#ff0000">\u7ecf</span> Book of History' ), "mw": markgeneratedfield( u'<span style="color:#00aa00">本</span> - <span style="color:#00aa00">běn</span>, <span style="color:#0000ff">册</span> - <span style="color:#0000ff">cè</span>, <span style="color:#0000ff">部</span> - <span style="color:#0000ff">bù</span>' ), "audio": markgeneratedfield(u"[sound:" + os.path.join("Test", "shu1.mp3") + "]"), "mwaudio": lambda mwaudio: assert_equal( sanitizequantitydigits(mwaudio), markgeneratedfield((u"[sound:" + os.path.join( "Test", "X.mp3") + u"][sound:" + os.path.join( "Test", "shu1.mp3") + "]") * 3)), "color": markgeneratedfield(u'<span style="color:#ff0000">书</span>'), "trad": markgeneratedfield(u"書"), "simp": markgeneratedfield(u"书") } yield self.assertUpdatesTo, u"书", config, { "expression": u"书", "reading": default, "meaning": default, "mw": default, "audio": default, "mwaudio": default, "color": default, "trad": default, "simp": default }, expected
def testUpdatingGeneratedVerison(self): self.assertUpdatesTo(None, {}, {"expression": markgeneratedfield(u"书")}, {"expression": markgeneratedfield(u"书")})
def testUpdatingGeneratedVersion(self): config = dict(forcereadingtobeformatted=True, tonedisplay="numeric") self.assertUpdatesTo(None, config, {"reading": markgeneratedfield(u"hen3")}, {"reading": markgeneratedfield(u"hen3")})
def testUpdatingGeneratedVersion(self): self.assertUpdatesTo(None, dict(forcepinyininaudiotosoundtags = True), { "audio" : markgeneratedfield(u"[sound:fake.mp3]") }, { "audio" : markgeneratedfield(u"[sound:fake.mp3]") })
def testUpdatingGeneratedVersion(self): self.assertUpdatesTo(None, dict(forcemeaningnumberstobeformatted = True), { "meaning" : markgeneratedfield(u"hen3") }, { "meaning" : markgeneratedfield(u"hen3") })
def testDoesntUpdateGeneratedFieldsIfInputsClean(self): updaters = [ ("intermediate", lambda _: "constant", ("input",)), ("output", lambda _: "modified output", ("intermediate",)) ] graph = filledgraphforupdaters(updaters, { "input" : "hello", "intermediate" : markgeneratedfield("constant"), "output" : markgeneratedfield("original output") }, { "input" : "goodbye" }) assert_equal(graph["output"][1](), "original output")
def testUpdatingGeneratedVersion(self): config = dict(forcereadingtobeformatted = True, tonedisplay = "numeric") self.assertUpdatesTo(None, config, { "reading" : markgeneratedfield(u"hen3") }, { "reading" : markgeneratedfield(u"hen3") })
def testUpdatingGeneratedVersion(self): self.assertUpdatesTo(None, dict(forcemeaningnumberstobeformatted=True), {"meaning": markgeneratedfield(u"hen3")}, {"meaning": markgeneratedfield(u"hen3")})