def test_show_verbose_one(self): with helper.Capturing() as output: mscxyz.execute(['-v', 'meta', '--clean', 'all', helper.get_tmpfile_path('simple.mscx')]) output = ' '.join(output) self.assertTrue('readonly_abspath' in output) self.assertFalse('readonly_relpath_backup' in output)
def test_clean_single_field(self): tmp = helper.get_tmpfile_path("meta-all-values.mscx") mscxyz.execute(["meta", "--clean", "vbox_title", tmp]) meta = Meta(tmp) iface = meta.interface self.assertEqual(iface.vbox_title, None, "vbox_title") self.assertEqual(iface.vbox_composer, "vbox_composer", "vbox_composer")
def test_export(self, mscore_function): tmp = helper.get_tmpfile_path('simple.mscx') mscxyz.execute(['export', '--extension', 'mp3', tmp]) args = mscore_function.call_args_list[0][0][0] self.assertEqual(args[0], '--export-to') self.assertEqual(args[1], tmp.replace('mscx', 'mp3')) self.assertEqual(args[2], tmp)
def test_broken_file(self): with helper.Capturing() as output: mscxyz.execute(['--config-file', ini_file, 'meta', helper.get_tmpfile_path('broken.mscx')]) self.assertTrue('Error: XMLSyntaxError; message: Start tag expected, ' '\'<\' not found, line 1, column 1' in ' '.join(output))
def test_delete_duplicates_move_subtitle(self): tmp = helper.get_tmpfile_path('meta-duplicates-move-subtitle.mscx') mscxyz.execute(['meta', '--delete-duplicates', tmp]) meta = Meta(tmp) self.assertFalse(meta.interface.combined_lyricist) self.assertFalse(meta.interface.combined_subtitle) self.assertEqual(meta.interface.combined_title, 'Title')
def test_broken_file(self): with helper.Capturing() as output: mscxyz.execute(['meta', helper.get_tmpfile_path('broken.mscx')]) self.assertTrue('Error: XMLSyntaxError; message: Start tag expected, ' '\'<\' not found, line 1, column 1' in ' '.join(output))
def test_version(self): with self.assertRaises(SystemExit): with helper.Capturing() as output: mscxyz.execute(["--version"]) result = re.search("[^ ]* [^ ]*", output[0]) self.assertTrue(result)
def test_set_field_multiple_times(self): tmp = helper.get_tmpfile_path('meta-all-values.mscx') mscxyz.execute(['meta', '--set-field', 'vbox_title', 'lol', '--set-field', 'vbox_composer', 'troll', tmp]) meta = Meta(tmp) self.assertEqual(meta.interface.vbox_title, 'lol') self.assertEqual(meta.interface.vbox_composer, 'troll')
def test_set_field_with_templating(self): tmp = helper.get_tmpfile_path('meta-all-values.mscx') mscxyz.execute(['meta', '--set-field', 'vbox_title', '$vbox_title ($vbox_composer)', tmp]) meta = Meta(tmp) self.assertEqual(meta.interface.vbox_title, 'vbox_title (vbox_composer)')
def test_log(self): tmp = helper.get_tmpfile_path('simple.mscx') log = tempfile.mktemp() mscxyz.execute(['meta', '--log', log, '$combined_title-$combined_composer', tmp]) log_file = open(log, 'r') self.assertEqual(log_file.readline(), 'Title-Composer\n')
def test_clean_single_field(self): tmp = helper.get_tmpfile_path('meta-all-values.mscx') mscxyz.execute(['meta', '--clean', 'vbox_title', tmp]) meta = Meta(tmp) iface = meta.interface self.assertEqual(iface.vbox_title, None, 'vbox_title') self.assertEqual(iface.vbox_composer, 'vbox_composer', 'vbox_composer')
def test_version(self): with self.assertRaises(SystemExit): with helper.Capturing() as output: mscxyz.execute(['--version']) result = re.search('[^ ]* [^ ]*', output[0]) self.assertTrue(result)
def test_clean_all(self): tmp = helper.get_tmpfile_path("meta-all-values.mscx") mscxyz.execute(["meta", "--clean", "all", tmp]) meta = Meta(tmp) iface = meta.interface_read_write for field in iface.fields: self.assertEqual(getattr(iface, field), None, field)
def test_log(self): tmp = helper.get_tmpfile_path('simple.mscx') log = tempfile.mktemp() mscxyz.execute( ['meta', '--log', log, '$combined_title-$combined_composer', tmp]) log_file = open(log, 'r') self.assertEqual(log_file.readline(), 'Title-Composer\n')
def _test_clean_add_style(self, version=2): tmp = helper.get_tmpfile_path("simple.mscx", version) mscxyz.execute([ "clean", "--style", helper.get_tmpfile_path("style.mss", version), tmp ]) style = helper.read_file(tmp) self.assertTrue("<staffUpperBorder>77</staffUpperBorder>" in style)
def test_show(self): with helper.Capturing() as output: mscxyz.execute(['meta', '--clean', 'all', helper.get_tmpfile_path('meta-all-values.mscx')]) self.assertEqual(output[0], '') self.assertTrue('meta-all-values.mscx' in ' '.join(output)) self.assertEqual(output[-1], 'vbox_title: “vbox_title” -> “”')
def test_show_verbose_two(self): with helper.Capturing() as output: mscxyz.execute([ '-vv', 'meta', '--clean', 'all', helper.get_tmpfile_path('simple.mscx') ]) output = ' '.join(output) self.assertTrue('readonly_relpath_backup' in output)
def test_distribute_field_exception_unmatched(self): tmp = helper.get_tmpfile_path('simple.mscx') with helper.Capturing() as output: mscxyz.execute([ 'meta', '--distribute-field', 'vbox_title', '$metatag_work_title - $metatag_composer', tmp ]) self.assertTrue('UnmatchedFormatStringError' in output[-1])
def test_set_field_with_templating(self): tmp = helper.get_tmpfile_path('meta-all-values.mscx') mscxyz.execute([ 'meta', '--set-field', 'vbox_title', '$vbox_title ($vbox_composer)', tmp ]) meta = Meta(tmp) self.assertEqual(meta.interface.vbox_title, 'vbox_title (vbox_composer)')
def test_set_field_with_templating(self): tmp = helper.get_tmpfile_path("meta-all-values.mscx") mscxyz.execute([ "meta", "--set-field", "vbox_title", "$vbox_title ($vbox_composer)", tmp ]) meta = Meta(tmp) self.assertEqual(meta.interface.vbox_title, "vbox_title (vbox_composer)")
def test_show_verbose_one(self): with helper.Capturing() as output: mscxyz.execute([ "-v", "meta", "--clean", "all", helper.get_tmpfile_path("simple.mscx") ]) output = " ".join(output) self.assertTrue("readonly_abspath" in output) self.assertFalse("readonly_relpath_backup" in output)
def test_show_simple_unverbose(self): with helper.Capturing() as output: mscxyz.execute(['meta', '--clean', 'all', helper.get_tmpfile_path('simple.mscx')]) self.assertEqual(output[0], '') self.assertTrue('simple.mscx' in ' '.join(output)) self.assertEqual(output[2], 'combined_composer: “Composer” -> “”') self.assertEqual(output[3], 'combined_title: “Title” -> “”') self.assertEqual(output[-1], 'vbox_title: “Title” -> “”')
def test_clean_single_field(self): tmp = helper.get_tmpfile_path('meta-all-values.mscx') mscxyz.execute( ['meta', '--clean', 'vbox_title', tmp] ) meta = Meta(tmp) iface = meta.interface self.assertEqual(iface.vbox_title, None, 'vbox_title') self.assertEqual(iface.vbox_composer, 'vbox_composer', 'vbox_composer')
def test_clean_all(self): tmp = helper.get_tmpfile_path('meta-all-values.mscx') mscxyz.execute( ['meta', '--clean', 'all', tmp] ) meta = Meta(tmp) iface = meta.interface_read_write for field in iface.fields: self.assertEqual(getattr(iface, field), None, field)
def test_set_field_multiple_times(self): tmp = helper.get_tmpfile_path('meta-all-values.mscx') mscxyz.execute([ 'meta', '--set-field', 'vbox_title', 'lol', '--set-field', 'vbox_composer', 'troll', tmp ]) meta = Meta(tmp) self.assertEqual(meta.interface.vbox_title, 'lol') self.assertEqual(meta.interface.vbox_composer, 'troll')
def test_clean(self): tmp = helper.get_tmpfile_path('formats.mscx') mscxyz.execute(['clean', tmp]) cleaned = helper.read_file(tmp) self.assertFalse('<font' in cleaned) self.assertFalse('<b>' in cleaned) self.assertFalse('<i>' in cleaned) self.assertFalse('<pos' in cleaned) self.assertFalse('<LayoutBreak>' in cleaned) self.assertFalse('<StemDirection>' in cleaned)
def test_broken_file(self): with helper.Capturing() as output: mscxyz.execute([ "--config-file", ini_file, "meta", helper.get_tmpfile_path("broken.mscx"), ]) self.assertTrue("Error: XMLSyntaxError; message: Start tag expected, " "'<' not found, line 1, column 1" in " ".join(output))
def _test_clean(self, version=2): tmp = helper.get_tmpfile_path('formats.mscx', version) mscxyz.execute(['clean', tmp]) cleaned = helper.read_file(tmp) self.assertFalse('<font' in cleaned) self.assertFalse('<b>' in cleaned) self.assertFalse('<i>' in cleaned) self.assertFalse('<pos' in cleaned) self.assertFalse('<LayoutBreak>' in cleaned) self.assertFalse('<StemDirection>' in cleaned)
def test_show(self): with helper.Capturing() as output: mscxyz.execute([ '--config-file', ini_file, 'meta', '--clean', 'all', helper.get_tmpfile_path('meta-all-values.mscx') ]) self.assertEqual(output[0], '') self.assertTrue('meta-all-values.mscx' in ' '.join(output)) self.assertEqual(output[-1], 'vbox_title: “vbox_title” -> “”')
def _test_clean(self, version=2): tmp = helper.get_tmpfile_path("formats.mscx", version) mscxyz.execute(["clean", tmp]) cleaned = helper.read_file(tmp) self.assertFalse("<font" in cleaned) self.assertFalse("<b>" in cleaned) self.assertFalse("<i>" in cleaned) self.assertFalse("<pos" in cleaned) self.assertFalse("<LayoutBreak>" in cleaned) self.assertFalse("<StemDirection>" in cleaned)
def test_distribute_field_exception_unmatched(self): tmp = helper.get_tmpfile_path("simple.mscx") with helper.Capturing() as output: mscxyz.execute([ "meta", "--distribute-field", "vbox_title", "$metatag_work_title - $metatag_composer", tmp, ]) self.assertTrue("UnmatchedFormatStringError" in output[-1])
def test_show_simple_unverbose(self): with helper.Capturing() as output: mscxyz.execute([ '--config-file', ini_file, 'meta', '--clean', 'all', helper.get_tmpfile_path('simple.mscx') ]) self.assertEqual(output[0], '') self.assertTrue('simple.mscx' in ' '.join(output)) self.assertEqual(output[2], 'combined_composer: “Composer” -> “”') self.assertEqual(output[3], 'combined_title: “Title” -> “”') self.assertEqual(output[-1], 'vbox_title: “Title” -> “”')
def _test_fix(self, version=2): score_path = helper.get_tmpfile_path("lyrics-fix.mscx", version) mscxyz.execute(["lyrics", "--fix", score_path]) self.xml_tree = mscxyz.lyrics.MscoreLyricsInterface(score_path) self.lyrics = self.xml_tree.lyrics text = [] syllabic = [] for element in self.lyrics: tag = element["element"] tag_text = tag.find("text") text.append(tag_text.text) tag_syllabic = tag.find("syllabic") if hasattr(tag_syllabic, "text"): syllabic.append(tag_syllabic.text) self.assertEqual( text, [ "Al", "K\xf6pf", "le", "chen", "mei", "un", "ne", "ters", "En", "Was", "te", "si", "lein.", "lein.", ], ) self.assertEqual( syllabic, [ "begin", "begin", "end", "end", "begin", "begin", "end", "end", "begin", "begin", "middle", "middle", "end", "end", ], )
def test_distribute_field_multple_source_fields(self): tmp = helper.get_tmpfile_path('Title - Composer.mscx') mscxyz.execute( ['meta', '--distribute-field', 'vbox_title,readonly_basename', '$combined_title - $combined_composer', tmp] ) meta = Meta(tmp) iface = meta.interface self.assertEqual(iface.vbox_composer, 'Composer') self.assertEqual(iface.metatag_composer, 'Composer') self.assertEqual(iface.vbox_title, 'Title') self.assertEqual(iface.metatag_work_title, 'Title')
def test_distribute_field_multple_source_fields(self): tmp = helper.get_tmpfile_path('Title - Composer.mscx') mscxyz.execute([ 'meta', '--distribute-field', 'vbox_title,readonly_basename', '$combined_title - $combined_composer', tmp ]) meta = Meta(tmp) iface = meta.interface self.assertEqual(iface.vbox_composer, 'Composer') self.assertEqual(iface.metatag_composer, 'Composer') self.assertEqual(iface.vbox_title, 'Title') self.assertEqual(iface.metatag_work_title, 'Title')
def test_distribute_field_multiple_values(self): tmp = helper.get_tmpfile_path('meta-distribute-field.mscx') mscxyz.execute([ 'meta', '--distribute-field', 'vbox_title', '$metatag_work_title - $metatag_composer', '--distribute-field', 'vbox_title', '$metatag_movement_title - $metatag_lyricist', tmp ]) meta = Meta(tmp) iface = meta.interface self.assertEqual(iface.metatag_lyricist, 'Composer') self.assertEqual(iface.metatag_composer, 'Composer') self.assertEqual(iface.metatag_movement_title, 'Title') self.assertEqual(iface.metatag_work_title, 'Title')
def test_show(self): with helper.Capturing() as output: mscxyz.execute([ "--config-file", ini_file, "meta", "--clean", "all", helper.get_tmpfile_path("meta-all-values.mscx"), ]) self.assertEqual(output[0], "") self.assertTrue("meta-all-values.mscx" in " ".join(output)) self.assertEqual(output[-1], "vbox_title: “vbox_title” -> “”")
def test_distribute_field_multple_source_fields(self): tmp = helper.get_tmpfile_path("Title - Composer.mscx") mscxyz.execute([ "meta", "--distribute-field", "vbox_title,readonly_basename", "$combined_title - $combined_composer", tmp, ]) meta = Meta(tmp) iface = meta.interface self.assertEqual(iface.vbox_composer, "Composer") self.assertEqual(iface.metatag_composer, "Composer") self.assertEqual(iface.vbox_title, "Title") self.assertEqual(iface.metatag_work_title, "Title")
def test_set_field_multiple_times(self): tmp = helper.get_tmpfile_path("meta-all-values.mscx") mscxyz.execute([ "meta", "--set-field", "vbox_title", "lol", "--set-field", "vbox_composer", "troll", tmp, ]) meta = Meta(tmp) self.assertEqual(meta.interface.vbox_title, "lol") self.assertEqual(meta.interface.vbox_composer, "troll")
def test_remap(self): score_path = helper.get_tmpfile_path("lyrics-remap.mscx") mscxyz.execute(["lyrics", "--remap", "2:6", score_path]) tree = mscxyz.lyrics.MscoreLyricsInterface(score_path) text = [] for element in tree.lyrics: tag = element["element"] tag_text = tag.find("no") if hasattr(tag_text, "text"): no = tag_text.text else: no = "0" text.append(no) self.assertEqual(text, ["0", "5", "2", "3", "4"])
def test_show_simple_unverbose(self): with helper.Capturing() as output: mscxyz.execute([ "--config-file", ini_file, "meta", "--clean", "all", helper.get_tmpfile_path("simple.mscx"), ]) self.assertEqual(output[0], "") self.assertTrue("simple.mscx" in " ".join(output)) self.assertEqual(output[2], "combined_composer: “Composer” -> “”") self.assertEqual(output[3], "combined_title: “Title” -> “”") self.assertEqual(output[-1], "vbox_title: “Title” -> “”")
def test_remap(self): tmp = helper.get_tmpfile_path('lyrics-remap.mscx') mscxyz.execute(['lyrics', '--remap', '2:6', tmp]) tree = mscxyz.lyrics.Lyrics(tmp) text = [] for element in tree.lyrics: tag = element['element'] tag_text = tag.find('no') if hasattr(tag_text, 'text'): no = tag_text.text else: no = '0' text.append(no) self.assertEqual(text, ['0', '5', '2', '3', '4'])
def test_distribute_field_multiple_values(self): tmp = helper.get_tmpfile_path("meta-distribute-field.mscx") mscxyz.execute([ "meta", "--distribute-field", "vbox_title", "$metatag_work_title - $metatag_composer", "--distribute-field", "vbox_title", "$metatag_movement_title - $metatag_lyricist", tmp, ]) meta = Meta(tmp) iface = meta.interface self.assertEqual(iface.metatag_lyricist, "Composer") self.assertEqual(iface.metatag_composer, "Composer") self.assertEqual(iface.metatag_movement_title, "Title") self.assertEqual(iface.metatag_work_title, "Title")
def test_distribute_field_multiple_values(self): tmp = helper.get_tmpfile_path('meta-distribute-field.mscx') mscxyz.execute( ['meta', '--distribute-field', 'vbox_title', '$metatag_work_title - $metatag_composer', '--distribute-field', 'vbox_title', '$metatag_movement_title - $metatag_lyricist', tmp] ) meta = Meta(tmp) iface = meta.interface self.assertEqual(iface.metatag_lyricist, 'Composer') self.assertEqual(iface.metatag_composer, 'Composer') self.assertEqual(iface.metatag_movement_title, 'Title') self.assertEqual(iface.metatag_work_title, 'Title')
def test_without_arguments(self): with self.assertRaises(SystemExit) as cm: with helper.Capturing('stderr'): mscxyz.execute() the_exception = cm.exception self.assertEqual(str(the_exception), '2')
def test_clean_add_style(self): tmp = helper.get_tmpfile_path('simple.mscx') mscxyz.execute(['clean', '--style', helper.get_tmpfile_path('style.mss'), tmp]) style = helper.read_file(tmp) self.assertTrue('<staffUpperBorder>77</staffUpperBorder>' in style)
def test_help_text(self): with self.assertRaises(SystemExit): with helper.Capturing() as output: mscxyz.execute(['-h']) self.assertTrue('[-h]' in output[0])
def setUp(self): self.tmp = helper.get_tmpfile_path('lyrics-fix.mscx') mscxyz.execute(['lyrics', '--fix', self.tmp]) self.xml_tree = mscxyz.lyrics.Lyrics(self.tmp) self.lyrics = self.xml_tree.lyrics
def test_extract_by_number(self): mscxyz.execute(['lyrics', '--extract', '2', self.tmp]) self.assertLyricsScoreFileExists(2)
def test_extract_all(self): mscxyz.execute(['lyrics', '--extract', 'all', self.tmp]) self.assertLyricsScoreFileExists(1) self.assertLyricsScoreFileExists(2) self.assertLyricsScoreFileExists(3)
def test_without_arguments(self): mscxyz.execute(['lyrics', self.tmp]) self.assertLyricsScoreFileExists(1) self.assertLyricsScoreFileExists(2) self.assertLyricsScoreFileExists(3)
def test_distribute_field_exception_unmatched(self): tmp = helper.get_tmpfile_path('simple.mscx') with helper.Capturing() as output: mscxyz.execute(['meta', '--distribute-field', 'vbox_title', '$metatag_work_title - $metatag_composer', tmp]) self.assertTrue('UnmatchedFormatStringError' in output[-1])
def test_help_long(self): with self.assertRaises(SystemExit) as cm: with helper.Capturing(): mscxyz.execute(['--help']) the_exception = cm.exception self.assertEqual(str(the_exception), '0')
def test_batch(self, Meta): with helper.Capturing(): mscxyz.execute(['meta', helper.get_tmpdir_path('batch')]) self.assertEqual(Meta.call_count, 3)
def setUp(self): self.tmp = helper.get_tmpfile_path('simple.mscx') self.backup = self.tmp.replace('.mscx', '_bak.mscx') with helper.Capturing(): mscxyz.execute(['--backup', 'meta', self.tmp])
def test_distribute_field_invalid_format_string(self): tmp = helper.get_tmpfile_path('meta-distribute-field.mscx') with self.assertRaises(meta.FormatStringNoFieldError): mscxyz.execute(['meta', '--distribute-field', 'vbox_title', 'lol', tmp])
def test_all(self): with self.assertRaises(SystemExit): with helper.Capturing() as output: mscxyz.execute(['help', 'all']) self.assertTrue(len(output) > 150)
def test_set_field_simple_string(self): tmp = helper.get_tmpfile_path('meta-all-values.mscx') mscxyz.execute(['meta', '--set-field', 'vbox_title', 'lol', tmp]) meta = Meta(tmp) self.assertEqual(meta.interface.vbox_title, 'lol')