Beispiel #1
0
class TestPitch(TestCase):
    def setUp(self):
        self.pitch = Pitch()

    def test_to_string(self):
        result = '<pitch>\n  <step>C</step>\n  <octave>4</octave>\n</pitch>\n'
        self.assertEqual(self.pitch.to_string(), result)

    def test_arguments(self):
        pitch = Pitch(Step('D'), octave=Octave(7), alter=Alter(1.5))
        result = '<pitch>\n  <step>D</step>\n  <alter>1.5</alter>\n  <octave>7</octave>\n</pitch>\n'
        self.assertEqual(pitch.to_string(), result)

    def test_change_alter_1(self):
        self.pitch.alter = Alter(-1)
        result = '<pitch>\n  <step>C</step>\n  <alter>-1</alter>\n  <octave>4</octave>\n</pitch>\n'
        self.assertEqual(self.pitch.to_string(), result)

    def test_change_alter_2(self):
        self.pitch.alter = Alter(-1)
        self.pitch.alter = Alter(1)
        result = '<pitch>\n  <step>C</step>\n  <alter>1</alter>\n  <octave>4</octave>\n</pitch>\n'
        self.assertEqual(self.pitch.to_string(), result)

    def test_set_children(self):
        pitch = Pitch(step='E')
        result = '<pitch>\n  <step>E</step>\n  <octave>4</octave>\n</pitch>\n'
        self.assertEqual(pitch.to_string(), result)
Beispiel #2
0
    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())
Beispiel #3
0
 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 #4
0
    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)
Beispiel #5
0
    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)
Beispiel #6
0
    def test_2(self):
        # accidental
        self.note.accidental.show = False
        self.note.add_child(Duration(int(self.note.quarter_duration)))
        self.note.event = Pitch(step='A', alter=-1.5)
        self.note.accidental.show = True
        result = '''<note>
  <pitch>
    <step>A</step>
    <alter>-1.5</alter>
    <octave>4</octave>
  </pitch>
  <duration>2</duration>
  <accidental>three-quarters-flat</accidental>
</note>
'''
        self.assertEqual(self.note.to_string(), result)
Beispiel #7
0
    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)
Beispiel #8
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 #9
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 #10
0
 def test_set_children(self):
     pitch = Pitch(step='E')
     result = '<pitch>\n  <step>E</step>\n  <octave>4</octave>\n</pitch>\n'
     self.assertEqual(pitch.to_string(), result)
Beispiel #11
0
 def test_arguments(self):
     pitch = Pitch(Step('D'), octave=Octave(7), alter=Alter(1.5))
     result = '<pitch>\n  <step>D</step>\n  <alter>1.5</alter>\n  <octave>7</octave>\n</pitch>\n'
     self.assertEqual(pitch.to_string(), result)
Beispiel #12
0
    def test_add_child_max_occurrence(self):
        self.note.add_child(Pitch())

        with self.assertRaises(ChildOccurrenceDTDConflict):
            self.note.add_child(Pitch())
Beispiel #13
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'))
Beispiel #14
0
 def setUp(self):
     self.pitch = Pitch()
Beispiel #15
0
 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))
Beispiel #16
0
 def setUp(self):
     self.note = Note()
     self.note.add_child(Duration())
     self.note.add_child(Pitch())
Beispiel #17
0
 def get_pitch_rest(self):
     if self.value == 0:
         return Rest()
     else:
         return Pitch(*self.get_pitch_name())