示例#1
0
 def testSimpleWrite(self):
     myCounter = Counter.Counter("e+a")
     count = MeasureCount.makeSimpleCount(myCounter, 4)
     handle = StringIO()
     indenter = fileUtils.Indenter(handle)
     dbfsv0.MeasureCountStructureV0().write(count, indenter)
     output = handle.getvalue().splitlines()
     self.assertEqual(output, [
         "COUNT_INFO_START", "  REPEAT_BEATS 4", "  BEAT_START",
         "    COUNT |^e+a|", "  BEAT_END", "COUNT_INFO_END"
     ])
示例#2
0
 def testNegativeBeatCount(self):
     data = """COUNT_INFO_START
           REPEAT_BEATS -1
           UNRECOGNISED LINE
           BEAT_START
               COUNT |^e+a|
           BEAT_END
       COUNT_INFO_END"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     self.assertRaises(DBErrors.InvalidPositiveInteger,
                       dbfsv0.MeasureCountStructureV0().read, iterator)
示例#3
0
 def testBadLine(self):
     data = """COUNT_INFO_START
           REPEAT_BEATS 4
           UNRECOGNISED LINE
           BEAT_START
               COUNT |^e+a|
           BEAT_END
       COUNT_INFO_END"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     self.assertRaises(DBErrors.UnrecognisedLine,
                       dbfsv0.MeasureCountStructureV0().read, iterator)
示例#4
0
 def testReadSimple(self):
     data = """COUNT_INFO_START
                   REPEAT_BEATS 4
                   BEAT_START
                       COUNT |^e+a|
                   BEAT_END
               COUNT_INFO_END"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     count = dbfsv0.MeasureCountStructureV0().read(iterator)
     self.assert_(count.isSimpleCount())
     self.assertEqual(len(count), 16)
     self.assertEqual(count.countString(), "1e+a2e+a3e+a4e+a")
示例#5
0
 def testComplexWrite(self):
     counter1 = Counter.Counter("e+a")
     counter2 = Counter.Counter("+a")
     counter3 = Counter.Counter("+")
     counter4 = Counter.Counter("e+a")
     count = MeasureCount.MeasureCount()
     count.addBeats(Beat.Beat(counter1), 1)
     count.addBeats(Beat.Beat(counter2), 1)
     count.addBeats(Beat.Beat(counter3), 1)
     count.addBeats(Beat.Beat(counter4, 2), 1)
     handle = StringIO()
     indenter = fileUtils.Indenter(handle)
     dbfsv0.MeasureCountStructureV0().write(count, indenter)
     output = handle.getvalue().splitlines()
     self.assertEqual(output, [
         "COUNT_INFO_START", "  BEAT_START", "    COUNT |^e+a|",
         "  BEAT_END", "  BEAT_START", "    COUNT |^+a|", "  BEAT_END",
         "  BEAT_START", "    COUNT |^+|", "  BEAT_END", "  BEAT_START",
         "    NUM_TICKS 2", "    COUNT |^e+a|", "  BEAT_END",
         "COUNT_INFO_END"
     ])
示例#6
0
 def testReadComplex(self):
     data = """COUNT_INFO_START
               BEAT_START
                 COUNT |^e+a|
               BEAT_END
               BEAT_START
                 COUNT |^+a|
               BEAT_END
               BEAT_START
                 COUNT |^+|
               BEAT_END
               BEAT_START
                 NUM_TICKS 2
                 COUNT |^e+a|
               BEAT_END
             COUNT_INFO_END"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     count = dbfsv0.MeasureCountStructureV0().read(iterator)
     self.assertFalse(count.isSimpleCount())
     self.assertEqual(len(count), 11)
     self.assertEqual(count.countString(), "1e+a2+a3+4e")