def test_flats(self): parser = ParserCantusVolpiano(root='alteration') parse = parser.parser.parse('i') alteration = visitParseTree(parse, VisitorCantusVolpiano()) self.assertIsInstance(alteration, chant.Alteration) self.assertIsInstance(alteration, chant.Flat) self.assertEqual(alteration.editorial.volpiano, 'i') self.assertEqual(alteration.editorial.volpianoPosition, 'j') # High e flat parse = parser.parser.parse('x') alteration = visitParseTree(parse, VisitorCantusVolpiano()) self.assertIsInstance(alteration, chant.Flat) self.assertEqual(alteration.editorial.volpianoPosition, 'm') # Low e flat parse = parser.parser.parse('w') alteration = visitParseTree(parse, VisitorCantusVolpiano()) self.assertIsInstance(alteration, chant.Flat) self.assertEqual(alteration.editorial.volpianoPosition, 'e') # Low b flat parse = parser.parser.parse('y') alteration = visitParseTree(parse, VisitorCantusVolpiano()) self.assertIsInstance(alteration, chant.Flat) self.assertEqual(alteration.editorial.volpianoPosition, 'b') # High b flat parse = parser.parser.parse('z') alteration = visitParseTree(parse, VisitorCantusVolpiano()) self.assertIsInstance(alteration, chant.Flat) self.assertEqual(alteration.editorial.volpianoPosition, 'q')
def test_naturals(self): parser = ParserCantusVolpiano(root='alteration') parse = parser.parser.parse('I') alteration = visitParseTree(parse, VisitorCantusVolpiano()) self.assertIsInstance(alteration, chant.Alteration) self.assertIsInstance(alteration, chant.Natural) self.assertEqual(alteration.editorial.volpiano, 'I') self.assertEqual(alteration.editorial.volpianoPosition, 'j') # High e flat parse = parser.parser.parse('X') alteration = visitParseTree(parse, VisitorCantusVolpiano()) self.assertIsInstance(alteration, chant.Natural) self.assertEqual(alteration.editorial.volpianoPosition, 'm') # Low e flat parse = parser.parser.parse('W') alteration = visitParseTree(parse, VisitorCantusVolpiano()) self.assertIsInstance(alteration, chant.Natural) self.assertEqual(alteration.editorial.volpianoPosition, 'e') # Low b flat parse = parser.parser.parse('Y') alteration = visitParseTree(parse, VisitorCantusVolpiano()) self.assertIsInstance(alteration, chant.Natural) self.assertEqual(alteration.editorial.volpianoPosition, 'b') # High b flat parse = parser.parser.parse('Z') alteration = visitParseTree(parse, VisitorCantusVolpiano()) self.assertIsInstance(alteration, chant.Natural) self.assertEqual(alteration.editorial.volpianoPosition, 'q')
def test_flatClefs(self): """Test whether flats are NOT reset by syllable boundaries""" parser = ParserGABC(root='body') parse = parser.parse('(cb2) (e)') stream = visitParseTree(parse, VisitorGABC()) notes = stream.flat.notes self.assertEqual(notes[0].name, 'B-')
def test_macros(self): """Test whether a file with macro's is converted properly despite them""" parser = ParserGABC(root='file') parse = parser.parse( '%%\ndef-m1:\grealign;\ndef-m2:\grealign;\n(c2) a(f)') elements = visitParseTree(parse, VisitorGABC()) self.assertTrue(True)
def test_f_clef(self): # TODO not really supported yet parser = ParserCantusVolpiano(root='clef') parse = parser.parser.parse('2') clef = visitParseTree(parse, VisitorCantusVolpiano()) self.assertIsInstance(clef, chant.Clef) self.assertEqual(clef.editorial.volpiano, '2')
def test_word(self): parser = ParserCantusVolpiano(root='word') parse = parser.parser.parse('fg-h--f--g') word = visitParseTree(parse, VisitorCantusVolpiano()) self.assertIsInstance(word, chant.Word) self.assertEqual(len(word), 3) self.assertIsInstance(word[0], chant.Syllable)
def test_syllable(self): parser = ParserCantusVolpiano(root='syllable') parse = parser.parser.parse('fg-h-g') syll = visitParseTree(parse, VisitorCantusVolpiano()) self.assertIsInstance(syll, chant.Syllable) self.assertEqual(len(syll), 3) self.assertIsInstance(syll[0], chant.Neume)
def test_neume(self): parser = ParserCantusVolpiano(root='neume') parse = parser.parser.parse('fg') neume = visitParseTree(parse, VisitorCantusVolpiano()) self.assertIsInstance(neume, chant.Neume) self.assertEqual(len(neume), 2) self.assertIsInstance(neume[0], chant.Note)
def test_clefs(self): parser = ParserGABC(root='clef') for clef in ['c1', 'c2', 'c3', 'c4', 'f3', 'f4', 'cb3', 'cb4']: parse = parser.parse(clef) element = visitParseTree(parse, VisitorGABC()) self.assertIsInstance(element, clef21.TrebleClef) self.assertEqual(element.editorial.gabc, clef)
def test_multipleNeumes(self): parser = ParserGABC(root='syllable') parse = parser.parse('A(fg/fg)') syllable = visitParseTree(parse, VisitorGABC()) self.assertEqual(syllable.lyric, 'A') self.assertEqual(len(syllable.flat.notes), 4) self.assertEqual(len(syllable), 2)
def test_mergeWords3(self): gabc = "(c4) A(f) (,) (c) B(g)" parser = ParserGABC() parse = parser.parse(gabc) ch = visitParseTree(parse, VisitorGABC()) ch.joinTextAcrossPausas() self.assertEqual(len(ch[0].elements), 3)
def test_polyphonicAlterations(self): parser = ParserGABC(root='music') parse = parser.parse('f{ix}g') elements = visitParseTree(parse, VisitorGABC()) n1, alt, n2 = elements self.assertIsInstance(n1, chant.Neume) self.assertIsInstance(alt, chant.Flat) self.assertIsInstance(n2, chant.Neume)
def test_notePrefix(self): parser = ParserGABC(root='note') parse = parser.parse('-f') note = visitParseTree(parse, VisitorGABC()) ed = note.editorial self.assertEqual(ed.gabcPosition, 'f') self.assertEqual(ed.gabcPrefix, '-') self.assertTrue(ed.liquescence)
def test_multipleSuffixes(self): parser = ParserGABC(root='note') parse = parser.parse('go1') n = visitParseTree(parse, VisitorGABC()) suffixes = n.editorial.gabcSuffixes self.assertTrue({'neumeShape': 'o'} in suffixes) self.assertTrue({'neumeShape': '1'} in suffixes) self.assertEqual(n.editorial.gabcPosition, 'g')
def test_liquescent(self): parser = ParserCantusVolpiano(root='liquescent') parse = parser.parser.parse('F') note = visitParseTree(parse, VisitorCantusVolpiano()) self.assertIsInstance(note, chant.Note) self.assertEqual(note.editorial.volpianoPosition, 'f') self.assertEqual(note.editorial.liquescence, True) self.assertEqual(note.notehead, 'x')
def test_noteSuffixes(self): parser = ParserGABC(root='note') parse = parser.parse('fs<.') note = visitParseTree(parse, VisitorGABC()) ed = note.editorial self.assertEqual(ed.gabcPosition, 'f') self.assertTrue({'neumeShape': 's<'} in ed.gabcSuffixes) self.assertTrue({'rhythmicSign': '.'} in ed.gabcSuffixes)
def test_multipleHeaders(self): parser = ParserGABC() fileStr = 'attr1:value1;\n%%\nattr2:value2;\n%%\n(c2) A(f)' parse = parser.parse(fileStr) ch = visitParseTree(parse, VisitorGABC()) metadata = {'attr1': 'value1', 'attr2': 'value2'} self.assertEqual(metadata['attr1'], 'value1') self.assertEqual(metadata['attr2'], 'value2')
def test_multipleSyllablesWithCommas2(self): """Test whether syllables separated by commas are correctly merged; including the last one""" parser = ParserGABC(root='word') gabc = 'a(f)(,)(f)(,)(f)' parse = parser.parse(gabc) word = visitParseTree(parse, VisitorGABC()) word.joinSyllablesAcrossPausas() self.assertEqual(len(word), 1)
def test_syllable(self): parser = ParserGABC(root='syllable') parse = parser.parse('A(f)') syll = visitParseTree(parse, VisitorGABC()) obj = syll.toObject() self.assertEqual(len(obj['elements']), 1) del obj['elements'] targetObj = {'type': 'syllable', 'lyric': 'A'} self.assertDictEqual(obj, targetObj)
def test_word(self): parser = ParserGABC(root='word') parse = parser.parse('A(f)B(g)') word = visitParseTree(parse, VisitorGABC()) obj = word.toObject() self.assertEqual(len(obj['elements']), 2) del obj['elements'] targetObj = {'type': 'word', 'musicAndTextAligned': None} self.assertDictEqual(obj, targetObj)
def test_twoSyllables(self): parser = ParserGABC(root='word') parse = parser.parse('s1(f)s2(f)') word = visitParseTree(parse, VisitorGABC()) syll1, syll2 = word.syllables lyric1 = syll1.flat.notes[0].lyrics[0] lyric2 = syll2.flat.notes[0].lyrics[0] self.assertEqual(lyric1.syllabic, 'begin') self.assertEqual(lyric2.syllabic, 'end')
def test_multipleNeumes(self): parser = ParserGABC(root='music') parse = parser.parse('eh/hi') elements = visitParseTree(parse, VisitorGABC()) self.assertEqual(len(elements), 2) self.assertIsInstance(elements[0], chant.Neume) self.assertEqual(len(elements[0]), 2) self.assertIsInstance(elements[1], chant.Neume) self.assertEqual(len(elements[1]), 2)
def test_breath_mark(self): """Test whether breath marks reset the accidentals""" parser = ParserGABC(root='body') parse = parser.parse('(c2) (exe,fe)') stream = visitParseTree(parse, VisitorGABC()) notes = stream.flat.notes self.assertEqual(notes[0].name, 'B-') self.assertEqual(notes[1].name, 'C') self.assertEqual(notes[2].name, 'B')
def test_wordBoundaries(self): """Test whether word boundaries reset accidentals""" parser = ParserGABC(root='body') parse = parser.parse('(c2) a(exfe) c(e)') stream = visitParseTree(parse, VisitorGABC()) notes = stream.flat.notes self.assertEqual(notes[0].name, 'C') self.assertEqual(notes[1].name, 'B-') self.assertEqual(notes[2].name, 'B')
def test_textAfterAccidental(self): parser = ParserGABC(root='body') parse = parser.parse('(c2) bla(eye)') ch = visitParseTree(parse, VisitorGABC()) word1, word2 = ch[0] self.assertIsNone(word1.flatLyrics) self.assertEqual(word2.flatLyrics, 'bla') note = word2.flat.notes[0] self.assertEqual(note.lyric, 'bla')
def test_alterations(self): parser = ParserGABC(root='alteration') for alteration in 'xy': parse = parser.parse(f'f{alteration}') element = visitParseTree(parse, VisitorGABC()) ed = element.editorial self.assertIsInstance(element, chant.Alteration) self.assertEqual(ed.gabcPosition, 'f') self.assertEqual(ed.gabcAlteration, alteration)
def test_syllableWithAnnotation(self): parser = ParserGABC(root='syllable') parse = parser.parse('*(:)') syll = visitParseTree(parse, VisitorGABC()) obj = syll.toObject() self.assertEqual(len(obj['elements']), 1) del obj['elements'] targetObj = {'annotation': '*', 'type': 'syllable'} self.assertDictEqual(obj, targetObj)
def test_fileWithoutHeader(self): parser = ParserGABC(root='file') fileStr = '(c2) a(f)b(g) c(h)\ni(j)' parse = parser.parse(fileStr) ch = visitParseTree(parse, VisitorGABC()) notes = ch.flat.notes self.assertEqual(notes[0].name, 'C') self.assertEqual(notes[1].name, 'D') self.assertEqual(notes[2].name, 'E') self.assertEqual(notes[3].name, 'G')
def test_articulationBeforeComma(self): parser = ParserGABC(root='body') parse = parser.parse("(c2) A(a,d)") ch = visitParseTree(parse, VisitorGABC()) ch.makeBreathMarks() clef, n1, n2 = ch.flat self.assertIsInstance(clef, chant.Clef) self.assertIsInstance(n1, chant.Note) self.assertIsInstance(n2, chant.Note) self.assertEqual(len(n1.articulations), 1)
def test_multipleSyllablesWithCommas(self): parser = ParserGABC(root='word') gabc = 'a(f)(,)(f)(,)(f)b(f)' parse = parser.parse(gabc) word = visitParseTree(parse, VisitorGABC()) word.joinSyllablesAcrossPausas() self.assertEqual(len(word), 2) syll1, syll2 = word.elements self.assertEqual(len(syll1.flat), 5) self.assertIsInstance(syll1.flat[1], chant.Pausa) self.assertEqual(len(syll2.flat), 1)