def _list_scores(path, extension='both', glob=None): with mock.patch('os.walk') as mockwalk: mockwalk.return_value = [ ('/a', ('bar',), ('lorem.mscx',)), ('/a/b', (), ('impsum.mscz', 'dolor.mscx', 'sit.txt')), ] return list_scores(path, extension, glob)
def _list_scores(path, extension="both", glob=None): with mock.patch("os.walk") as mockwalk: mockwalk.return_value = [ ("/a", ("bar", ), ("lorem.mscx", )), ("/a/b", (), ("impsum.mscz", "dolor.mscx", "sit.txt")), ] return list_scores(path, extension, glob)
def _list_scores(path, extension='both', glob=None): with mock.patch('os.walk') as mockwalk: mockwalk.return_value = [ ('/a', ('bar',), ('lorem.mscx',)), ('/a/b', (), ('impsum.mscz', 'dolor.mscx', 'sit.txt')), ] return list_scores(path, extension, glob)
def test_isfile_no_match(self): with mock.patch("os.path.isfile") as mock_isfile: mock_isfile.return_value = True result = list_scores("/a/b/lorem.lol") self.assertEqual(result, [])
def test_isfile(self): with mock.patch('os.path.isfile') as mock_isfile: mock_isfile.return_value = True result = list_scores('/a/b/lorem.mscx') self.assertEqual(result, ['/a/b/lorem.mscx'])
def execute(args: typing.Sequence = None): args = cli.parser.parse_args(args) config = parse_config_ini(args.general_config_file) if config: args = merge_config_into_args(config, args) set_args(args) if args.subcommand == "help": show_all_help(args) sys.exit() files = list_scores(path=args.path, glob=args.general_glob) for file in files: print("\n" + color(file, "red")) if args.general_backup: from mscxyz.score_file_classes import MscoreFile score = MscoreFile(file) score.backup() if args.subcommand == "clean": score = MscoreXmlTree(file) print(score.filename) score.clean() if args.clean_style: score.merge_style(styles=args.clean_style.name) score.save(mscore=args.general_mscore) elif args.subcommand == "lyrics": score = MscoreLyricsInterface(file) if args.lyrics_remap: score.remap(remap_string=args.lyrics_remap, mscore=args.general_mscore) elif args.lyrics_fix: score.fix_lyrics(mscore=args.general_mscore) else: score.extract_lyrics(number=args.lyrics_extract, mscore=args.general_mscore) elif args.subcommand == "meta": score = Meta(file) if no_error(lxml.etree.XMLSyntaxError, score.errors): pre = score.interface.export_to_dict() if args.meta_clean: score.clean(fields=args.meta_clean) if args.meta_json: score.export_json() if args.meta_dist: for a in args.meta_dist: score.distribute_field(source_fields=a[0], format_string=a[1]) if args.meta_set: for a in args.meta_set: score.set_field(destination_field=a[0], format_string=a[1]) if args.meta_delete: score.delete_duplicates() if args.meta_sync: score.sync_fields() if args.meta_log: score.write_to_log_file(args.meta_log[0], args.meta_log[1]) post = score.interface.export_to_dict() score.show(pre, post) if not args.general_dry_run and not score.errors and pre != post: score.save(mscore=args.general_mscore) elif args.subcommand == "rename": score = rename_filename(file) elif args.subcommand == "export": from mscxyz.score_file_classes import MscoreFile score = MscoreFile(file) score.export(extension=args.export_extension) report_errors(score.errors)
def execute(args=None): args = cli.parser.parse_args(args) set_settings('args', args) if args.subcommand == 'help': show_all_help(args) sys.exit() files = list_scores(path=args.path, glob=args.general_glob) for file in files: print('\n' + color(file, 'red')) if args.general_backup: from mscxyz.score_file_classes import ScoreFile score = ScoreFile(file) score.backup() if args.subcommand == 'clean': score = XMLTree(file) print(score.filename) score.clean() if args.clean_style: score.merge_style(styles=args.clean_style.name) score.save(mscore=args.general_mscore) elif args.subcommand == 'lyrics': score = Lyrics(file) if args.lyrics_remap: score.remap(remap_string=args.lyrics_remap, mscore=args.general_mscore) elif args.lyrics_fix: score.fix_lyrics(mscore=args.general_mscore) else: score.extract_lyrics(number=args.lyrics_extract, mscore=args.general_mscore) elif args.subcommand == 'meta': score = Meta(file) if no_error(lxml.etree.XMLSyntaxError, score.errors): pre = score.interface.export_to_dict() if args.meta_clean: score.clean(fields=args.meta_clean) if args.meta_json: score.export_json() if args.meta_dist: for a in args.meta_dist: score.distribute_field(source_fields=a[0], format_string=a[1]) if args.meta_set: for a in args.meta_set: score.set_field(destination_field=a[0], format_string=a[1]) if args.meta_delete: score.delete_duplicates() if args.meta_sync: score.sync_fields() if args.meta_log: score.write_to_log_file(args.meta_log[0], args.meta_log[1]) post = score.interface.export_to_dict() score.show(pre, post) if not args.general_dry_run and not score.errors and pre != post: score.save(mscore=args.general_mscore) elif args.subcommand == 'rename': score = rename_filename(file) elif args.subcommand == 'export': from mscxyz.score_file_classes import ScoreFile score = ScoreFile(file) score.export(extension=args.export_extension) report_errors(score.errors)
def test_isfile_no_match(self): with mock.patch('os.path.isfile') as mock_isfile: mock_isfile.return_value = True result = list_scores('/a/b/lorem.lol') self.assertEqual(result, [])