Ejemplo n.º 1
0
class TestSubtitleFilter(unittest.TestCase):
   def setUp(self):
      self.sf = TagFilter()
      
   def test_BasicStringPasses(self):
      """Tests that a tag free short string passes through unchanged."""
      teststring = "This is a normal string."
      out = self.sf.filter(teststring) + self.sf.filter("")
      self.failUnless(teststring == out,out)
      
   def test_MaintestAllAtOnce(self):
      """Tests that a large string including tags is properly filtered.  See in the file to view the test input and output."""
      output = self.sf.filter(themaintestinput) + self.sf.filter("")
      self.failUnless(themaintestoutput == output)
      
   def test_locateDifferences(self):
      """Repeats the all at one test but also tries to give details about where
      the files differed.  This is more a debugging tool than a pass/fail unittest."""
      out = self.sf.filter(themaintestinput) + self.sf.filter("")
      for i in xrange(0,len(out)):
         if out[i] != themaintestoutput[i]:
            self.fail("Difference at character " + str(i) + " " + out[i] + "\n" + out[i-90:i+45] + "\n" + themaintestoutput[i-90:i+45])
     
   def test_bitbybit(self):
      """Repeats the main test with the same strings but this time passes the
      text to the filter a chunk at a time.  It also tries to print the location
     of problems to assist debugging."""
      out = ""
      pos = 0
      while pos <= len(themaintestinput):
         out = out + self.sf.filter(themaintestinput[pos:pos +20])
         pos = pos + 20
      out = out + self.sf.filter("")
      for i in xrange(0,len(out)):
         if out[i] != themaintestoutput[i]:
            self.fail("Difference at character " + str(i) + " " + out[i] + "\n" + out[i-90:i+45] + "\n" + themaintestoutput[i-90:i+45])
      self.failUnless(out == themaintestoutput)
Ejemplo n.º 2
0
 def setUp(self):
    self.sf = TagFilter()