示例#1
0
  def test_TOC(self):
      #Check that we can build a table of contents and split it across multiple pages when necessary
      book_text = ""
      slotmachine = "samples/slot_machine_baby.cho.txt\n"
      book_text += slotmachine * 30
      b = books.cp_song_book()
      b.load_from_text(book_text)
      toc = books.TOC(b, 3)
      self.assertEqual(len(toc.pages), 1)
      self.assertEqual(len(b.songs),30)
      
      
      book_text += slotmachine * 60
      b = books.cp_song_book()
      b.load_from_text(book_text)
      toc = books.TOC(b, 3)
      self.assertEqual(len(toc.pages), 3)
      self.assertEqual(len(b.songs), 90)

      book_text += slotmachine * 40
      b = books.cp_song_book()
      b.load_from_text(book_text)
      toc = books.TOC(b, 3)
      self.assertEqual(len(toc.pages), 4)
      self.assertEqual(len(b.songs), 131)
      
      book_text += slotmachine * 80
      b = books.cp_song_book()
      b.load_from_text(book_text)
      toc = books.TOC(b, 3)
      self.assertEqual(len(toc.pages), 6)
      self.assertEqual(len(b.songs), 211)
示例#2
0
  def test_TOC(self):
      #Check that we can build a table of contents and split it across multiple pages when necessary
      book_text = ""
      slotmachine = "samples/slot_machine_baby.cho.txt\n"
      
      book_text += slotmachine * 30
      b = books.cp_song_book()
      b.load_from_text(book_text)
      for song in b.songs:
          song.format()
      toc = books.TOC(b, 3)
      self.assertEqual(len(toc.pages), 1)
      self.assertEqual(len(b.songs),30)
      
      
      book_text += slotmachine * 60
      b = books.cp_song_book()
      b.load_from_text(book_text)
      toc = books.TOC(b, 3)
      self.assertEqual(len(toc.pages), 3)
      self.assertEqual(len(b.songs), 90)

      book_text += slotmachine * 40
      b = books.cp_song_book()
      b.load_from_text(book_text)
      toc = books.TOC(b, 3)
      self.assertEqual(len(toc.pages), 4)
      self.assertEqual(len(b.songs), 131)
      
      book_text += slotmachine * 80
      b = books.cp_song_book()
      b.load_from_text(book_text)
      toc = books.TOC(b, 3)
      self.assertEqual(len(toc.pages), 6)
      self.assertEqual(len(b.songs), 211)
示例#3
0
 def test_book(self):
     book_path = "samples/sample.book.txt"
     sample_book_text = open(book_path).read()
     b = books.cp_song_book(path=book_path)
     b.load_from_text(sample_book_text)
     self.assertEqual(len(b.songs), 4)
     self.assertEqual(b.songs[1].key, "C")
     self.assertEqual(b.songs[2].key, "Bb")
     
     book_path="samples/sample-lazy.book.txt"
     """This one has auto-transpose turned on"""
     sample_book_text = open(book_path).read()
     b = books.cp_song_book( path=book_path)
     b.load_from_text(sample_book_text)
     self.assertEqual(len(b.songs), 8)
     self.assertEqual(b.title, "Sample songs")
    
     book_path="samples/sample-lazy-uke.book.txt"
     sample_book_text = open(book_path).read()
     b = books.cp_song_book(path=book_path)
     b.load_from_text(sample_book_text)
    
     self.assertEqual(len(b.songs), 4)
     #self.assertEqual(b.songs[3].transpose, -3)
     self.assertEqual(b.songs[3].title, "Universe")
     self.assertEqual(b.title, "Sample songs")
     self.assertEqual(b.default_instrument_names[0],"Ukulele")
示例#4
0
  def test_versioned_book(self):
      book_path = "samples/sample.book.txt"
      b = books.cp_song_book(path=book_path)

      self.assertEqual(b.version, None)
      book_path = "samples/sample_versioned.book.txt"         
      b = books.cp_song_book(path=book_path)
      self.assertEqual(b.version, "v1.1a")
      
      book_path = "samples/sample_auto_versioned.book.txt"
      b = books.cp_song_book(path=book_path)
      self.assertEqual(b.version, 'auto')
示例#5
0
 def test_single_song_multitple_pdf(self):
     b = books.cp_song_book()
     b.add_song_from_text("{title: This is a song!}\n{key: Db}", "test1")
     with tempfile.TemporaryDirectory() as tmp:
         result = b.save_as_single_sheets(tmp)
     self.assertEqual(len(result), 1)
     b = books.cp_song_book()
     self.assertEqual(result[0]["title"], "This is a song! (C#)")
     b.add_song_from_text("{title: This is a second song!}\n{key: Db}\n{tr: +1 +2}", "test1")
     with tempfile.TemporaryDirectory() as tmp:
         result = b.save_as_single_sheets(tmp)
     self.assertEqual(len(result), 3)
     self.assertEqual(result[1]["title"], "This is a second song! (D)")
示例#6
0
 def test_single_song_multitple_pdf(self):
     b = books.cp_song_book()
     b.add_song_from_text("{title: This is a song!}\n{key: Db}", "test1")
     with tempfile.TemporaryDirectory() as tmp:
         result = b.save_as_single_sheets(tmp)
     self.assertEqual(len(result), 1)
     b = books.cp_song_book()
     self.assertEqual(result[0]["title"], "This is a song! (C#)")
     b.add_song_from_text("{title: This is a second song!}\n{key: Db}\n{tr: +1 +2}", "test1")
     with tempfile.TemporaryDirectory() as tmp:
         result = b.save_as_single_sheets(tmp)
     self.assertEqual(len(result), 3)
     self.assertEqual(result[1]["title"], "This is a second song! (D)")
示例#7
0
    def test_versioned_setlist(self):
        book_path = "samples/sample.setlist.md"
        sample_book_text = open(book_path).read()
        # This is cumbersome, but if you want to pass a string to setlist
        # you need to set the path first
        b = books.cp_song_book()
        b.set_path(book_path)
        b.order_by_setlist(sample_book_text)
        self.assertEqual(b.version, None)

        book_path = "samples/sample_versioned.setlist.md"
        b = books.cp_song_book()
        b.order_by_setlist(book_path)
        self.assertEqual(b.version, "32b")

        book_path = "samples/sample_auto_versioned.setlist.md"
        b = books.cp_song_book()
        b.order_by_setlist(book_path)
        self.assertEqual(b.version, 'auto')
示例#8
0
    def test_book(self):
        book_path = "samples/sample.book.txt"
        b = books.cp_song_book(path=book_path)
        self.assertEqual(len(b.songs), 4)
        self.assertEqual(b.songs[1].key, "C")
        self.assertEqual(b.songs[2].key, "Bb")

        book_path = "samples/sample-lazy.book.txt"

        b = books.cp_song_book(path=book_path)

        self.assertEqual(len(b.songs), 9)
        self.assertEqual(b.title, "Sample songs")

        book_path = "samples/sample-lazy-uke.book.txt"
        b = books.cp_song_book(path=book_path)

        self.assertEqual(len(b.songs), 5)
        self.assertEqual(b.title, "Sample songs")
        self.assertEqual(b.default_instrument_names[0], "Ukulele")
示例#9
0
  def test_versioned_book(self):
      book_path = "samples/sample.book.txt"
      sample_book_text = open(book_path).read()
      b = books.cp_song_book(path=book_path)
      b.load_from_text(sample_book_text)

      self.assertEqual(b.version, None)
      
      book_path = "samples/sample_versioned.book.txt"
      sample_book_text = open(book_path).read()
         

      b = books.cp_song_book(path=book_path)
      b.load_from_text(sample_book_text)
      self.assertEqual(b.version, "v1.1a")

      book_path = "samples/sample_auto_versioned.book.txt"
      sample_book_text = open(book_path).read()
      b = books.cp_song_book(path=book_path)
      b.load_from_text(sample_book_text)
      self.assertEqual(b.version, 'auto')
示例#10
0
 def test_reorder(self):
   one1 = "{title: 1 page}"
   one2 = "{title: 1 page}"
   two1 = "{title: 2 page}\n{new_page}\nxxx"
   two2 = "{title: 2 page}\n{new_page}\yxxx"
 
   book = books.cp_song_book()
   book.add_song_from_text(one1, "1")
   book.add_song_from_text(one2, "2")
   book.add_song_from_text(two1, "3")
   book.add_song_from_text(two2, "4")
   page = 3
   book.reorder(page)
   for song in book.songs:
     #Check that two or four page spreads start on an even page
     if song.pages % 2 == 0:
       self.assertEqual(page % 2, 0)
     page += song.pages
示例#11
0
 def test_reorder(self):
   one1 = "{title: 1 page}"
   one2 = "{title: 1 page}"
   two1 = "{title: 2 page}\n{new_page}\nxxx"
   two2 = "{title: 2 page}\n{new_page}\yxxx"
 
   book = books.cp_song_book()
   book.add_song_from_text(one1, "1")
   book.add_song_from_text(one2, "2")
   book.add_song_from_text(two1, "3")
   book.add_song_from_text(two2, "4")
   page = 3
   book.reorder(page)
   for song in book.songs:
     #Check that two or four page spreads start on an even page
     if song.pages % 2 == 0:
       self.assertEqual(page % 2, 0)
     page += song.pages
示例#12
0
    def test_setlist(self):

        #This is our setlist
        book_path = "samples/sample.setlist.md"
        b = books.cp_song_book()

        #Now use the setlist to order the book - should find the {book directive}
        b.order_by_setlist(book_path)

        self.assertEqual(len(b.songs), 4)
        self.assertEqual(len(b.sets), 2)

        b.format()

        keys = ["C", "A", "G", "Bb"]
        actual_keys = [s.key for s in b.songs]
        self.assertEqual(keys, actual_keys)

        original_keys = ["C", "C", "G", "C"]
        actual_keys = [s.original_key for s in b.songs]
        self.assertEqual(original_keys, actual_keys)