Permalink
Browse files

Fix tests that I'd managed to disable and then break

  • Loading branch information...
1 parent 0d6c8ac commit 15ec1bfa4ba3a09d06864c424f55343ca18852a3 @batterseapower batterseapower committed Dec 6, 2009
Showing with 41 additions and 22 deletions.
  1. +13 −13 pinyin/tests/updater.py
  2. +28 −9 pinyin/tests/updatergraph.py
View
@@ -18,18 +18,18 @@ def assertUpdatesTo(updater, expression, theconfig, incomingfact, expectedfact,
updater(MockNotifier(), MockMediaManager(mediapacks), config.Config(utils.updated({ "dictlanguage" : "en" }, theconfig))).updatefact(actualfact, expression, **kwargs)
assert_dict_equal(actualfact, expectedfact, values_as_assertions=True)
-class FieldUpdaterFromAudioTest(unittest.TestCase):
+class TestFieldUpdaterFromAudio(object):
def testDoesntReformatWhenDisabled(self):
- self.assertUpdatesTo(u"hen3 hao3", dict(forcepinyininaudiotosoundtags = False), { "audio" : "", "expression" : "junk" }, { "audio" : "hen3 hao3", "expression" : "junk" })
+ self.assertUpdatesTo(u"hen3 hao3", dict(forcepinyininaudiotosoundtags = False), { "audio" : u"", "expression" : u"junk" }, { "audio" : u"hen3 hao3", "expression" : u"junk" })
def testLeavesOtherFieldsAlone(self):
- self.assertUpdatesTo(u"", dict(forcepinyininaudiotosoundtags = True), { "audio" : "[sound:fake.mp3]", "expression" : "junk" }, { "audio" : u"", "expression" : "junk" })
+ self.assertUpdatesTo(u"", dict(forcepinyininaudiotosoundtags = True), { "audio" : u"[sound:fake.mp3]", "expression" : u"junk" }, { "audio" : u"", "expression" : u"junk" })
def testReusesOldValueIfNoDelta(self):
- self.assertUpdatesTo(None, dict(forcepinyininaudiotosoundtags = True), { "audio" : "[sound:fake.mp3]" }, { "audio" : u"[sound:fake.mp3]" })
+ self.assertUpdatesTo(None, dict(forcepinyininaudiotosoundtags = True), { "audio" : u"[sound:fake.mp3]" }, { "audio" : u"[sound:fake.mp3]" })
def testUpdatingGeneratedVersion(self):
- self.assertUpdatesTo(None, dict(forcepinyininaudiotosoundtags = True), { "audio" : markgeneratedfield("[sound:fake.mp3]") }, { "audio" : markgeneratedfield(u"[sound:fake.mp3]") })
+ self.assertUpdatesTo(None, dict(forcepinyininaudiotosoundtags = True), { "audio" : markgeneratedfield(u"[sound:fake.mp3]") }, { "audio" : markgeneratedfield(u"[sound:fake.mp3]") })
def testReformatsAccordingToConfig(self):
henhaoaudio = u"[sound:" + os.path.join("Test", "hen3.mp3") + "][sound:" + os.path.join("Test", "hao3.mp3") + "]"
@@ -49,7 +49,7 @@ def assertUpdatesTo(self, *args):
"hen3.mp3" : "hen3.mp3", "hen2.mp3" : "hen2.mp3", "hao3.mp3" : "hao3.mp3" })]
assertUpdatesTo(partial(FieldUpdater, "audio"), *args, mediapacks=mediapacks)
-class FieldUpdaterFromMeaningTest(unittest.TestCase):
+class TestFieldUpdaterFromMeaning(object):
def testDoesntReformatWhenDisabled(self):
config = dict(forcemeaningnumberstobeformatted = False)
self.assertUpdatesTo(u"(1) yes (2) no", config, { "meaning" : "", "expression" : "junk" }, { "meaning" : "(1) yes (2) no", "expression" : "junk" })
@@ -71,7 +71,7 @@ def testReformatsAccordingToConfig(self):
def assertUpdatesTo(self, *args):
assertUpdatesTo(partial(FieldUpdater, "meaning"), *args)
-class FieldUpdaterFromReadingTest(unittest.TestCase):
+class TestFieldUpdaterFromReading(object):
def testDoesntReformatWhenDisabled(self):
config = dict(forcereadingtobeformatted = False)
self.assertUpdatesTo(u"hen3 hǎo", config, { "reading" : "", "expression" : "junk" }, { "reading" : u"hen3 hǎo", "expression" : "junk" })
@@ -117,11 +117,11 @@ def testReformattingRespectsExistingColorization(self):
def assertUpdatesTo(self, *args, **kwargs):
assertUpdatesTo(partial(FieldUpdater, "reading"), *args, **kwargs)
-class FieldUpdaterFromExpressionTest(object):
+class TestFieldUpdaterFromExpression(object):
def testReusesOldValueIfNoDelta(self):
- self.assertUpdatesTo(None, dict(tonedisplay = "tonified", readinggeneration = True),
- { "expression" : "", "reading" : "" },
- { "expression" : "", "reading" : "shu1" })
+ self.assertUpdatesTo(None, dict(colorizedpinyingeneration = False, tonedisplay = "numeric", readinggeneration = True),
+ { "expression" : u"", "reading" : "" },
+ { "expression" : u"", "reading" : markgeneratedfield("shu1") })
def testUpdatingGeneratedVerison(self):
self.assertUpdatesTo(None, {}, { "expression" : markgeneratedfield("") }, { "expression" : markgeneratedfield("") })
@@ -156,12 +156,12 @@ def testGenerateAllFieldsWhenEmptyOrGenerated(self):
"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") + "]") * 4)),
+ "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, { "reading" : default, "meaning" : default, "mw" : default, "audio" : default, "mwaudio" : default, "color" : default, "trad" : default, "simp" : default }, expected
+ 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 testDontOverwriteNonGeneratedFields(self):
config = dict(colorizedpinyingeneration = True, colorizedcharactergeneration = True, meaninggeneration = True, detectmeasurewords = True,
@@ -12,14 +12,14 @@
from pinyin.mocks import *
-class GeneralGraphTest(unittest.TestCase):
+class TestUpdaterGraphGeneralFunctionality(object):
def testDoesntUpdateNonGeneratedFields(self):
updaters = [
("output", lambda _: "modified output", ["input"])
]
graph = filledgraphforupdaters(updaters, { "input" : "hello", "output" : "original output" }, { "input" : "goodbye" })
- self.assertEquals(graph["output"][1](), "original output")
+ assert_equal(graph["output"][1](), "original output")
def testDoesntUpdateGeneratedFieldsIfInputsClean(self):
updaters = [
@@ -28,7 +28,7 @@ def testDoesntUpdateGeneratedFieldsIfInputsClean(self):
]
graph = filledgraphforupdaters(updaters, { "input" : "hello", "intermediate" : markgeneratedfield("constant"), "output" : markgeneratedfield("original output") }, { "input" : "goodbye" })
- self.assertEquals(graph["output"][1](), "original output")
+ assert_equal(graph["output"][1](), "original output")
def testUpdatesBlankFieldsDependentOnNonDirtyInputs(self):
updaters = [
@@ -37,9 +37,28 @@ def testUpdatesBlankFieldsDependentOnNonDirtyInputs(self):
]
graph = filledgraphforupdaters(updaters, { "input" : "hello", "intermediate" : markgeneratedfield("constant"), "output" : "" }, { "input" : "goodbye" })
- self.assertEquals(graph["output"][1](), "modified output")
+ assert_equal(graph["output"][1](), "modified output")
+
+ def testPreferUpdatersWhichUseChangedField(self):
+ short_chain_updaters = [
+ ("output", lambda _: "from input one", ["input one"]),
+ ("output", lambda _: "from input two", ["input two"])
+ ]
+
+ long_chain_updaters = [
+ ("output", lambda _: "from input one", ["input one"]),
+ ("intermediate", lambda x: x, ["input two"]),
+ ("output", lambda _: "from input two", ["intermediate"])
+ ]
+
+ for updaters in [short_chain_updaters, long_chain_updaters]:
+ graph = filledgraphforupdaters(updaters, { "input one" : "", "input two" : "", "output" : "" }, { "input one" : "go" })
+ yield assert_equal, graph["output"][1](), "from input one"
+
+ graph = filledgraphforupdaters(updaters, { "input one" : "", "input two" : "", "output" : "" }, { "input two" : "go" })
+ yield assert_equal, graph["output"][1](), "from input two"
-class UpdaterGraphTest(unittest.TestCase):
+class TestUpdaterGraphUpdaters(unittest.TestCase):
def testEverythingEnglish(self):
config = dict(prefersimptrad = "simp", forceexpressiontobesimptrad = False, tonedisplay = "tonified", hanzimasking = False,
emphasisemainmeaning = False, meaningnumbering = "circledChinese", colormeaningnumbers = False, meaningseperator = "lines",
@@ -161,8 +180,8 @@ def testNotifiedUponAudioGenerationWithNoPacks(self):
config = dict(colorizedpinyingeneration = False, detectmeasurewords = False, tonedisplay = "numeric")
def nassert(notifier):
- self.assertEquals(len(notifier.infos), 1)
- self.assertTrue("cannot" in notifier.infos[0])
+ assert_equal(len(notifier.infos), 1)
+ assert_true("cannot" in notifier.infos[0])
self.assertProduces({ "expression" : u"三月", "mwfieldinfact" : False }, config, {
"reading" : u'san1 yue4', "audio" : None
@@ -180,7 +199,7 @@ def mwaudioassert(mwaudio):
"X", "guan4", "pi2", "X",
"X", "tong3", "pi2", "X",
"X", "gang1", "pi2", "X"]
- self.assertEquals(sanitizequantitydigits(mwaudio), "".join([u"[sound:" + os.path.join("MWAudio", sound + ".mp3") + "]" for sound in sounds]))
+ assert_equal(sanitizequantitydigits(mwaudio), "".join([u"[sound:" + os.path.join("MWAudio", sound + ".mp3") + "]" for sound in sounds]))
# NB: turning off meaninggeneration here triggers a bug that happened in 0.6 where
# we wouldn't set up the dictmeasurewords for the mwaudio
@@ -221,7 +240,7 @@ def assertProduces(self, known, configdict, expected, mediapacks=None, notifiera
"hen3.mp3" : "hen3.mp3", "hen2.mp3" : "hen2.mp3", "hao3.mp3" : "hao3.mp3" })]
if notifierassertion == None:
- notifierassertion = lambda notifier: self.assertEquals(len(notifier.infos), 0)
+ notifierassertion = lambda notifier: assert_equal(len(notifier.infos), 0)
notifier = MockNotifier()
gbu = GraphBasedUpdater(notifier, MockMediaManager(mediapacks), pinyin.config.Config(pinyin.utils.updated({ "dictlanguage" : "en" }, configdict)))

0 comments on commit 15ec1bf

Please sign in to comment.