当前位置: 首页>>代码示例>>Python>>正文


Python MeiDocument.root方法代码示例

本文整理汇总了Python中pymei.MeiDocument.root方法的典型用法代码示例。如果您正苦于以下问题:Python MeiDocument.root方法的具体用法?Python MeiDocument.root怎么用?Python MeiDocument.root使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymei.MeiDocument的用法示例。


在下文中一共展示了MeiDocument.root方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_documentpointers

# 需要导入模块: from pymei import MeiDocument [as 别名]
# 或者: from pymei.MeiDocument import root [as 别名]
    def test_documentpointers(self):
        mei = MeiElement("mei")
        mus = MeiElement("music")
        body = MeiElement("body")
        staff = MeiElement("staff")
        staff2 = MeiElement("staff")
        n1 = MeiElement("note")
        n2 = MeiElement("note")
        n3 = MeiElement("note")

        self.assertEqual(None, mei.document)
        mei.addChild(mus)
        self.assertEqual(None, mus.document)

        doc = MeiDocument()
        mus.addChild(body)
        doc.root = mei

        self.assertEqual(doc, mei.document)
        self.assertEqual(doc, mus.document)
        self.assertEqual(doc, body.document)

        self.assertEqual(None, staff.document)
        body.addChild(staff)
        self.assertEqual(doc, staff.document)
开发者ID:Breakend,项目名称:libmei,代码行数:27,代码来源:meidocument_test.py

示例2: test_elementsbyname

# 需要导入模块: from pymei import MeiDocument [as 别名]
# 或者: from pymei.MeiDocument import root [as 别名]
    def test_elementsbyname(self):
        mei = MeiElement("mei")
        mus = MeiElement("music")
        body = MeiElement("body")
        staff = MeiElement("staff")
        staff2 = MeiElement("staff")
        n1 = MeiElement("note")
        n2 = MeiElement("note")
        n3 = MeiElement("note")
        n4 = MeiElement("note")

        mei.addChild(mus)
        mus.addChild(body)
        body.addChild(staff)
        body.addChild(staff2)
        staff.addChild(n1)
        staff.addChild(n2)
        staff.addChild(n3)
        staff2.addChild(n4)

        doc = MeiDocument()

        doc.root = mei

        notes = doc.getElementsByName("note")
        self.assertEqual(4, len(notes))

        rests = doc.getElementsByName("rest")
        self.assertEqual(0, len(rests))

        n5 = MeiElement("note")
        staff2.addChild(n5)
        notes_new = doc.getElementsByName('note')
        self.assertEqual(5, len(notes_new))
开发者ID:lpugin,项目名称:libmei,代码行数:36,代码来源:meidocument_test.py

示例3: test_getpositionindocument

# 需要导入模块: from pymei import MeiDocument [as 别名]
# 或者: from pymei.MeiDocument import root [as 别名]
    def test_getpositionindocument(self):
        m = MeiElement("mei")
        m1 = MeiElement("music")
        musicid = m1.id
        b1 = MeiElement("body")
        s1 = MeiElement("staff")
        n1 = MeiElement("note")
        noteid = n1.id
        n2 = MeiElement("note")
        n3 = MeiElement("note")
        n4 = MeiElement("note")
        note4id = n4.id

        m.addChild(m1)
        m1.addChild(b1)
        b1.addChild(s1)
        s1.addChild(n1)
        s1.addChild(n2)
        s1.addChild(n3)

        doc = MeiDocument()
        doc.root = m

        self.assertEqual(4, n1.getPositionInDocument())

        # an unattached element will return -1
        self.assertEqual(-1, n4.getPositionInDocument())
开发者ID:gburlet,项目名称:libmei,代码行数:29,代码来源:meielement_test.py

示例4: test_documentwritefailure

# 需要导入模块: from pymei import MeiDocument [as 别名]
# 或者: from pymei.MeiDocument import root [as 别名]
 def test_documentwritefailure(self):
     doc = MeiDocument()
     root = MeiElement("mei")
     root.id = "myid"
     doc.root = root
     with self.assertRaises(FileWriteFailureException) as cm:
         ret = XmlExport.meiDocumentToFile(doc, "C:/StupidPath")
     self.assertTrue(isinstance(cm.exception, FileWriteFailureException))
开发者ID:lpugin,项目名称:libmei,代码行数:10,代码来源:xmlexport_test.py

示例5: test_exporttostring

# 需要导入模块: from pymei import MeiDocument [as 别名]
# 或者: from pymei.MeiDocument import root [as 别名]
    def test_exporttostring(self):
        doc = MeiDocument()
        root = MeiElement("mei")
        root.id = "myid"
        doc.root = root

        expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<mei xml:id=\"myid\" xmlns=\"http://www.music-encoding.org/ns/mei\" meiversion=\"2013\" />\n"
        ret = documentToText(doc)
        self.assertEqual(expected, ret)
开发者ID:AFFogarty,项目名称:libmei,代码行数:11,代码来源:xmlexport_test.py

示例6: test_flattenedtree

# 需要导入模块: from pymei import MeiDocument [as 别名]
# 或者: from pymei.MeiDocument import root [as 别名]
    def test_flattenedtree(self):
        mei = MeiElement("mei")
        mus = MeiElement("music")
        body = MeiElement("body")
        staff = MeiElement("staff")
        staff2 = MeiElement("staff")
        n1 = MeiElement("note")
        n2 = MeiElement("note")
        n3 = MeiElement("note")

        doc = MeiDocument()

        mei.addChild(mus)

        doc.root = mei

        mus.addChild(body)
        body.addChild(staff)
        body.addChild(staff2)
        staff.addChild(n1)
        staff.addChild(n2)
        staff2.addChild(n3)

        doc.lookBack(n2, "mei")
        self.assertEqual(8, len(doc.getFlattenedTree()))

        staff.removeChild(n2)
        self.assertEqual(7, len(doc.getFlattenedTree()))

        self.assertEqual(staff2, doc.getFlattenedTree()[5])

        staff.removeChildrenWithName("note")
        self.assertEqual(6, len(doc.getFlattenedTree()))

        body.deleteAllChildren()
        self.assertEqual(3, len(doc.getFlattenedTree()))

        children = MeiElementList()
        staff3 = MeiElement("staff")
        staff4 = MeiElement("staff")
        children.append(staff3)
        children.append(staff4)

        body.children = children

        self.assertEqual(5, len(doc.getFlattenedTree()))

        elements = [mei, mus, body, staff3, staff4]

        for i,el in enumerate(doc.getFlattenedTree()):
            self.assertEqual(elements[i], doc.getFlattenedTree()[i])
开发者ID:lpugin,项目名称:libmei,代码行数:53,代码来源:meidocument_test.py

示例7: test_exportcomment

# 需要导入模块: from pymei import MeiDocument [as 别名]
# 或者: from pymei.MeiDocument import root [as 别名]
    def test_exportcomment(self):
        doc = MeiDocument()
        root = MeiElement("mei")
        root.id = "myid"

        doc.root = root

        comment = MeiElement("_comment")
        comment.value = "comment"
        comment.tail = "t"

        root.addChild(comment)
        expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<mei xml:id=\"myid\" xmlns=\"http://www.music-encoding.org/ns/mei\" meiversion=\"2013\">\n\t<!--comment-->t</mei>\n"
        ret = documentToText(doc)
        self.assertEqual(expected, ret)
开发者ID:AFFogarty,项目名称:libmei,代码行数:17,代码来源:xmlexport_test.py

示例8: test_exportnamespace

# 需要导入模块: from pymei import MeiDocument [as 别名]
# 或者: from pymei.MeiDocument import root [as 别名]
    def test_exportnamespace(self):
        doc = MeiDocument()
        root = MeiElement("mei")
        root.id = "myid"
        doc.root = root

        xlink = MeiNamespace("xlink", "http://www.w3.org/1999/xlink")
        attr = MeiAttribute(xlink, "title", "my awesome thing")
        root.addAttribute(attr)

        expected = "<?xml version=\"1.0\"?>\n<mei xmlns=\"http://www.music-encoding.org/ns/mei\" \
xmlns:xlink=\"http://www.w3.org/1999/xlink\" xml:id=\"myid\" xlink:title=\"my awesome thing\" meiversion=\"2013\"/>\n";

        ret = XmlExport.meiDocumentToText(doc)
        self.assertEqual(expected, ret)
开发者ID:lpugin,项目名称:libmei,代码行数:17,代码来源:xmlexport_test.py

示例9: test_exportvalueandtail

# 需要导入模块: from pymei import MeiDocument [as 别名]
# 或者: from pymei.MeiDocument import root [as 别名]
    def test_exportvalueandtail(self):
        doc = MeiDocument()
        root = MeiElement("mei")
        root.id = "myid"
        doc.root = root

        note = MeiElement("note")
        note.id = "noteid"
        note.value = "value"
        note.tail = "tail"
        root.addChild(note)

        expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<mei xml:id=\"myid\" xmlns=\"http://www.music-encoding.org/ns/mei\" meiversion=\"2013\">\n\t<note xml:id=\"noteid\">value</note>tail</mei>\n"
        ret = documentToText(doc)

        self.assertEqual(expected, ret)
开发者ID:AFFogarty,项目名称:libmei,代码行数:18,代码来源:xmlexport_test.py

示例10: test_exportProcessingInstructions

# 需要导入模块: from pymei import MeiDocument [as 别名]
# 或者: from pymei.MeiDocument import root [as 别名]
    def test_exportProcessingInstructions(self):
        procinst = XmlInstructions()

        xpi1 = XmlProcessingInstruction("xml-model", "href=\"mei-2012.rng\" type=\"application/xml\" schematypens=\"http://purl.oclc.org/dsdl/schematron\"")
        xpi2 = XmlProcessingInstruction("xml-stylesheet", "href=\"mei-2012.rng\" type=\"application/xml\" schematypens=\"http://purl.oclc.org/dsdl/schematron\"")

        procinst.extend([xpi1, xpi2])

        doc = MeiDocument()
        root = MeiElement("mei")
        root.id = "myid"
        doc.root = root

        ret = XmlExport.meiDocumentToText(doc, procinst)

        expected = "<?xml version=\"1.0\"?>\n<?xml-model href=\"mei-2012.rng\" type=\"application/xml\" \
schematypens=\"http://purl.oclc.org/dsdl/schematron\"?>\n<?xml-stylesheet href=\"mei-2012.rng\" type=\"application/xml\" \
schematypens=\"http://purl.oclc.org/dsdl/schematron\"?>\n<mei xmlns=\"http://www.music-encoding.org/ns/mei\" \
xml:id=\"myid\" meiversion=\"2013\"/>\n"

        self.assertEqual(expected, ret)
开发者ID:lpugin,项目名称:libmei,代码行数:23,代码来源:xmlexport_test.py

示例11: test_elementbyid

# 需要导入模块: from pymei import MeiDocument [as 别名]
# 或者: from pymei.MeiDocument import root [as 别名]
    def test_elementbyid(self):
        mei = MeiElement("mei")
        mus = MeiElement("music")
        body = MeiElement("body")
        staff = MeiElement("staff")
        staff2 = MeiElement("staff")
        n1 = MeiElement("note")
        wantedId = n1.id
        n2 = MeiElement("note")
        n3 = MeiElement("note")
        n4 = MeiElement("note")

        mei.addChild(mus)
        mus.addChild(body)
        body.addChild(staff)
        body.addChild(staff2)
        staff.addChild(n1)
        staff.addChild(n2)
        staff.addChild(n3)
        staff2.addChild(n4)

        doc = MeiDocument()
        self.assertEqual(None, doc.getElementById(wantedId))

        doc.root = mei

        self.assertEqual(n1, doc.getElementById(wantedId))

        self.assertEqual(None, doc.getElementById("unknownID"))

        n5 = MeiElement("note")
        newid = n5.id
        staff2.addChild(n5)

        self.assertEqual(n5, doc.getElementById(newid))
        staff2.removeChild(n5)
        self.assertEqual(None, doc.getElementById(newid))
开发者ID:lpugin,项目名称:libmei,代码行数:39,代码来源:meidocument_test.py

示例12: test_getroot

# 需要导入模块: from pymei import MeiDocument [as 别名]
# 或者: from pymei.MeiDocument import root [as 别名]
    def test_getroot(self):
        doc = MeiDocument()
        mei = MeiElement("mei")
        doc.root = mei

        self.assertEqual(mei, doc.root)
开发者ID:lpugin,项目名称:libmei,代码行数:8,代码来源:meidocument_test.py


注:本文中的pymei.MeiDocument.root方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。