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) dbfsv1.MeasureCountStructureV1().write(count, indenter) output = handle.getvalue().splitlines() self.assertEqual(output, ["START_MEASURE_COUNT", " BEAT_START", " NUM_TICKS 4", " COUNT |^e+a|", " BEAT_END", " BEAT_START", " NUM_TICKS 3", " COUNT |^+a|", " BEAT_END", " BEAT_START", " NUM_TICKS 2", " COUNT |^+|", " BEAT_END", " BEAT_START", " NUM_TICKS 2", " COUNT |^e+a|", " BEAT_END", "END_MEASURE_COUNT"])
def setUp(self): self.reg = Counter.CounterRegistry(False) self.counter1 = Counter.Counter("^bcd") self.counter2 = Counter.Counter("^vw", "^yz") self.counter3 = Counter.Counter("^fgh") self.reg.register("four", self.counter1) self.reg.register("three", self.counter2) self.reg.register("four2", self.counter3)
def testRegisterIterAndClear(self): reg = Counter.CounterRegistry(False) tc1 = Counter.Counter("^bcd") tc2 = Counter.Counter("^vw", "^yz") tc3 = Counter.Counter("^fgh") reg.register("four", tc1) reg.register("three", tc2) self.assertRaises(KeyError, reg.register, "four", tc3) self.assertRaises(ValueError, reg.register, "test", tc1) counts = list(reg) self.assertEqual(counts, [("four", tc1), ("three", tc2)]) reg.clear() counts = list(reg) self.assertEqual(counts, [])
class TestCounter(unittest.TestCase): counter = Counter.Counter("^bcd", "^fgh", "^jkl") def testLength(self): self.assertEqual(len(self.counter), 4) def testIter(self): self.assertEqual(list(self.counter), ["^", "b", "c", "d"]) def testStr(self): self.assertEqual(str(self.counter), "^bcd") def testBadCounter(self): self.assertRaises(ValueError, Counter.Counter, "abcd") self.assertRaises(ValueError, Counter.Counter, "^bcd", "defg") self.assertRaises(ValueError, Counter.Counter, "^bcd", "^de") def testWrite(self): handle = StringIO() indenter = fileUtils.Indenter(handle) self.counter.write(indenter) self.assertEqual(handle.getvalue(), "COUNT |^bcd|\n") def testMatchExact(self): self.assert_(self.counter.matchesExact("^bcd")) self.assertFalse(self.counter.matchesExact("^fgh")) self.assertFalse(self.counter.matchesExact("^xyz")) def testMatchAlternative(self): self.assertFalse(self.counter.matchesAlternative("^bcd")) self.assert_(self.counter.matchesAlternative("^fgh")) self.assert_(self.counter.matchesAlternative("^jkl")) self.assertFalse(self.counter.matchesAlternative("^xyz"))
class TestCounter(unittest.TestCase): counter = Counter.Counter("^bcd", "^fgh", "^jkl") def testLength(self): self.assertEqual(len(self.counter), 4) def testIter(self): self.assertEqual(list(self.counter), ["^", "b", "c", "d"]) def testStr(self): self.assertEqual(str(self.counter), "^bcd") def testBadCounter(self): self.assertRaises(ValueError, Counter.Counter, "^bcd", "defg") self.assertRaises(ValueError, Counter.Counter, "^bcd", "^de") def testMatchExact(self): self.assert_(self.counter.matchesExact("^bcd")) self.assertFalse(self.counter.matchesExact("^fgh")) self.assertFalse(self.counter.matchesExact("^xyz")) def testMatchAlternative(self): self.assertFalse(self.counter.matchesAlternative("^bcd")) self.assert_(self.counter.matchesAlternative("^fgh")) self.assert_(self.counter.matchesAlternative("^jkl")) self.assertFalse(self.counter.matchesAlternative("^xyz"))
class TestPartialBeat(unittest.TestCase): beat = Beat.Beat(Counter.Counter("e+a"), 2) def testStr(self): self.assertEqual(str(self.beat), "^e+a") def testTicksPerBeat(self): self.assertEqual(self.beat.ticksPerBeat, 4) def testNumTicks(self): self.assertEqual(self.beat.numTicks, 2) def testNumBeats(self): self.assertEqual(self.beat.numBeats(), 0.5) def testIter(self): count = list(self.beat) self.assertEqual(count, ["^", "e"]) def testIterTicks(self): ticks = list(self.beat.iterTicks()) self.assertEqual(ticks, [0, 1]) def testCount(self): count = list(self.beat.count(2)) self.assertEqual(count, ["2", "e"])
class TestFullBeat(unittest.TestCase): beat = Beat.Beat(Counter.Counter("e+a")) def testStr(self): self.assertEqual(str(self.beat), "^e+a") def testTicksPerBeat(self): self.assertEqual(self.beat.ticksPerBeat, 4) def testNumTicks(self): self.assertEqual(self.beat.numTicks, 4) def testNumBeats(self): self.assertEqual(self.beat.numBeats(), 1.0) def testIter(self): count = list(self.beat) self.assertEqual(count, ["^", "e", "+", "a"]) def testIterTicks(self): ticks = list(self.beat.iterTicks()) self.assertEqual(ticks, [0, 1, 2, 3]) def testCount(self): count = list(self.beat.count(2)) self.assertEqual(count, ["2", "e", "+", "a"])
class TestPartialBeat(unittest.TestCase): beat = Beat.Beat(Counter.Counter(Counter.BEAT_COUNT + "e+a"), 2) def testStr(self): self.assertEqual(str(self.beat), "^e+a") def testTicksPerBeat(self): self.assertEqual(self.beat.ticksPerBeat, 4) def testNumTicks(self): self.assertEqual(self.beat.numTicks, 2) def testNumBeats(self): self.assertEqual(self.beat.numBeats(), 0.5) def testIter(self): count = list(self.beat) self.assertEqual(count, ["^", "e"]) def testIterTicks(self): ticks = list(self.beat.iterTicks()) self.assertEqual(ticks, [0, 1]) def testCount(self): count = list(self.beat.count(2)) self.assertEqual(count, ["2", "e"]) def testWrite(self): handle = StringIO() indenter = fileUtils.Indenter(handle) self.beat.write(indenter) output = handle.getvalue().splitlines() self.assertEqual( output, ["BEAT_START", " NUM_TICKS 2", " COUNT |^e+a|", "BEAT_END"])
def testWriteFullBeat(self): beat = Beat.Beat(Counter.Counter("e+a")) handle = StringIO() indenter = fileUtils.Indenter(handle) dbfsv0.BeatStructureV0().write(beat, indenter) output = handle.getvalue().splitlines() self.assertEqual(output, ["BEAT_START", " COUNT |^e+a|", "BEAT_END"])
def testWrite(self): counter = Counter.Counter("^bcd", "^fgh", "^jkl") handle = StringIO() indenter = fileUtils.Indenter(handle) dbfsv0.CounterFieldV0("COUNT", getter=lambda _: counter).write_all( self, indenter) self.assertEqual(handle.getvalue(), "COUNT |^bcd|\n")
def testSimpleDefaultWrite(self): myCounter = Counter.Counter("e+a") count = MeasureCount.makeSimpleCount(myCounter, 4) handle = StringIO() indenter = fileUtils.Indenter(handle) dbfsv1.DefaultMeasureCountStructureV1().write(count, indenter) output = handle.getvalue().splitlines() self.assertEqual(output, ["START_DEFAULT_MEASURE_COUNT", " BEAT_START", " NUM_TICKS 4", " COUNT |^e+a|", " BEAT_END", " BEAT_START", " NUM_TICKS 4", " COUNT |^e+a|", " BEAT_END", " BEAT_START", " NUM_TICKS 4", " COUNT |^e+a|", " BEAT_END", " BEAT_START", " NUM_TICKS 4", " COUNT |^e+a|", " BEAT_END", "END_DEFAULT_MEASURE_COUNT"])
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" ])
class TestDefaultRegistry(unittest.TestCase): reg = Counter.CounterRegistry() def testIter(self): self.assertEqual(len(list(self.reg)), 11) def testQuarters(self): names = [name for name, unusedCount in self.reg.countsByTicks(1)] self.assertEqual(names, ["Quarter Notes"]) self.assertEqual(len(self.reg.findMaster("^")), 1) def testEighths(self): names = [name for name, unusedCount in self.reg.countsByTicks(2)] self.assertEqual(names, ["8ths"]) self.assertEqual(len(self.reg.findMaster("^+")), 2) def testSixteenths(self): names = [name for name, unusedCount in self.reg.countsByTicks(4)] self.assertEqual(names, ["16ths", "Sparse 16ths"]) self.assertEqual(len(self.reg.findMaster("^e+a")), 4) self.assertEqual(len(self.reg.findMaster("^ + ")), 4) def testThirtySeconds(self): names = [name for name, unusedCount in self.reg.countsByTicks(8)] self.assertEqual(names, ["32nds", "Sparse 32nds"]) self.assertEqual(len(self.reg.findMaster("^.e.+.a.")), 8) self.assertEqual(len(self.reg.findMaster("^ e + a ")), 8) def testTriplets(self): names = [name for name, unusedCount in self.reg.countsByTicks(3)] self.assertEqual(names, ["Triplets"]) self.assertEqual(len(self.reg.findMaster("^+a")), 3) self.assertEqual(len(self.reg.findMaster("^ea")), 3) def testSixteenthTriplets(self): names = [name for name, unusedCount in self.reg.countsByTicks(6)] self.assertEqual(names, ["16th Triplets", "Sparse 16th Triplets"]) self.assertEqual(len(self.reg.findMaster("^ea+ea")), 6) self.assertEqual(len(self.reg.findMaster("^ + ")), 6) def testThirtySecondTriplets(self): names = [name for name, unusedCount in self.reg.countsByTicks(12)] self.assertEqual(names, ["32nd Triplets", "Sparse 32nd Triplets"]) self.assertEqual(len(self.reg.findMaster("^.e.a.+.e.a.")), 12) self.assertEqual(len(self.reg.findMaster("^ e a + e a ")), 12)
class TestComplex(unittest.TestCase): counter1 = Counter.Counter(Counter.BEAT_COUNT + "e+a") counter2 = Counter.Counter(Counter.BEAT_COUNT + "+a") counter3 = Counter.Counter(Counter.BEAT_COUNT + "+") counter4 = Counter.Counter(Counter.BEAT_COUNT + "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) def testLength(self): self.assertEqual(len(self.count), 11) def testNumBeats(self): self.assertEqual(self.count.numBeats(), 4) def testIsSimple(self): self.assertFalse(self.count.isSimpleCount()) def testCount(self): self.assertEqual(list(self.count.count()), ["1", "e", "+", "a", "2", "+", "a", "3", "+", "4", "e", ]) def testCountString(self): self.assertEqual(self.count.countString(), "1e+a2+a3+4e") def testGetItem(self): beat = self.count[1] self.assert_(isinstance(beat, Beat.Beat)) self.assertEqual(beat.numTicks, 3) self.assertEqual(beat.ticksPerBeat, 3) self.assertRaises(IndexError, self.count.__getitem__, 4) def testIterTimesMs(self): times = list(self.count.iterTimesMs(120)) self.assertEqual(times, [0, 30, 60, 90, 120, 160, 200, 240, 300, 360, 390, 420]) def testTimeSig(self): self.assertEqual(self.count.timeSig(), (7, 8)) def testIterBeatTicks(self): ticks = list(self.count.iterBeatTicks()) beat1 = self.count[0] beat2 = self.count[1] beat3 = self.count[2] beat4 = self.count[3] self.assertEqual(ticks, [(0, beat1, 0), (0, beat1, 1), (0, beat1, 2), (0, beat1, 3), (1, beat2, 0), (1, beat2, 1), (1, beat2, 2), (2, beat3, 0), (2, beat3, 1), (3, beat4, 0), (3, beat4, 1)]) def testIterBeatTickPositions(self): ticks = list(self.count.iterBeatTickPositions()) self.assertEqual(ticks, [0, 4, 7, 9]) def testIterMidiTicks(self): ticks = list(self.count.iterMidiTicks()) self.assertEqual(ticks, [0, 24, 48, 72, 96, 128, 160, 192, 240, 288, 312, 336]) def testIterTime(self): ticks = list(self.count.iterTime()) self.assertEqual(ticks, [(0, 0, 4), (0, 1, 4), (0, 2, 4), (0, 3, 4), (1, 0, 3), (1, 1, 3), (1, 2, 3), (2, 0, 2), (2, 1, 2), (3, 0, 4), (3, 1, 4)]) def testWrite(self): handle = StringIO() indenter = fileUtils.Indenter(handle) self.count.write(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"])
class TestSimple(unittest.TestCase): my_counter = Counter.Counter("e+a") count = MeasureCount.makeSimpleCount(my_counter, 4) def testLength(self): self.assertEqual(len(self.count), 16) def testNumBeats(self): self.assertEqual(self.count.numBeats(), 4) def testIsSimple(self): self.assert_(self.count.isSimpleCount()) def testCount(self): self.assertEqual(list(self.count.count()), ["1", "e", "+", "a", "2", "e", "+", "a", "3", "e", "+", "a", "4", "e", "+", "a"]) def testCountString(self): self.assertEqual(self.count.countString(), "1e+a2e+a3e+a4e+a") def testGetItem(self): beat = self.count[1] self.assert_(isinstance(beat, Beat.Beat)) self.assertEqual(beat.numTicks, 4) self.assertEqual(beat.ticksPerBeat, 4) self.assertRaises(IndexError, self.count.__getitem__, 4) def testIterTimesMs(self): times = list(self.count.iterTimesMs(100)) self.assertEqual(times, [0, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400]) def testTimeSig(self): self.assertEqual(self.count.timeSig(), (4, 4)) def testIterBeatTicks(self): ticks = list(self.count.iterBeatTicks()) beat = self.count[0] self.assertEqual(ticks, [(0, beat, 0), (0, beat, 1), (0, beat, 2), (0, beat, 3), (1, beat, 0), (1, beat, 1), (1, beat, 2), (1, beat, 3), (2, beat, 0), (2, beat, 1), (2, beat, 2), (2, beat, 3), (3, beat, 0), (3, beat, 1), (3, beat, 2), (3, beat, 3)]) def testIterBeatTickPositions(self): ticks = list(self.count.iterBeatTickPositions()) self.assertEqual(ticks, [0, 4, 8, 12]) def testIterMidiTicks(self): ticks = list(self.count.iterMidiTicks()) self.assertEqual(ticks, [0, 48, 96, 144, 192, 240, 288, 336, 384, 432, 480, 528, 576, 624, 672, 720, 768]) def testIterTime(self): ticks = list(self.count.iterTime()) self.assertEqual(ticks, [(0, 0, 4), (0, 1, 4), (0, 2, 4), (0, 3, 4), (1, 0, 4), (1, 1, 4), (1, 2, 4), (1, 3, 4), (2, 0, 4), (2, 1, 4), (2, 2, 4), (2, 3, 4), (3, 0, 4), (3, 1, 4), (3, 2, 4), (3, 3, 4)])
class TestTimeSigs(unittest.TestCase): sixteenths = Counter.Counter("e+a") triplets = Counter.Counter("+a") eighths = Counter.Counter("+") def testTwoFour(self): count = MeasureCount.makeSimpleCount(self.eighths, 2) self.assertEqual(count.timeSig(), (2, 4)) count = MeasureCount.makeSimpleCount(self.triplets, 2) self.assertEqual(count.timeSig(), (2, 4)) count = MeasureCount.makeSimpleCount(self.sixteenths, 2) self.assertEqual(count.timeSig(), (2, 4)) def testThreeFour(self): count = MeasureCount.makeSimpleCount(self.eighths, 3) self.assertEqual(count.timeSig(), (3, 4)) count = MeasureCount.makeSimpleCount(self.triplets, 3) self.assertEqual(count.timeSig(), (3, 4)) count = MeasureCount.makeSimpleCount(self.sixteenths, 3) self.assertEqual(count.timeSig(), (3, 4)) def testFourFour(self): count = MeasureCount.makeSimpleCount(self.eighths, 4) self.assertEqual(count.timeSig(), (4, 4)) count = MeasureCount.makeSimpleCount(self.triplets, 4) self.assertEqual(count.timeSig(), (4, 4)) count = MeasureCount.makeSimpleCount(self.sixteenths, 4) self.assertEqual(count.timeSig(), (4, 4)) def testFiveFour(self): count = MeasureCount.makeSimpleCount(self.eighths, 5) self.assertEqual(count.timeSig(), (5, 4)) count = MeasureCount.makeSimpleCount(self.triplets, 5) self.assertEqual(count.timeSig(), (5, 4)) count = MeasureCount.makeSimpleCount(self.sixteenths, 5) self.assertEqual(count.timeSig(), (5, 4)) def testSixFour(self): count = MeasureCount.makeSimpleCount(self.eighths, 6) self.assertEqual(count.timeSig(), (6, 4)) count = MeasureCount.makeSimpleCount(self.triplets, 6) self.assertEqual(count.timeSig(), (6, 4)) count = MeasureCount.makeSimpleCount(self.sixteenths, 6) self.assertEqual(count.timeSig(), (6, 4)) def testSevenFour(self): count = MeasureCount.makeSimpleCount(self.eighths, 7) self.assertEqual(count.timeSig(), (7, 4)) count = MeasureCount.makeSimpleCount(self.triplets, 7) self.assertEqual(count.timeSig(), (7, 4)) count = MeasureCount.makeSimpleCount(self.sixteenths, 7) self.assertEqual(count.timeSig(), (7, 4)) def testThreeEight(self): count = MeasureCount.makeSimpleCount(self.eighths, 1) count.addBeats(Beat.Beat(self.eighths, 1), 1) self.assertEqual(count.timeSig(), (3, 8)) count = MeasureCount.makeSimpleCount(self.sixteenths, 1) count.addBeats(Beat.Beat(self.sixteenths, 2), 1) self.assertEqual(count.timeSig(), (3, 8)) def testFiveEight(self): count = MeasureCount.makeSimpleCount(self.eighths, 2) count.addBeats(Beat.Beat(self.eighths, 1), 1) self.assertEqual(count.timeSig(), (5, 8)) count = MeasureCount.makeSimpleCount(self.sixteenths, 2) count.addBeats(Beat.Beat(self.sixteenths, 2), 1) self.assertEqual(count.timeSig(), (5, 8)) def testSevenEight(self): count = MeasureCount.makeSimpleCount(self.eighths, 3) count.addBeats(Beat.Beat(self.eighths, 1), 1) self.assertEqual(count.timeSig(), (7, 8)) count = MeasureCount.makeSimpleCount(self.sixteenths, 3) count.addBeats(Beat.Beat(self.sixteenths, 2), 1) self.assertEqual(count.timeSig(), (7, 8)) def testNineEight(self): count = MeasureCount.makeSimpleCount(self.eighths, 4) count.addBeats(Beat.Beat(self.eighths, 1), 1) self.assertEqual(count.timeSig(), (9, 8)) count = MeasureCount.makeSimpleCount(self.sixteenths, 4) count.addBeats(Beat.Beat(self.sixteenths, 2), 1) self.assertEqual(count.timeSig(), (9, 8)) def testThirteenSixteen(self): count = MeasureCount.makeSimpleCount(self.sixteenths, 3) count.addBeats(Beat.Beat(self.sixteenths, 1), 1) self.assertEqual(count.timeSig(), (13, 16)) def testFifteenSixteen(self): count = MeasureCount.makeSimpleCount(self.sixteenths, 3) count.addBeats(Beat.Beat(self.sixteenths, 3), 1) self.assertEqual(count.timeSig(), (15, 16)) def testSeventeenSixteen(self): count = MeasureCount.makeSimpleCount(self.sixteenths, 4) count.addBeats(Beat.Beat(self.sixteenths, 1), 1) self.assertEqual(count.timeSig(), (17, 16))
class TestComplex(unittest.TestCase): 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) def testLength(self): self.assertEqual(len(self.count), 11) def testNumBeats(self): self.assertEqual(self.count.numBeats(), 4) def testIsSimple(self): self.assertFalse(self.count.isSimpleCount()) def testCount(self): self.assertEqual(list(self.count.count()), ["1", "e", "+", "a", "2", "+", "a", "3", "+", "4", "e", ]) def testCountString(self): self.assertEqual(self.count.countString(), "1e+a2+a3+4e") def testGetItem(self): beat = self.count[1] self.assert_(isinstance(beat, Beat.Beat)) self.assertEqual(beat.numTicks, 3) self.assertEqual(beat.ticksPerBeat, 3) self.assertRaises(IndexError, self.count.__getitem__, 4) def testIterTimesMs(self): times = list(self.count.iterTimesMs(120)) self.assertEqual(times, [0, 30, 60, 90, 120, 160, 200, 240, 300, 360, 390, 420]) def testTimeSig(self): self.assertEqual(self.count.timeSig(), (7, 8)) def testIterBeatTicks(self): ticks = list(self.count.iterBeatTicks()) beat1 = self.count[0] beat2 = self.count[1] beat3 = self.count[2] beat4 = self.count[3] self.assertEqual(ticks, [(0, beat1, 0), (0, beat1, 1), (0, beat1, 2), (0, beat1, 3), (1, beat2, 0), (1, beat2, 1), (1, beat2, 2), (2, beat3, 0), (2, beat3, 1), (3, beat4, 0), (3, beat4, 1)]) def testIterBeatTickPositions(self): ticks = list(self.count.iterBeatTickPositions()) self.assertEqual(ticks, [0, 4, 7, 9]) def testIterMidiTicks(self): ticks = list(self.count.iterMidiTicks()) self.assertEqual(ticks, [0, 48, 96, 144, 192, 256, 320, 384, 480, 576, 624, 672]) def testIterTime(self): ticks = list(self.count.iterTime()) self.assertEqual(ticks, [(0, 0, 4), (0, 1, 4), (0, 2, 4), (0, 3, 4), (1, 0, 3), (1, 1, 3), (1, 2, 3), (2, 0, 2), (2, 1, 2), (3, 0, 4), (3, 1, 4)])
class TestSimple(unittest.TestCase): my_counter = Counter.Counter(Counter.BEAT_COUNT + "e+a") count = MeasureCount.makeSimpleCount(my_counter, 4) def testLength(self): self.assertEqual(len(self.count), 16) def testNumBeats(self): self.assertEqual(self.count.numBeats(), 4) def testIsSimple(self): self.assert_(self.count.isSimpleCount()) def testCount(self): self.assertEqual(list(self.count.count()), ["1", "e", "+", "a", "2", "e", "+", "a", "3", "e", "+", "a", "4", "e", "+", "a"]) def testCountString(self): self.assertEqual(self.count.countString(), "1e+a2e+a3e+a4e+a") def testGetItem(self): beat = self.count[1] self.assert_(isinstance(beat, Beat.Beat)) self.assertEqual(beat.numTicks, 4) self.assertEqual(beat.ticksPerBeat, 4) self.assertRaises(IndexError, self.count.__getitem__, 4) def testIterTimesMs(self): times = list(self.count.iterTimesMs(100)) self.assertEqual(times, [0, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400]) def testTimeSig(self): self.assertEqual(self.count.timeSig(), (4, 4)) def testIterBeatTicks(self): ticks = list(self.count.iterBeatTicks()) beat = self.count[0] self.assertEqual(ticks, [(0, beat, 0), (0, beat, 1), (0, beat, 2), (0, beat, 3), (1, beat, 0), (1, beat, 1), (1, beat, 2), (1, beat, 3), (2, beat, 0), (2, beat, 1), (2, beat, 2), (2, beat, 3), (3, beat, 0), (3, beat, 1), (3, beat, 2), (3, beat, 3)]) def testIterBeatTickPositions(self): ticks = list(self.count.iterBeatTickPositions()) self.assertEqual(ticks, [0, 4, 8, 12]) def testIterMidiTicks(self): ticks = list(self.count.iterMidiTicks()) self.assertEqual(ticks, [0, 24, 48, 72, 96, 120, 144, 168, 192, 216, 240, 264, 288, 312, 336, 360, 384]) def testIterTime(self): ticks = list(self.count.iterTime()) self.assertEqual(ticks, [(0, 0, 4), (0, 1, 4), (0, 2, 4), (0, 3, 4), (1, 0, 4), (1, 1, 4), (1, 2, 4), (1, 3, 4), (2, 0, 4), (2, 1, 4), (2, 2, 4), (2, 3, 4), (3, 0, 4), (3, 1, 4), (3, 2, 4), (3, 3, 4)]) def testWrite(self): handle = StringIO() indenter = fileUtils.Indenter(handle) self.count.write(indenter) output = handle.getvalue().splitlines() self.assertEqual(output, ["COUNT_INFO_START", " REPEAT_BEATS 4", " BEAT_START", " COUNT |^e+a|", " BEAT_END", "COUNT_INFO_END"])