This commit is contained in:
Jamie Hardt
2024-07-07 15:21:24 -07:00
parent e0431da6df
commit 8d299e2335
3 changed files with 28 additions and 19 deletions

View File

@@ -14,7 +14,7 @@ import inspect
from tqdm import tqdm
from mfbatch.util import readline_with_escaped_newlines
import mfbatch.metaflac as flac
import mfbatch.metaflac as metadata_funcs
from mfbatch.commands import BatchfileParser
@@ -40,7 +40,7 @@ def create_batch_list(command_file: str, recursive=True):
flac_files = glob('./**/*.flac', recursive=recursive)
flac_files = sorted(flac_files)
for path in tqdm(flac_files, unit='File', desc='Scanning FLAC files'):
this_file_metadata = flac.read_metadata(path)
this_file_metadata = metadata_funcs.read_metadata(path)
for this_key, this_value in this_file_metadata.items():
if this_key not in metadatums:
f.write(f":set {this_key} "
@@ -66,7 +66,8 @@ def main():
"""
Entry point implementation
"""
op = ArgumentParser(prog='mfbatch', usage='%(prog)s (-c | -e | -W) [options]')
op = ArgumentParser(
prog='mfbatch', usage='%(prog)s (-c | -e | -W) [options]')
op.add_argument('-c', '--create', default=False,
action='store_true',

View File

@@ -64,8 +64,10 @@ class CommandEnv:
self.incr.pop(k, None)
self.patterns.pop(k, None)
def reset_keys(self):
"""
Reset all keys in the environment
"""
all_keys = list(self.metadatums.keys())
for key in all_keys:
@@ -74,7 +76,6 @@ class CommandEnv:
self.patterns = {}
self.incr = {}
def set_pattern(self, to: str, frm: str, pattern: str, repl: str):
"""
Establish a pattern replacement in the environment

View File

@@ -6,7 +6,11 @@ from typing import cast
from mfbatch.commands import BatchfileParser
class CommandTests(unittest.TestCase):
"""
Tests the BatchfileParser class
"""
def setUp(self):
self.command_parser = BatchfileParser()
self.command_parser.dry_run = False
@@ -15,14 +19,16 @@ class CommandTests(unittest.TestCase):
def tearDown(self):
pass
def testSetWithoutWrite(self):
def test_set_without_write(self):
"Test setting a key without writing"
self.command_parser.set(['TYPE', 'Everything'])
self.assertFalse(cast(MagicMock,
self.command_parser.write_metadata_f).called)
self.assertEqual(self.command_parser.env.metadatums['TYPE'],
'Everything')
def testSetCommand(self):
def test_set_command(self):
"Test set command"
self.command_parser.set(['X', 'Y'])
self.command_parser.eval("./testfile.flac", lineno=1,
interactive=False)
@@ -32,16 +38,17 @@ class CommandTests(unittest.TestCase):
self.command_parser.write_metadata_f).call_args.args,
('./testfile.flac', {'X': 'Y'}))
def testUnsetCommand(self):
def test_unset_command(self):
"Test unset command"
self.command_parser.set(['A', '1'])
self.assertEqual(self.command_parser.env.metadatums['A'], '1')
self.command_parser.unset(['A'])
self.assertNotIn('A', self.command_parser.env.metadatums.keys())
def testSetP(self):
pass
def test_setp(self):
"Test setp command"
def testEval(self):
def test_eval(self):
"Test eval"
self.command_parser.eval(":set A 1", 1, False)
self.assertEqual(self.command_parser.env.metadatums['A'], '1')