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" ])
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)
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)
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")
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" ])
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")