* introduce logcommand.Lager, Whipper(); use argparse for whipper image commands, stub logging * update Lager docstring to mention config.Config() * make incorrect subcommand and --version work on toplevel command * migrate accurip show, expand Lager, do not attempt to return from Lager.__init__. * migrate offset find, add Lager.error * correct offset find drive symlink handling * migrate drive * change Lager.__init__(prog) to arg from kwarg * but actually * remove Whipper.usage * add and use Lager.device_option() context manager * help I married an axe murderer * use unified options namespace for entire command tree * migrate whipper cd without comprehensive config loading * switch to logging module - use logging instead of flog for non-extern modules - use WHIPPER_DEBUG and WHIPPER_LOGFILE env variables * convert self.log calls to logger.debug * convert self.error calls to logger.error * remove log.Loggable, use logger not logging * Logging conversion continues - Convert log.* calls to logger.* - Remove morituri.common.log imports * remove morituri.common.log from tests * remove extern/flog, bare minimum Debug conversion * update README for logging changes * update soxi to use logging * refactor Lager for more declarative subcommands * Refactor Lager.device_option: - inline into __init__ - throw IOError instead of Exception for missing drives - remove CommandError checking in rip/main * rename rip to whipper in rip.main * convert rip.debug commands * Rename logcommand.Lager to command.BaseCommand - remove command.CommandError occurrences - remove python-command external module * remove submodules from README, update rclog formatter * update minor ambiguity in readme for command invocation * update version number to match setup.py * remove gitmodules * update version number in tests as well (boo) * convert logger.error to logger.critical * Change morituri.rip to morituri.command - mv common.command to command.basecommand - move TEMPLATES used only by rip.cd out of rip.common - update entry point for command to command.main * update basecommand documentation * go pyflaking: import fixing * replace self.stdout with sys.stdout * remove BaseCommand.config, alphabetise imports * convert self.stdXXX leftovers * convert last getRootCommand to config.Config * convert last getExceptionMessage's to str * change musicbrainz useragent to whipper
119 lines
4.1 KiB
Python
119 lines
4.1 KiB
Python
# -*- Mode: Python; test-case-name: morituri.test.test_common_program -*-
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
|
|
import os
|
|
import pickle
|
|
|
|
import unittest
|
|
|
|
from morituri.result import result
|
|
from morituri.common import program, accurip, mbngs, config
|
|
from morituri.command.cd import DEFAULT_DISC_TEMPLATE
|
|
|
|
|
|
class TrackImageVerifyTestCase(unittest.TestCase):
|
|
# example taken from a rip of Luke Haines Is Dead, disc 1
|
|
# AccurateRip database has 0 confidence for 1st track
|
|
# Rip had a wrong result for track 9
|
|
|
|
def testVerify(self):
|
|
path = os.path.join(os.path.dirname(__file__),
|
|
'dBAR-020-002e5023-029d8e49-040eaa14.bin')
|
|
data = open(path, "rb").read()
|
|
responses = accurip.getAccurateRipResponses(data)
|
|
|
|
# these crc's were calculated from an actual rip
|
|
checksums = [1644890007, 2945205445, 3983436658, 1528082495,
|
|
1203704270, 1163423644, 3649097244, 100524219, 1583356174, 373652058,
|
|
1842579359, 2850056507, 1329730252, 2526965856, 2525886806, 209743350,
|
|
3184062337, 2099956663, 2943874164, 2321637196]
|
|
|
|
prog = program.Program(config.Config())
|
|
prog.result = result.RipResult()
|
|
# fill it with empty trackresults
|
|
for i, c in enumerate(checksums):
|
|
r = result.TrackResult()
|
|
r.number = i + 1
|
|
prog.result.tracks.append(r)
|
|
|
|
prog._verifyImageWithChecksums(responses, checksums)
|
|
|
|
# now check if the results were filled in properly
|
|
tr = prog.result.getTrackResult(1)
|
|
self.assertEquals(tr.accurip, False)
|
|
self.assertEquals(tr.ARDBMaxConfidence, 0)
|
|
self.assertEquals(tr.ARDBCRC, 0)
|
|
self.assertEquals(tr.ARDBCRC, 0)
|
|
|
|
tr = prog.result.getTrackResult(2)
|
|
self.assertEquals(tr.accurip, True)
|
|
self.assertEquals(tr.ARDBMaxConfidence, 2)
|
|
self.assertEquals(tr.ARDBCRC, checksums[2 - 1])
|
|
|
|
tr = prog.result.getTrackResult(10)
|
|
self.assertEquals(tr.accurip, False)
|
|
self.assertEquals(tr.ARDBMaxConfidence, 2)
|
|
# we know track 10 was ripped wrong
|
|
self.assertNotEquals(tr.ARDBCRC, checksums[10 - 1])
|
|
|
|
res = prog.getAccurateRipResults()
|
|
self.assertEquals(res[1 - 1],
|
|
"Track 1: rip NOT accurate (not found) "
|
|
"[620b0797], DB [notfound]")
|
|
self.assertEquals(res[2 - 1],
|
|
"Track 2: rip accurate (max confidence 2) "
|
|
"[af8c44c5], DB [af8c44c5]")
|
|
self.assertEquals(res[10 - 1],
|
|
"Track 10: rip NOT accurate (max confidence 2) "
|
|
"[16457a5a], DB [eb6e55b4]")
|
|
|
|
|
|
class HTOATestCase(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
path = os.path.join(os.path.dirname(__file__),
|
|
'silentalarm.result.pickle')
|
|
self._tracks = pickle.load(open(path, 'rb'))
|
|
|
|
def testGetAccurateRipResults(self):
|
|
prog = program.Program(config.Config())
|
|
prog.result = result.RipResult()
|
|
prog.result.tracks = self._tracks
|
|
|
|
prog.getAccurateRipResults()
|
|
|
|
|
|
class PathTestCase(unittest.TestCase):
|
|
|
|
def testStandardTemplateEmpty(self):
|
|
prog = program.Program(config.Config())
|
|
|
|
path = prog.getPath(u'/tmp', DEFAULT_DISC_TEMPLATE,
|
|
'mbdiscid', 0)
|
|
self.assertEquals(path,
|
|
u'/tmp/unknown/Unknown Artist - mbdiscid/Unknown Artist - mbdiscid')
|
|
|
|
def testStandardTemplateFilled(self):
|
|
prog = program.Program(config.Config())
|
|
md = mbngs.DiscMetadata()
|
|
md.artist = md.sortName = 'Jeff Buckley'
|
|
md.title = 'Grace'
|
|
prog.metadata = md
|
|
|
|
path = prog.getPath(u'/tmp', DEFAULT_DISC_TEMPLATE,
|
|
'mbdiscid', 0)
|
|
self.assertEquals(path,
|
|
u'/tmp/unknown/Jeff Buckley - Grace/Jeff Buckley - Grace')
|
|
|
|
def testIssue66TemplateFilled(self):
|
|
prog = program.Program(config.Config())
|
|
md = mbngs.DiscMetadata()
|
|
md.artist = md.sortName = 'Jeff Buckley'
|
|
md.title = 'Grace'
|
|
prog.metadata = md
|
|
|
|
path = prog.getPath(u'/tmp', u'%A/%d', 'mbdiscid', 0)
|
|
self.assertEquals(path,
|
|
u'/tmp/Jeff Buckley/Grace')
|