Beispiel #1
0
 def setUp(self):
     self.note = Note()
     # self.dtd = note_dtd.__deepcopy__()
     self.note.add_xml_child(Instrument())
     self.note.add_xml_child(Rest())
     self.note.add_xml_child(Duration())
     self.note.add_xml_child(Type('quarter'))
Beispiel #2
0
    def setUp(self):
        self.score = Score()
        self.score.version = '3.0'
        part_list = self.score.add_child(PartList())
        score_part = part_list.add_child(ScorePart(id='P1'))
        score_part.add_child(PartName(name="Oboe"))
        score_part.add_child(PartAbbreviation("Ob."))

        measure = self.score.add_child(Measure(number='1'))
        part = measure.add_child(Part(id='P1'))
        attributes = part.add_child(Attributes())
        attributes.add_child(Divisions(2))
        time = attributes.add_child(Time())
        time.add_child(Beats(4))
        time.add_child(BeatType(4))
        clef = attributes.add_child(Clef())
        clef.add_child(Sign('G'))
        clef.add_child(Line(2))
        note = part.add_child(Note())
        note.add_child(Rest(measure='yes'))
        note.add_child(Duration(8))

        measure = self.score.add_child(Measure(number='2'))
        part = measure.add_child(Part(id='P1'))
        attributes = part.add_child(Attributes())
        attributes.add_child(Divisions(2))
        note = part.add_child(Note())
        note.add_child(Rest(measure='yes'))
        note.add_child(Duration(8))
Beispiel #3
0
    def test_1(self):
        part = Part(id='P1')
        attributes = part.add_child(Attributes())
        attributes.add_child(Divisions(2))
        d = part.add_child(Direction())
        dt = d.add_child(DirectionType())
        dt.add_child(Words(value='bla'))
        note = part.add_child(Note())
        note.add_child(Rest())
        note.add_child(Duration(8))

        result = '''<part id="P1">
  <attributes>
    <divisions>2</divisions>
  </attributes>
  <direction>
    <direction-type>
      <words>bla</words>
    </direction-type>
  </direction>
  <note>
    <rest/>
    <duration>8</duration>
  </note>
</part>
'''
        self.assertEqual(part.to_string(), result)
Beispiel #4
0
    def test_lyrics(self):
        self.note = Note()
        self.note.add_child(Pitch())
        self.note.add_child(Duration())
        self.note.add_child(Lyric()).add_child(Text('lyric 1'))
        self.note.add_child(Lyric(number='2')).add_child(Text('lyric 2'))
        result = '''<note>
  <pitch>
    <step>C</step>
    <octave>4</octave>
  </pitch>
  <duration>1</duration>
  <lyric number="1">
    <text>lyric 1</text>
  </lyric>
  <lyric number="2">
    <text>lyric 2</text>
  </lyric>
</note>
'''
        self.assertEqual(self.note.to_string(), result)
Beispiel #5
0
class Test(TestCase):
    def setUp(self):
        self.note = Note()
        self.note.add_child(Duration())
        self.note.add_child(Pitch())

    def test_1(self):
        notations = self.note.add_child(Notations())
        articulations = notations.add_child(Articulations())
        articulations.add_child(Accent())
        articulations.add_child(Staccato(relative_y=20))

        result = """<note>
  <pitch>
    <step>C</step>
    <octave>4</octave>
  </pitch>
  <duration>1</duration>
  <notations>
    <articulations>
      <accent/>
      <staccato relative-y="20"/>
    </articulations>
  </notations>
</note>
"""
        self.assertEqual(self.note.to_string(), result)
Beispiel #6
0
class Test(TestCase):
    def setUp(self):
        self.note = Note()
        self.note.add_child(Duration())
        self.note.add_child(Pitch())

    def test_1(self):
        notations = self.note.add_child(Notations())
        technical = notations.add_child(Technical())
        hole = technical.add_child(Hole())
        hole.add_child(HoleClosed(value='no'))
        technical.add_child(SnapPizzicato(relative_y=20))

        result = """<note>
  <pitch>
    <step>C</step>
    <octave>4</octave>
  </pitch>
  <duration>1</duration>
  <notations>
    <technical>
      <hole>
        <hole-closed>no</hole-closed>
      </hole>
      <snap-pizzicato relative-y="20"/>
    </technical>
  </notations>
</note>
"""
        self.assertEqual(self.note.to_string(), result)
Beispiel #7
0
class Test(TestCase):
    def setUp(self) -> None:
        self.note = Note()
        self.note.add_child(Pitch())
        self.note.add_child(Duration())

    def test_voice(self):
        self.note.add_child(Voice('1'))
        result = '''<note>
  <pitch>
    <step>C</step>
    <octave>4</octave>
  </pitch>
  <duration>1</duration>
  <voice>1</voice>
</note>
'''
        self.assertEqual(self.note.to_string(), result)
Beispiel #8
0
class TestNoteBeamDTD(TestCase):
    def setUp(self):
        self.note = Note()
        self.note.add_child(Pitch())
        self.note.add_child(Duration())

    def test_note_beam(self):
        self.note.add_child(Beam('begin', number=2))
        result = '''<note>
  <pitch>
    <step>C</step>
    <octave>4</octave>
  </pitch>
  <duration>1</duration>
  <beam number="2">begin</beam>
</note>
'''
        self.assertEqual(self.note.to_string(), result)
Beispiel #9
0
    def setUp(self):
        self.score = Score()
        self.score.version = '3.0'
        part_list = self.score.add_child(PartList())
        score_part = part_list.add_child(ScorePart(id='P1'))
        score_part.add_child(PartName(name="Oboe", print_object='yes'))

        part = self.score.add_child(Part(id='P1'))
        measure = part.add_child(Measure(number='1'))
        attributes = measure.add_child(Attributes())
        attributes.add_child(Divisions(1))
        time = attributes.add_child(Time())
        time.add_child(Beats(4))
        time.add_child(BeatType(4))
        clef = attributes.add_child(Clef())
        clef.add_child(Sign('G'))
        clef.add_child(Line(2))
        note = measure.add_child(Note())
        note.add_child(Pitch())
        note.add_child(Duration(4))
Beispiel #10
0
class TestAccidentalDTD(TestCase):
    def setUp(self):
        self.note = Note()
        self.note.add_child(Duration())
        pitch = self.note.add_child(Pitch())
        pitch.add_child(Alter(1))
        self.note.add_child(Accidental('sharp'))

    def test_accidental(self):
        result = '''<note>
  <pitch>
    <step>C</step>
    <alter>1</alter>
    <octave>4</octave>
  </pitch>
  <duration>1</duration>
  <accidental>sharp</accidental>
</note>
'''
        self.assertEqual(self.note.to_string(), result)
Beispiel #11
0
 def setUp(self):
     self.note = Note()
     self.note.add_child(Duration())
     self.note.add_child(Pitch())
 def test_add_note(self):
     part = self.measure.add_child(timewise.Part(id='bla'))
     note = part.add_child(Note())
     note.add_child(Beam('end'))
     with self.assertRaises(TypeError):
         self.measure.number = 3
Beispiel #13
0
 def setUp(self):
     self.note = Note()
Beispiel #14
0
class TestNoteDTD(TestCase):
    def setUp(self):
        self.note = Note()

    def test_add_chord(self):

        ch = self.note.add_child(Chord())
        self.note.add_child(Pitch())
        self.note.add_child(Grace())
        with self.assertRaises(Exception):
            ch.add_child(Rest())

    def test_add_child_type(self):
        self.note.add_child(Pitch())
        self.note.add_child(Grace())
        with self.assertRaises(ChildTypeDTDConflict):
            self.note.add_child(Duration(1))

    def test_add_child_max_occurrence(self):
        self.note.add_child(Pitch())

        with self.assertRaises(ChildOccurrenceDTDConflict):
            self.note.add_child(Pitch())

    def test_close_1(self):
        self.note.add_child(Rest())
        self.note.add_child(Grace())
        self.note.close_dtd()
        result = [
            'Grace', 'Chord', 'Rest', 'Instrument', 'FootNote', 'Level',
            'Voice', 'Type', 'Dot', 'Accidental', 'TimeModification', 'Stem',
            'Notehead', 'NoteheadText', 'StaffElement', 'Beam', 'Notations',
            'Lyric', 'Play'
        ]
        self.assertEqual([
            node.type_.__name__
            for node in self.note.current_dtd_choice.traverse_leaves()
        ], result)

    def test_close_2(self):
        self.note.add_child(Rest())
        with self.assertRaises(ChildIsNotOptional):
            self.note.close_dtd()

    def test_sort_children(self):
        self.note.add_child(Pitch())
        self.note.add_child(Beam('begin'))
        self.note.add_child(Tie())
        self.note.add_child(Beam('continue'))
        self.note.add_child(Duration(1))
        self.note.add_child(Tie())
        self.note.close_dtd()

        result = ['Pitch', 'Duration', 'Tie', 'Tie', 'Beam', 'Beam']
        self.assertEqual(
            [type(child).__name__ for child in self.note.get_children()],
            result)

    def test_grace(self):
        self.note.add_child(Pitch())
        grace = Grace()
        grace.slash = 'yes'
        grace.make_time = 101
        with self.assertRaises(ValueError):
            grace.steal_time_following = 120

        grace.steal_time_following = 90
        self.note.add_child(grace)
        result = '''<note>
  <grace steal-time-following="90" make-time="101" slash="yes"/>
  <pitch>
    <step>C</step>
    <octave>4</octave>
  </pitch>
</note>
'''
        self.assertEqual(self.note.to_string(), result)

#     def test_to_string(self):
#         self.note.add_child(Pitch())
#         self.note.add_child(Beam('begin'))
#         self.note.add_child(Tie())
#         self.note.add_child(Beam('continue'))
#         self.note.add_child(Duration(1))
#         self.note.add_child(Tie())
#         self.note.add_child(Chord())
#         self.note.close()
#         result = '''<note>
#   <chord/>
#   <pitch>
#     <step>C</step>
#     <octave>4</octave>
#   </pitch>
#   <duration>1</duration>
#   <tie/>
#   <tie/>
#   <beam number="1">begin</beam>
#   <beam number="1">continue</beam>
# </note>
# '''
#         self.assertEqual(self.note.to_string(), result)

    def test_rest(self):
        rest = self.note.add_child(Rest())
        self.note.add_child(Duration(1))
#         rest.add_child(DisplayOctave(4))
#         rest.add_child(DisplayStep('B'))
#         result = '''<note>
#   <rest>
#     <display-step>B</display-step>
#     <display-octave>4</display-octave>
#   </rest>
#   <duration>1</duration>
# </note>
# '''
#         self.assertEqual(self.note.to_string(), result)

    def test_type(self):
        self.note.add_child(Pitch())
        self.note.add_child(Duration())
        self.note.add_child(Type(value='quarter'))
        result = '''<note>
  <pitch>
    <step>C</step>
    <octave>4</octave>
  </pitch>
  <duration>1</duration>
  <type>quarter</type>
</note>
'''
        self.assertEqual(self.note.to_string(), result)

    def test_lyrics(self):
        self.note = Note()
        self.note.add_child(Pitch())
        self.note.add_child(Duration())
        self.note.add_child(Lyric()).add_child(Text('lyric 1'))
        self.note.add_child(Lyric(number='2')).add_child(Text('lyric 2'))
        result = '''<note>
  <pitch>
    <step>C</step>
    <octave>4</octave>
  </pitch>
  <duration>1</duration>
  <lyric number="1">
    <text>lyric 1</text>
  </lyric>
  <lyric number="2">
    <text>lyric 2</text>
  </lyric>
</note>
'''
        self.assertEqual(self.note.to_string(), result)
Beispiel #15
0
class TestNoteDtd(TestCase):
    def setUp(self):
        self.note = Note()
        # self.dtd = note_dtd.__deepcopy__()
        self.note.add_xml_child(Instrument())
        self.note.add_xml_child(Rest())
        self.note.add_xml_child(Duration())
        self.note.add_xml_child(Type('quarter'))

    def test_dtd_note_1(self):
        with self.assertRaises(ChildTypeDTDConflict):
            self.note.add_xml_child(Unpitched())

    def test_dtd_note_2(self):
        with self.assertRaises(ChildOccurrenceDTDConflict):
            self.note.add_xml_child(Instrument())

    def test_dtd_note_3(self):
        self.note.add_xml_child(Tie())
        self.note.add_xml_child(Tie())

        result = ['Rest', 'Duration', 'Tie', 'Tie', 'Instrument', 'Type']
        self.assertEqual([type(xml_child).__name__ for xml_child in self.note.current_children], result)

        with self.assertRaises(ChildOccurrenceDTDConflict):
            self.note.add_xml_child(Tie())

    def test_dtd_pitch(self):
        p = Pitch()
        result = ['Step', 'Octave']
        self.assertEqual([type(child).__name__ for child in p.get_children()], result)
        p.add_child(Alter(2))
        result = ['Step', 'Alter', 'Octave']
        self.assertEqual([type(child).__name__ for child in p.get_children()], result)
Beispiel #16
0
    def test_add_note(self):
        note = Note()
        note.add_child(Rest())
        note.add_child(Duration(2))
        self.part.add_child(note)

        note = Note()
        note.add_child(Rest())
        note.add_child(Duration(2))
        result = '''<part id="p1">
  <attributes>
    <divisions>1</divisions>
  </attributes>
  <note>
    <rest/>
    <duration>2</duration>
  </note>
</part>
'''
        self.assertEqual(self.part.to_string(), result)
Beispiel #17
0
 def setUp(self):
     self.note = Note()
     self.note.add_child(Duration())
     pitch = self.note.add_child(Pitch())
     pitch.add_child(Alter(1))
     self.note.add_child(Accidental('sharp'))