class notes(unittest.TestCase):
    def setUp(self):
        self.tags = ["note"]
        self.chars = {}
        self.attrs = {"part":{"id": "P1"}, "measure":{"number": "1"}}
        self.handler = MxmlParser.CreateNote
        MxmlParser.part_id = "P1"
        MxmlParser.measure_id = 1
        self.piece = PieceTree()
        self.piece.addPart(Part.Part(), index="P1")
        self.piece.getPart("P1").addEmptyMeasure(1,1)
        self.data = {"note": None, "direction": None, "expression": None, "staff_id":1}


    def copy(self):
        pass
class notes(unittest.TestCase):

    def setUp(self):
        self.tags = ["note"]
        self.chars = {}
        self.attrs = {"part": {"id": "P1"}, "measure": {"number": "1"}}
        self.handler = MxmlParser.CreateNote
        MxmlParser.part_id = "P1"
        MxmlParser.measure_id = 1
        self.piece = PieceTree()
        self.piece.addPart(Part.Part(), index="P1")
        self.piece.getPart("P1").addEmptyMeasure(1, 1)
        self.data = {
            "note": None,
            "direction": None,
            "expression": None,
            "staff_id": 1}

    def copy(self):
        pass
Esempio n. 3
0
class MeasureTesting(unittest.TestCase):
    def setUp(self):
        self.tags = []
        self.tags.append("measure")
        self.attrs = {"measure": {"number": "1"}, "part": {"id": "P1"}}
        self.chars = {}
        self.handler = MxmlParser.HandleMeasures
        self.piece = PieceTree()
        self.piece.addPart(index="P1", item=Part.Part())
        self.part = self.piece.getPart("P1")
        MxmlParser.direction = None
        MxmlParser.note = None
        MxmlParser.expression = None
        self.data = {"note": None, "direction": None, "expression": None, "staff_id": 1, "voice": 1}

    def tearDown(self):
        self.piece = None
Esempio n. 4
0
class MeasureTesting(unittest.TestCase):

    def setUp(self):
        self.tags = []
        self.tags.append("measure")
        self.attrs = {"measure": {"number": "1"}, "part": {"id": "P1"}}
        self.chars = {}
        self.handler = MxmlParser.HandleMeasures
        self.piece = PieceTree()
        self.piece.addPart(index="P1", item=Part.Part())
        self.part = self.piece.getPart("P1")
        MxmlParser.direction = None
        MxmlParser.note = None
        MxmlParser.expression = None
        self.data = {
            "note": None,
            "direction": None,
            "expression": None,
            "staff_id": 1,
            "voice": 1}

    def tearDown(self):
        self.piece = None
class testHandlePart(unittest.TestCase):
    def setUp(self):
        self.handler = MxmlParser.UpdatePart
        self.tags = []
        self.chars = {}
        self.attrs = {}
        self.piece = PieceTree()
        self.data = {}

    def testNoData(self):
        self.assertEqual(None, self.handler(self.tags,self.attrs,self.chars,self.piece, self.data), "ERROR: no tags should return none in TestNodata")

    def testIrrelevantTag(self):
        self.tags.append("wut")
        MxmlParser.part_id = None
        self.assertEqual(None, self.handler(self.tags, self.attrs,self.chars,self.piece, self.data), "ERROR: irrelevant tags should return none in TestIrrelevantTag")

    def testScorePartTag(self):
        MxmlParser.part_id = None
        self.assertEqual(None, MxmlParser.part_id,"ERROR: part_id not none in testScorePartTag")
        self.tags.append("score-part")
        self.attrs["score-part"] = {"id":"P1"}
        self.handler(self.tags,self.attrs,self.chars,self.piece, self.data)
        self.assertEqual(1, len(self.piece.root.GetChildrenIndexes()))

    def testPnameTag(self):
        self.assertEqual(0, len(self.piece.root.GetChildrenIndexes()))
        self.tags.append("score-part")
        self.attrs["score-part"] = {"id":"P1"}
        self.tags.append("part-name")
        self.chars["part-name"] = "will"
        self.handler(self.tags,self.attrs,self.chars,self.piece, self.data)
        self.assertEqual("will", self.piece.getPart("P1").GetItem().name)

    def testPNameWithShortName(self):
        self.assertEqual(0, len(self.piece.root.GetChildrenIndexes()))
        self.tags.append("score-part")
        self.attrs["score-part"] = {"id":"P1"}
        self.tags.append("part-abbreviation")
        self.chars["part-abbreviation"] = "w"
        self.handler(self.tags,self.attrs,self.chars,self.piece, self.data)
        self.assertEqual("w", self.piece.getPart("P1").GetItem().shortname)

    def testPartGroupOpen(self):
        self.tags.append("part-group")
        self.attrs["part-group"] = {"number":"1","type":"start"}
        self.tags.append("score-part")
        self.attrs["score-part"] = {"id":"P1"}
        self.handler(self.tags,self.attrs,self.chars,self.piece, self.data)
        self.tags.append("score-part")
        self.attrs["score-part"] = {"id":"P2"}
        self.handler(self.tags,self.attrs,self.chars,self.piece, self.data)
        self.assertEqual(["P1","P2"], self.piece.getGroup(1))

    def testPartGroupClose(self):
        self.tags.append("part-group")
        self.attrs["part-group"] = {"number":"1","type":"start"}
        self.tags.append("score-part")
        self.attrs["score-part"] = {"id":"P1"}
        self.handler(self.tags,self.attrs,self.chars,self.piece, self.data)
        self.tags.append("part-group")
        self.attrs["part-group"] = {"number":"1","type":"stop"}
        self.handler(self.tags,self.attrs,self.chars,self.piece, self.data)
        self.tags.append("score-part")
        self.attrs["score-part"] = {"id":"P2"}
        self.handler(self.tags,self.attrs,self.chars,self.piece, self.data)
        self.assertEqual(["P1"], self.piece.getGroup(1))
class testHandlePart(unittest.TestCase):

    def setUp(self):
        self.handler = MxmlParser.UpdatePart
        self.tags = []
        self.chars = {}
        self.attrs = {}
        self.piece = PieceTree()
        self.data = {}

    def testNoData(self):
        self.assertEqual(
            None,
            self.handler(
                self.tags,
                self.attrs,
                self.chars,
                self.piece,
                self.data),
            "ERROR: no tags should return none in TestNodata")

    def testIrrelevantTag(self):
        self.tags.append("wut")
        MxmlParser.part_id = None
        self.assertEqual(
            None,
            self.handler(
                self.tags,
                self.attrs,
                self.chars,
                self.piece,
                self.data),
            "ERROR: irrelevant tags should return none in TestIrrelevantTag")

    def testScorePartTag(self):
        MxmlParser.part_id = None
        self.assertEqual(
            None,
            MxmlParser.part_id,
            "ERROR: part_id not none in testScorePartTag")
        self.tags.append("score-part")
        self.attrs["score-part"] = {"id": "P1"}
        self.handler(self.tags, self.attrs, self.chars, self.piece, self.data)
        self.assertEqual(1, len(self.piece.root.GetChildrenIndexes()))

    def testPnameTag(self):
        self.assertEqual(0, len(self.piece.root.GetChildrenIndexes()))
        self.tags.append("score-part")
        self.attrs["score-part"] = {"id": "P1"}
        self.tags.append("part-name")
        self.chars["part-name"] = "will"
        self.handler(self.tags, self.attrs, self.chars, self.piece, self.data)
        self.assertEqual("will", self.piece.getPart("P1").GetItem().name)

    def testPNameWithShortName(self):
        self.assertEqual(0, len(self.piece.root.GetChildrenIndexes()))
        self.tags.append("score-part")
        self.attrs["score-part"] = {"id": "P1"}
        self.tags.append("part-abbreviation")
        self.chars["part-abbreviation"] = "w"
        self.handler(self.tags, self.attrs, self.chars, self.piece, self.data)
        self.assertEqual("w", self.piece.getPart("P1").GetItem().shortname)

    def testPartGroupOpen(self):
        self.tags.append("part-group")
        self.attrs["part-group"] = {"number": "1", "type": "start"}
        self.tags.append("score-part")
        self.attrs["score-part"] = {"id": "P1"}
        self.handler(self.tags, self.attrs, self.chars, self.piece, self.data)
        self.tags.append("score-part")
        self.attrs["score-part"] = {"id": "P2"}
        self.handler(self.tags, self.attrs, self.chars, self.piece, self.data)
        self.assertEqual(["P1", "P2"], self.piece.getGroup(1))

    def testPartGroupClose(self):
        self.tags.append("part-group")
        self.attrs["part-group"] = {"number": "1", "type": "start"}
        self.tags.append("score-part")
        self.attrs["score-part"] = {"id": "P1"}
        self.handler(self.tags, self.attrs, self.chars, self.piece, self.data)
        self.tags.append("part-group")
        self.attrs["part-group"] = {"number": "1", "type": "stop"}
        self.handler(self.tags, self.attrs, self.chars, self.piece, self.data)
        self.tags.append("score-part")
        self.attrs["score-part"] = {"id": "P2"}
        self.handler(self.tags, self.attrs, self.chars, self.piece, self.data)
        self.assertEqual(["P1"], self.piece.getGroup(1))