Test implementation

This commit is contained in:
Jamie Hardt
2024-07-07 15:15:01 -07:00
parent 0d765f9d84
commit d334181dc8
2 changed files with 22 additions and 4 deletions

View File

@@ -11,7 +11,7 @@ import os.path
from typing import Dict, Tuple, Optional from typing import Dict, Tuple, Optional
import mfbatch.metaflac as flac from mfbatch.metaflac import write_metadata as flac
class UnrecognizedCommandError(Exception): class UnrecognizedCommandError(Exception):
@@ -158,6 +158,7 @@ they appear in the batchfile.
def __init__(self): def __init__(self):
self.dry_run = True self.dry_run = True
self.env = CommandEnv() self.env = CommandEnv()
self.write_metadata_f = flac
def eval(self, line: str, lineno: int, interactive: bool): def eval(self, line: str, lineno: int, interactive: bool):
""" """
@@ -192,7 +193,7 @@ they appear in the batchfile.
print("DRY RUN would write metadata here.") print("DRY RUN would write metadata here.")
else: else:
sys.stdout.write("Writing metadata... ") sys.stdout.write("Writing metadata... ")
flac.write_metadata(line, self.env.metadatums) self.write_metadata_f(line, self.env.metadatums)
sys.stdout.write("Complete!") sys.stdout.write("Complete!")
self.env.increment_all() self.env.increment_all()

View File

@@ -1,19 +1,36 @@
"mfbatch tests" "mfbatch tests"
import unittest import unittest
from unittest.mock import MagicMock
from typing import cast
from mfbatch.commands import BatchfileParser from mfbatch.commands import BatchfileParser
class CommandTests(unittest.TestCase): class CommandTests(unittest.TestCase):
def setUp(self): def setUp(self):
self.command_parser = BatchfileParser() self.command_parser = BatchfileParser()
self.command_parser.dry_run = False
self.command_parser.write_metadata_f = MagicMock()
def tearDown(self): def tearDown(self):
pass pass
def testSetWithoutWrite(self):
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 testSetCommand(self):
self.command_parser.set(['X', 'Y']) self.command_parser.set(['X', 'Y'])
self.assertEqual(self.command_parser.env.metadatums['X'], 'Y') self.command_parser.eval("./testfile.flac", lineno=1,
interactive=False)
self.assertTrue(cast(MagicMock,
self.command_parser.write_metadata_f).called)
self.assertEqual(cast(MagicMock,
self.command_parser.write_metadata_f).call_args.args,
('./testfile.flac', {'X': 'Y'}))
def testUnsetCommand(self): def testUnsetCommand(self):
self.command_parser.set(['A', '1']) self.command_parser.set(['A', '1'])