def test_numbered_chords(self): # Check that nashville/numbered chords are working song = books.cp_song("{title: A Song!}\nSome stuff\n{key: C}\n[C] [F] [G]", nashville=True) song.format() self.assertTrue("[I]" in song.md) self.assertTrue("[IV]" in song.md) self.assertTrue("[V]" in song.md) # Lowercase for minors song = books.cp_song("{title: A Song!}\nSome stuff\n{key: Cm}\n[Cm] [Fm] [G]", nashville=True) song.format() self.assertTrue("[i]" in song.md) self.assertTrue("[iv]" in song.md) self.assertTrue("[V]" in song.md) # Check that charts are working song = books.cp_song("{title: A Song!}\nSome stuff\n{key: Cm}\n[Cm] [Fm] [G]", nashville=True, major_chart=True) song.format() self.assertTrue("[vi]" in song.md) self.assertTrue("[ii]" in song.md) self.assertTrue("[III]" in song.md) # Check that we can change keys song = books.cp_song("{title: A Song!}\nSome stuff\n{key: C}\n[C] [F] [G]\n{key: G}\n [C] [F] [G]", nashville=True) song.format() self.assertTrue("[I]" in song.md) self.assertTrue("[IV]" in song.md) self.assertTrue("[V]" in song.md) # Should be variants for these cos of the key change self.assertTrue("[IV]" in song.md) self.assertTrue("[♭VII]" in song.md) self.assertTrue("[I]" in song.md)
def test_page_image_formatting(self): import re song = books.cp_song(""" {page_image: test.png} """, path="/this/is/my/path/song.cho.txt") print("TEST", song.text) self.assertTrue( song.text, re.search("<img src='file:///.*?' width='680'>", song.text))
def test_parse(self): song = books.cp_song("{title: A Song!}\nSome stuff\n{key: C#}\n") self.assertEqual(song.key, "C#") self.assertEqual(song.title, "A Song!") song = books.cp_song("{title: A Song!}\nSome stuff\n{key: C#}\n#A comment\n#or two", transpose=3) self.assertEqual(song.key, "E") song.format() self.assertEqual(song.to_html().replace("\n",''), '<div class="song"><div class="page"><h1 class="song-title">A Song! (E)</h1><div class="grids"></div><div class="song-page"><div class="song-text"><p>Some stuff</p></div></div></div></div>') # Test auto-apply of classes to lines beginning with a . song = books.cp_song("{title: A Song!}\nSome stuff\n{key: C#}\n.♂ Mark this up as class ♂ \n") self.assertEqual(song.key, "C#") self.assertEqual(song.title, "A Song!") self.assertEqual(song.text, "Some stuff \n<span class='♂'>♂ Mark this up as class ♂</span>\n\n") # Test that chords with rhythm don't get counted as separate chords song = books.cp_song(""" {title: Test} {soc} {c: Chorus} {instrument: Uke} This [C] is the [C!] chorus [Db7 / / / /] [C!] [Db7!] CHorus chorus {eoc} After the chorus """) song.format( instrument_name="Uke") # Should only be two chords in the above self.assertEqual(len(song.chords_used),2) # Test that chords with different names for the same thing are all counted song = books.cp_song(""" {title: Test} {soc} {c: Chorus} {instrument: Uke} This [BbM7] is the [Bbmaj7] chorus [A#M7] is the [A#maj7] chorus CHorus chorus {eoc} After the chorus """) song.format( instrument_name="Uke") # Should be four chords in the above, all the same, but not up to us to change what the author wrote self.assertEqual(len(song.chords_used),4) song = books.cp_song(""" {title: Test} {soc} {c: Chorus} This is the chorus CHorus chorus {eoc} After the chorus """) result = """ > **Chorus** > This is the chorus > CHorus chorus After the chorus """ self.assertEqual(song.text, result) song = books.cp_song(""" {title: Test} {sot} This is where some Preformatted Tab goes --5---5----5 1---2--2--2- 3-3-3-3-3-3- --9--9--9-9- {eot} After the tab """) result = """ ``` This is where some Preformatted Tab goes --5---5----5 1---2--2--2- 3-3-3-3-3-3- --9--9--9-9- ``` After the tab """ self.assertEqual(song.text, result) song = books.cp_song(""" {title: Test} {sot} This is where some Preformatted Tab goes --5---5----5 1---2--2--2- 3-3-3-3-3-3- --9--9--9-9- {soc} {c: Chorus} Where someone forgot to close the tab {eoc}""") result = """ ``` This is where some Preformatted Tab goes --5---5----5 1---2--2--2- 3-3-3-3-3-3- --9--9--9-9- > **Chorus** > Where someone forgot to close the tab """ self.assertEqual(song.text, result) song = books.cp_song(""" {title: Test} {start_of_chorus} {c: Here's a chorus with tab in it} {sot} This is where some Preformatted Tab goes --5---5----5 1---2--2--2- 3-3-3-3-3-3- --9--9--9-9- {eot} Still in the chorus {eoc} After the chorus """) result = """ > **Here's a chorus with tab in it** > This is where some > Preformatted > Tab goes > --5---5----5 > 1---2--2--2- > 3-3-3-3-3-3- > --9--9--9-9- > Still in the chorus After the chorus """ song = books.cp_song("{instrument: Thongaphone}") self.assertEqual( "Thongaphone", song.local_instruments.get_instrument_by_name("Thongaphone").name) self.assertEqual( "Thongaphone", song.local_instruments.get_instrument_by_name("Thongaphone").name) song = books.cp_song("{instrument: Thongaphone}\n{define: C#7 frets 0 1 0 1 0 1 0 1}\n{define: C#7-5 frets 0 1 0 1 0 1 0 1}") #song.instruments.get_instrument_by_name("Thongaphone").chart.get_default("C#7-5").show() self.assertEqual("{define: C#7-5 frets 0 1 0 1 0 1 0 1}", song.local_instruments.get_instrument_by_name("Thongaphone").chart.get_default("C#7-5").to_chordpro()) song = books.cp_song("{instrument: Uke}\n{define: C frets 12 12 12 15}") #song.instruments.get_instrument_by_name("Soprano Ukulele").chart.get_default("C").show() song.format(instrument_name = "Nope!") self.assertEqual("{define: C base-fret 11 frets 1 1 1 4}", song.local_instruments.get_instrument_by_name("Soprano Ukulele").chart.get_default("C").to_chordpro())
def test_auto_transpose(self): song1 = books.cp_song("{title: 1 page}\n{key: C}\n{transpose: +2 -3}") self.assertEqual(song1.standard_transpositions, [0, 2, -3])
def test_parse(self): song = books.cp_song("{title: A Song!}\nSome stuff\n{key: C#}\n") self.assertEqual(song.key, "C#") self.assertEqual(song.title, "A Song!") song = books.cp_song("{title: A Song!}\nSome stuff\n{key: C#}\n#A comment\n#or two", transpose=3) self.assertEqual(song.key, "E") song.format() print(song.to_html()) self.assertEqual(song.to_html().replace("\n",''), '<div class="song"><div class="page"><h1 class="song-title">A Song! (E)</h1><div class="grids"></div><div class="song-page"><div class="song-text"><p>Some stuff</p></div></div></div></div>') # Test auto-apply of classes to lines beginning with a . song = books.cp_song("{title: A Song!}\nSome stuff\n{key: C#}\n.♂ Mark this up as class ♂ \n") self.assertEqual(song.key, "C#") self.assertEqual(song.title, "A Song!") self.assertEqual(song.text, "Some stuff \n<span class='♂'>♂ Mark this up as class ♂</span>\n\n") # Test that chords with rhythm don't get counted as separate chords song = books.cp_song(""" {title: Test} {soc} {c: Chorus} {instrument: Uke} This [C] is the [C!] chorus [Db7 / / / /] [C!] [Db7!] CHorus chorus {eoc} After the chorus """) song.format( instrument_name="Uke") # Should only be two chords in the above self.assertEqual(len(song.chords_used),2) # Test that chords with different names for the same thing are all counted song = books.cp_song(""" {title: Test} {soc} {c: Chorus} {instrument: Uke} This [BbM7] is the [Bbmaj7] chorus [A#M7] is the [A#maj7] chorus CHorus chorus {eoc} After the chorus """) song.format( instrument_name="Uke") # Should be four chords in the above, all the same, but not up to us to change what the author wrote self.assertEqual(len(song.chords_used),4) song = books.cp_song(""" {title: Test} {soc} {c: Chorus} This is the chorus CHorus chorus {eoc} After the chorus """) result = """ > **Chorus** > This is the chorus > CHorus chorus After the chorus """ self.assertEqual(song.text, result) song = books.cp_song(""" {title: Test} {sot} This is where some Preformatted Tab goes --5---5----5 1---2--2--2- 3-3-3-3-3-3- --9--9--9-9- {eot} After the tab """) result = """ ``` This is where some Preformatted Tab goes --5---5----5 1---2--2--2- 3-3-3-3-3-3- --9--9--9-9- ``` After the tab """ self.assertEqual(song.text, result) song = books.cp_song(""" {title: Test} {sot} This is where some Preformatted Tab goes --5---5----5 1---2--2--2- 3-3-3-3-3-3- --9--9--9-9- {soc} {c: Chorus} Where someone forgot to close the tab {eoc}""") result = """ ``` This is where some Preformatted Tab goes --5---5----5 1---2--2--2- 3-3-3-3-3-3- --9--9--9-9- > **Chorus** > Where someone forgot to close the tab """ self.assertEqual(song.text, result) song = books.cp_song(""" {title: Test} {start_of_chorus} {c: Here's a chorus with tab in it} {sot} This is where some Preformatted Tab goes --5---5----5 1---2--2--2- 3-3-3-3-3-3- --9--9--9-9- {eot} Still in the chorus {eoc} After the chorus """) result = """ > **Here's a chorus with tab in it** > This is where some > Preformatted > Tab goes > --5---5----5 > 1---2--2--2- > 3-3-3-3-3-3- > --9--9--9-9- > Still in the chorus After the chorus """ # TODO TEST IS MISSING! song = books.cp_song("{instrument: Thongaphone}") self.assertEqual( "Thongaphone", song.local_instruments.get_instrument_by_name("Thongaphone").name) self.assertEqual( "Thongaphone", song.local_instruments.get_instrument_by_name("Thongaphone").name) song = books.cp_song("{instrument: Thongaphone}\n{define: C#7 frets 0 1 0 1 0 1 0 1}\n{define: C#7-5 frets 0 1 0 1 0 1 0 1}") #song.instruments.get_instrument_by_name("Thongaphone").chart.get_default("C#7-5").show() self.assertEqual("{define: C#7-5 frets 0 1 0 1 0 1 0 1}", song.local_instruments.get_instrument_by_name("Thongaphone").chart.get_default("C#7-5").to_chordpro()) song = books.cp_song("{instrument: Uke}\n{define: C frets 12 12 12 15}") #song.instruments.get_instrument_by_name("Soprano Ukulele").chart.get_default("C").show() song.format(instrument_name = "Nope!") self.assertEqual("{define: C base-fret 11 frets 1 1 1 4}", song.local_instruments.get_instrument_by_name("Soprano Ukulele").chart.get_default("C").to_chordpro())