mirror of
https://github.com/iluvcapra/mfbatch.git
synced 2025-12-31 08:50:51 +00:00
Test implementation
This commit is contained in:
@@ -11,7 +11,7 @@ import os.path
|
||||
|
||||
from typing import Dict, Tuple, Optional
|
||||
|
||||
import mfbatch.metaflac as flac
|
||||
from mfbatch.metaflac import write_metadata as flac
|
||||
|
||||
|
||||
class UnrecognizedCommandError(Exception):
|
||||
@@ -158,6 +158,7 @@ they appear in the batchfile.
|
||||
def __init__(self):
|
||||
self.dry_run = True
|
||||
self.env = CommandEnv()
|
||||
self.write_metadata_f = flac
|
||||
|
||||
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.")
|
||||
else:
|
||||
sys.stdout.write("Writing metadata... ")
|
||||
flac.write_metadata(line, self.env.metadatums)
|
||||
self.write_metadata_f(line, self.env.metadatums)
|
||||
sys.stdout.write("Complete!")
|
||||
|
||||
self.env.increment_all()
|
||||
|
||||
@@ -1,19 +1,36 @@
|
||||
"mfbatch tests"
|
||||
|
||||
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):
|
||||
def setUp(self):
|
||||
self.command_parser = BatchfileParser()
|
||||
self.command_parser.dry_run = False
|
||||
self.command_parser.write_metadata_f = MagicMock()
|
||||
|
||||
def tearDown(self):
|
||||
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):
|
||||
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):
|
||||
self.command_parser.set(['A', '1'])
|
||||
|
||||
Reference in New Issue
Block a user