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