Skip to content
This repository
Browse code

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

…ere else
  • Loading branch information...
commit 6312720617cb7af18c5ed73f6a1c32e3cf2422cc 1 parent d58fbcd
Max Bolingbroke authored February 12, 2010
13  pinyin/tests/transformations.py
@@ -135,19 +135,6 @@ def testUseBestPack(self):
135 135
                  MediaPack("Bar", {"ma3.mp3" : "ma3.mp3", "ci2.mp3" : "ci2.mp3", "dian3.mp3" : "dian3.mp3"})]
136 136
         self.assertHasPartialReading(u"小马词典", ["ma3.mp3", "ci2.mp3", "dian3.mp3"], bestpackshouldbe=packs[1], mediapacks=packs)
137 137
 
138  
-    def testRandomizeBestPackOnTie(self):
139  
-        pack1 = MediaPack("Foo", {"ni3.mp3" : "PACK1.mp3"})
140  
-        pack2 = MediaPack("Bar", {"ni3.mp3" : "PACK2.mp3"})
141  
-
142  
-        gotpacks = []
143  
-        for n in range(1, 10):
144  
-            gotpack, _, _ = PinyinAudioReadings([pack1, pack2], [".mp3", ".ogg"]).audioreading(englishdict.reading(u"你"))
145  
-            gotpacks.append(gotpack)
146  
-        
147  
-        # This test will nondeterministically fail (1/2)^10 = 0.01% of the time
148  
-        self.assertTrue(pack1 in gotpacks)
149  
-        self.assertTrue(pack2 in gotpacks)
150  
-
151 138
     def testUseSpokenToneRatherThanWrittenOne(self):
152 139
         mediapacks = [MediaPack("Foo", { "ma2.mp3" : "ma2.mp3", "ma3.mp3" : "ma3.mp3" })]
153 140
         mediapack, output, mediamissingcount = PinyinAudioReadings(mediapacks, [".mp3"]).audioreadings([Word(Pinyin("ma", ToneInfo(written=2, spoken=3)))])[0]
19  pinyin/tests/updatergraph.py
@@ -201,6 +201,25 @@ def testAudioUsesExistingSoundsIfPossible(self):
201 201
                                                 u"[sound:" + os.path.join("Existing", "yue4.mp3") + "]"
202 202
           }, mediapacks=mediapacks, alreadyimported=[os.path.join("Existing", "san1.mp3"), os.path.join("Existing", "yue4.mp3")])
203 203
 
  204
+    def testRandomizeBestPackOnTie(self):
  205
+        configdict = dict(colorizedpinyingeneration = False, detectmeasurewords = False, tonedisplay = "numeric", dictlanguage = "en")
  206
+        
  207
+        mediapacks = [media.MediaPack("Foo", {"ni3.mp3" : "PACK1.mp3"}),
  208
+                      media.MediaPack("Bar", {"ni3.mp3" : "PACK2.mp3"})]
  209
+        
  210
+        gotpack1, gotpack2 = False, False
  211
+        for n in range(1, 10):
  212
+            graph = GraphBasedUpdater(MockNotifier(), MockMediaManager(mediapacks), pinyin.config.Config(configdict)).filledgraph({}, {
  213
+                "expression" : u"你", "mwfieldinfact" : False
  214
+              })
  215
+            
  216
+            gotpack1 = gotpack1 or "PACK1" in graph["audio"][1]()
  217
+            gotpack2 = gotpack2 or "PACK2" in graph["audio"][1]()
  218
+        
  219
+        # This test will nondeterministically fail (1/2)^10 = 0.01% of the time
  220
+        assert_true(gotpack1)
  221
+        assert_true(gotpack2)
  222
+
204 223
     def testUpdateMeasureWordAudio(self):
205 224
         config = dict(audioextensions = [".mp3", ".ogg"])
206 225
         
10  pinyin/transformations.py
@@ -201,16 +201,6 @@ def audioreadings(self, tokens):
201 201
         possibilities = sorted(possibilities, using(lambda (_mediapack, output, missingmediacount): (missingmediacount, count(output))))
202 202
         return possibilities and list(itertools.takewhile(lambda (_mediapack, _output, missingmediacount): missingmediacount == possibilities[0][2], possibilities)) or []
203 203
 
204  
-    # TODO: do I actually use this method?
205  
-    def audioreading(self, tokens):
206  
-        # Choose a random reading from the available possibilities, if any possibility exists
207  
-        possibilities = self.audioreadings(tokens)
208  
-        if possibilities:
209  
-            bestmediapack, bestoutput, bestmissingmediacount = random.choice(possibilities)
210  
-            return bestmediapack, bestoutput, (bestmissingmediacount != 0)
211  
-        else:
212  
-            return None, [], True
213  
-
214 204
 # Simple wrapper around the PinyinAudioReadingsVisitor
215 205
 def audioreadingforpack(mediapack, audioextensions, words):
216 206
     visitor = PinyinAudioReadingsVisitor(mediapack, audioextensions)

0 notes on commit 6312720

Please sign in to comment.
Something went wrong with that request. Please try again.