Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove the now-redundant audioreading method and move its test somewh…

…ere else
  • Loading branch information...
commit 6312720617cb7af18c5ed73f6a1c32e3cf2422cc 1 parent d58fbcd
@batterseapower batterseapower authored
View
13 pinyin/tests/transformations.py
@@ -135,19 +135,6 @@ def testUseBestPack(self):
MediaPack("Bar", {"ma3.mp3" : "ma3.mp3", "ci2.mp3" : "ci2.mp3", "dian3.mp3" : "dian3.mp3"})]
self.assertHasPartialReading(u"小马词典", ["ma3.mp3", "ci2.mp3", "dian3.mp3"], bestpackshouldbe=packs[1], mediapacks=packs)
- def testRandomizeBestPackOnTie(self):
- pack1 = MediaPack("Foo", {"ni3.mp3" : "PACK1.mp3"})
- pack2 = MediaPack("Bar", {"ni3.mp3" : "PACK2.mp3"})
-
- gotpacks = []
- for n in range(1, 10):
- gotpack, _, _ = PinyinAudioReadings([pack1, pack2], [".mp3", ".ogg"]).audioreading(englishdict.reading(u""))
- gotpacks.append(gotpack)
-
- # This test will nondeterministically fail (1/2)^10 = 0.01% of the time
- self.assertTrue(pack1 in gotpacks)
- self.assertTrue(pack2 in gotpacks)
-
def testUseSpokenToneRatherThanWrittenOne(self):
mediapacks = [MediaPack("Foo", { "ma2.mp3" : "ma2.mp3", "ma3.mp3" : "ma3.mp3" })]
mediapack, output, mediamissingcount = PinyinAudioReadings(mediapacks, [".mp3"]).audioreadings([Word(Pinyin("ma", ToneInfo(written=2, spoken=3)))])[0]
View
19 pinyin/tests/updatergraph.py
@@ -201,6 +201,25 @@ def testAudioUsesExistingSoundsIfPossible(self):
u"[sound:" + os.path.join("Existing", "yue4.mp3") + "]"
}, mediapacks=mediapacks, alreadyimported=[os.path.join("Existing", "san1.mp3"), os.path.join("Existing", "yue4.mp3")])
+ def testRandomizeBestPackOnTie(self):
+ configdict = dict(colorizedpinyingeneration = False, detectmeasurewords = False, tonedisplay = "numeric", dictlanguage = "en")
+
+ mediapacks = [media.MediaPack("Foo", {"ni3.mp3" : "PACK1.mp3"}),
+ media.MediaPack("Bar", {"ni3.mp3" : "PACK2.mp3"})]
+
+ gotpack1, gotpack2 = False, False
+ for n in range(1, 10):
+ graph = GraphBasedUpdater(MockNotifier(), MockMediaManager(mediapacks), pinyin.config.Config(configdict)).filledgraph({}, {
+ "expression" : u"", "mwfieldinfact" : False
+ })
+
+ gotpack1 = gotpack1 or "PACK1" in graph["audio"][1]()
+ gotpack2 = gotpack2 or "PACK2" in graph["audio"][1]()
+
+ # This test will nondeterministically fail (1/2)^10 = 0.01% of the time
+ assert_true(gotpack1)
+ assert_true(gotpack2)
+
def testUpdateMeasureWordAudio(self):
config = dict(audioextensions = [".mp3", ".ogg"])
View
10 pinyin/transformations.py
@@ -201,16 +201,6 @@ def audioreadings(self, tokens):
possibilities = sorted(possibilities, using(lambda (_mediapack, output, missingmediacount): (missingmediacount, count(output))))
return possibilities and list(itertools.takewhile(lambda (_mediapack, _output, missingmediacount): missingmediacount == possibilities[0][2], possibilities)) or []
- # TODO: do I actually use this method?
- def audioreading(self, tokens):
- # Choose a random reading from the available possibilities, if any possibility exists
- possibilities = self.audioreadings(tokens)
- if possibilities:
- bestmediapack, bestoutput, bestmissingmediacount = random.choice(possibilities)
- return bestmediapack, bestoutput, (bestmissingmediacount != 0)
- else:
- return None, [], True
-
# Simple wrapper around the PinyinAudioReadingsVisitor
def audioreadingforpack(mediapack, audioextensions, words):
visitor = PinyinAudioReadingsVisitor(mediapack, audioextensions)
Please sign in to comment.
Something went wrong with that request. Please try again.