Address test failures

More details about the fix to the testDuration failure (regression):

```
FAIL: testDuration (whipper.test.test_image_toc.CapitalMergeTestCase)
testDuration
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/twisted/internet/defer.py", line 151, in maybeDeferred
    result = f(*args, **kw)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/twisted/internet/utils.py", line 221, in runWithWarningsSuppressed
    reraise(exc_info[1], exc_info[2])
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/twisted/python/compat.py", line 464, in reraise
    raise exception.with_traceback(traceback)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/twisted/internet/utils.py", line 217, in runWithWarningsSuppressed
    result = f(*a, **kw)
  File "/home/travis/build/whipper-team/whipper/whipper/test/test_image_toc.py", line 271, in testDuration
    self.assertEqual(self.table.getFrameLength(), 173530)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/twisted/trial/_synctest.py", line 432, in assertEqual
    super(_Assertions, self).assertEqual(first, second, msg)
  File "/opt/python/3.5.6/lib/python3.5/unittest/case.py", line 829, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/opt/python/3.5.6/lib/python3.5/unittest/case.py", line 822, in _baseAssertEqual
    raise self.failureException(msg)
twisted.trial.unittest.FailTest: 184930 != 173530
```

The test fails because if either nextTrack.session or thisTrack.session are None the if is false and the instructions inside it aren't executed. The check for None is needed because Python 3 doesn't allow NoneType comparisons (in Python 2 that was possible).
IIRC correctly in that test nextTrack.session has value 2 while thisTrack.session is None. That means the Python 2 version evaluates the if condition to true, while the Python 3 version in the first commit does not.
With this change both of the values of nextTrack.session and thisTrack.session are compared as int (if None, the value 1 is used for the comparison - as in disc session 1).

Regression introduced in 64dd9d843a.

Signed-off-by: JoeLametta <JoeLametta@users.noreply.github.com>
This commit is contained in:
JoeLametta
2019-08-10 09:30:00 +00:00
parent 35201d5290
commit fff3014e15
11 changed files with 38 additions and 33 deletions

View File

@@ -193,7 +193,8 @@ def _match_responses(tracks, responses):
for i, track in enumerate(tracks): for i, track in enumerate(tracks):
for v in ('v1', 'v2'): for v in ('v1', 'v2'):
if track.AR[v]['CRC'] == r.checksums[i]: if track.AR[v]['CRC'] == r.checksums[i]:
if r.confidences[i] > track.AR[v]['DBConfidence']: if (track.AR[v]['DBConfidence'] is None or
r.confidences[i] > track.AR[v]['DBConfidence']):
track.AR[v]['DBCRC'] = r.checksums[i] track.AR[v]['DBCRC'] = r.checksums[i]
track.AR[v]['DBConfidence'] = r.confidences[i] track.AR[v]['DBConfidence'] = r.confidences[i]
logger.debug( logger.debug(
@@ -242,7 +243,8 @@ def print_report(result):
track.AR['v2']['DBCRC'] track.AR['v2']['DBCRC']
) if _f]) ) if _f])
max_conf = max( max_conf = max(
[track.AR[v]['DBConfidence'] for v in ('v1', 'v2')] [track.AR[v]['DBConfidence'] for v in ('v1', 'v2')
if track.AR[v]['DBConfidence'] is not None], default=None
) )
if max_conf: if max_conf:
if max_conf < track.AR['DBMaxConfidence']: if max_conf < track.AR['DBMaxConfidence']:

View File

@@ -98,7 +98,7 @@ class Persister:
if not os.path.exists(self._path): if not os.path.exists(self._path):
return return
handle = open(self._path) handle = open(self._path, 'rb')
import pickle import pickle
try: try:

View File

@@ -44,7 +44,7 @@ class Config:
# Open the file with the correct encoding # Open the file with the correct encoding
if os.path.exists(self._path): if os.path.exists(self._path):
with codecs.open(self._path, 'r', encoding='utf-8') as f: with codecs.open(self._path, 'r', encoding='utf-8') as f:
self._parser.readfp(f) self._parser.read_file(f)
logger.debug('loaded %d sections from config file', logger.debug('loaded %d sections from config file',
len(self._parser.sections())) len(self._parser.sections()))

View File

@@ -91,7 +91,7 @@ class Operator:
Execute the operations Execute the operations
""" """
def next(self): def __next__(self):
operation = self._todo[len(self._done)] operation = self._todo[len(self._done)]
if self._resuming: if self._resuming:
operation.redo() operation.redo()
@@ -199,7 +199,8 @@ class RenameInFile(Operation):
(fd, name) = tempfile.mkstemp(suffix='.whipper') (fd, name) = tempfile.mkstemp(suffix='.whipper')
for s in handle: for s in handle:
os.write(fd, s.replace(self._source, self._destination)) os.write(fd,
s.replace(self._source, self._destination).encode())
os.close(fd) os.close(fd)
os.rename(name, self._path) os.rename(name, self._path)

View File

@@ -220,10 +220,12 @@ class Table:
# if on a session border, subtract the session leadin # if on a session border, subtract the session leadin
thisTrack = self.tracks[number - 1] thisTrack = self.tracks[number - 1]
nextTrack = self.tracks[number] nextTrack = self.tracks[number]
if None not in [thisTrack.session, nextTrack.session]: # The session attribute of a track is None by default (session 1)
if nextTrack.session > thisTrack.session: # with value > 1 if the track is in another session. Py3 doesn't
gap = self._getSessionGap(nextTrack.session) # allow NoneType comparisons so we compare against 1 in that case
end -= gap if int(nextTrack.session or 1) > int(thisTrack.session or 1):
gap = self._getSessionGap(nextTrack.session)
end -= gap
return end return end
@@ -286,7 +288,7 @@ class Table:
offset = self.getTrackStart(track.number) + delta offset = self.getTrackStart(track.number) + delta
offsets.append(offset) offsets.append(offset)
debug.append(str(offset)) debug.append(str(offset))
seconds = offset / common.FRAMES_PER_SECOND seconds = offset // common.FRAMES_PER_SECOND
n += self._cddbSum(seconds) n += self._cddbSum(seconds)
# the 'real' leadout, not offset by 150 frames # the 'real' leadout, not offset by 150 frames
@@ -389,11 +391,11 @@ class Table:
discid = self.getMusicBrainzDiscId() discid = self.getMusicBrainzDiscId()
values = self._getMusicBrainzValues() values = self._getMusicBrainzValues()
query = urlencode({ query = urlencode([
'id': discid, ('toc', ' '.join([str(v) for v in values])),
'toc': ' '.join([str(v) for v in values]), ('tracks', self.getAudioTracks()),
'tracks': self.getAudioTracks(), ('id', discid),
}) ])
return urlunparse(( return urlunparse((
'https', host, '/cdtoc/attach', '', query, '')) 'https', host, '/cdtoc/attach', '', query, ''))

View File

@@ -70,7 +70,7 @@ class TestCase(unittest.TestCase):
version so we can use it in comparisons. version so we can use it in comparisons.
""" """
cuefile = os.path.join(os.path.dirname(__file__), name) cuefile = os.path.join(os.path.dirname(__file__), name)
ret = open(cuefile).read().decode('utf-8') ret = open(cuefile).read()
ret = re.sub( ret = re.sub(
'REM COMMENT "whipper.*', 'REM COMMENT "whipper.*',
'REM COMMENT "whipper %s"' % whipper.__version__, 'REM COMMENT "whipper %s"' % whipper.__version__,

View File

@@ -16,7 +16,7 @@ class MBLookupTestCase(unittest.TestCase):
"""Mock function for whipper.common.mbngs.musicbrainz function.""" """Mock function for whipper.common.mbngs.musicbrainz function."""
filename = "whipper.discid.{}.pickle".format(discid) filename = "whipper.discid.{}.pickle".format(discid)
path = os.path.join(os.path.dirname(__file__), filename) path = os.path.join(os.path.dirname(__file__), filename)
with open(path) as p: with open(path, "rb") as p:
return pickle.load(p) return pickle.load(p)
def testMissingReleaseType(self): def testMissingReleaseType(self):

View File

@@ -2,7 +2,7 @@
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
import sys import sys
from StringIO import StringIO from io import StringIO
from os import chmod, makedirs from os import chmod, makedirs
from os.path import dirname, exists, join from os.path import dirname, exists, join
from shutil import copy, rmtree from shutil import copy, rmtree
@@ -22,7 +22,7 @@ class TestAccurateRipResponse(TestCase):
def setUpClass(cls): def setUpClass(cls):
cls.path = 'c/1/2/dBAR-002-0000f21c-00027ef8-05021002.bin' cls.path = 'c/1/2/dBAR-002-0000f21c-00027ef8-05021002.bin'
cls.entry = _split_responses( cls.entry = _split_responses(
open(join(dirname(__file__), cls.path[6:])).read() open(join(dirname(__file__), cls.path[6:]), "rb").read()
) )
cls.other_path = '4/8/2/dBAR-011-0010e284-009228a3-9809ff0b.bin' cls.other_path = '4/8/2/dBAR-011-0010e284-009228a3-9809ff0b.bin'
@@ -101,7 +101,7 @@ class TestVerifyResult(TestCase):
def setUpClass(cls): def setUpClass(cls):
path = 'c/1/2/dBAR-002-0000f21c-00027ef8-05021002.bin' path = 'c/1/2/dBAR-002-0000f21c-00027ef8-05021002.bin'
cls.responses = _split_responses( cls.responses = _split_responses(
open(join(dirname(__file__), path[6:])).read() open(join(dirname(__file__), path[6:]), "rb").read()
) )
cls.checksums = { cls.checksums = {
'v1': ['284fc705', '9cc1f32e'], 'v1': ['284fc705', '9cc1f32e'],

View File

@@ -18,7 +18,7 @@ class MetadataTestCase(unittest.TestCase):
filename = 'whipper.release.c56ff16e-1d81-47de-926f-ba22891bd2bd.json' filename = 'whipper.release.c56ff16e-1d81-47de-926f-ba22891bd2bd.json'
path = os.path.join(os.path.dirname(__file__), filename) path = os.path.join(os.path.dirname(__file__), filename)
handle = open(path, "rb") handle = open(path, "rb")
response = json.loads(handle.read()) response = json.loads(handle.read().decode('utf-8'))
handle.close() handle.close()
discid = "b.yqPuCBdsV5hrzDvYrw52iK_jE-" discid = "b.yqPuCBdsV5hrzDvYrw52iK_jE-"
@@ -31,7 +31,7 @@ class MetadataTestCase(unittest.TestCase):
filename = 'whipper.release.a76714e0-32b1-4ed4-b28e-f86d99642193.json' filename = 'whipper.release.a76714e0-32b1-4ed4-b28e-f86d99642193.json'
path = os.path.join(os.path.dirname(__file__), filename) path = os.path.join(os.path.dirname(__file__), filename)
handle = open(path, "rb") handle = open(path, "rb")
response = json.loads(handle.read()) response = json.loads(handle.read().decode('utf-8'))
handle.close() handle.close()
discid = "f7XO36a7n1LCCskkCiulReWbwZA-" discid = "f7XO36a7n1LCCskkCiulReWbwZA-"
@@ -59,7 +59,7 @@ class MetadataTestCase(unittest.TestCase):
filename = 'whipper.release.e32ae79a-336e-4d33-945c-8c5e8206dbd3.json' filename = 'whipper.release.e32ae79a-336e-4d33-945c-8c5e8206dbd3.json'
path = os.path.join(os.path.dirname(__file__), filename) path = os.path.join(os.path.dirname(__file__), filename)
handle = open(path, "rb") handle = open(path, "rb")
response = json.loads(handle.read()) response = json.loads(handle.read().decode('utf-8'))
handle.close() handle.close()
discid = "xAq8L4ELMW14.6wI6tt7QAcxiDI-" discid = "xAq8L4ELMW14.6wI6tt7QAcxiDI-"
@@ -93,7 +93,7 @@ class MetadataTestCase(unittest.TestCase):
filename = 'whipper.release.61c6fd9b-18f8-4a45-963a-ba3c5d990cae.json' filename = 'whipper.release.61c6fd9b-18f8-4a45-963a-ba3c5d990cae.json'
path = os.path.join(os.path.dirname(__file__), filename) path = os.path.join(os.path.dirname(__file__), filename)
handle = open(path, "rb") handle = open(path, "rb")
response = json.loads(handle.read()) response = json.loads(handle.read().decode('utf-8'))
handle.close() handle.close()
discid = "u0aKVpO.59JBy6eQRX2vYcoqQZ0-" discid = "u0aKVpO.59JBy6eQRX2vYcoqQZ0-"
@@ -130,7 +130,7 @@ class MetadataTestCase(unittest.TestCase):
filename = 'whipper.release.8478d4da-0cda-4e46-ae8c-1eeacfa5cf37.json' filename = 'whipper.release.8478d4da-0cda-4e46-ae8c-1eeacfa5cf37.json'
path = os.path.join(os.path.dirname(__file__), filename) path = os.path.join(os.path.dirname(__file__), filename)
handle = open(path, "rb") handle = open(path, "rb")
response = json.loads(handle.read()) response = json.loads(handle.read().decode('utf-8'))
handle.close() handle.close()
discid = "RhrwgVb0hZNkabQCw1dZIhdbMFg-" discid = "RhrwgVb0hZNkabQCw1dZIhdbMFg-"
@@ -167,7 +167,7 @@ class MetadataTestCase(unittest.TestCase):
filename = 'whipper.release.f484a9fc-db21-4106-9408-bcd105c90047.json' filename = 'whipper.release.f484a9fc-db21-4106-9408-bcd105c90047.json'
path = os.path.join(os.path.dirname(__file__), filename) path = os.path.join(os.path.dirname(__file__), filename)
handle = open(path, "rb") handle = open(path, "rb")
response = json.loads(handle.read()) response = json.loads(handle.read().decode('utf-8'))
handle.close() handle.close()
discid = "X2c2IQ5vUy5x6Jh7Xi_DGHtA1X8-" discid = "X2c2IQ5vUy5x6Jh7Xi_DGHtA1X8-"
@@ -214,7 +214,7 @@ class MetadataTestCase(unittest.TestCase):
filename = 'whipper.release.d8e6153a-2c47-4804-9d73-0aac1081c3b1.json' filename = 'whipper.release.d8e6153a-2c47-4804-9d73-0aac1081c3b1.json'
path = os.path.join(os.path.dirname(__file__), filename) path = os.path.join(os.path.dirname(__file__), filename)
handle = open(path, "rb") handle = open(path, "rb")
response = json.loads(handle.read()) response = json.loads(handle.read().decode('utf-8'))
handle.close() handle.close()
discid = "xu338_M8WukSRi0J.KTlDoflB8Y-" # disc 4 discid = "xu338_M8WukSRi0J.KTlDoflB8Y-" # disc 4
@@ -228,7 +228,7 @@ class MetadataTestCase(unittest.TestCase):
filename = 'whipper.release.6109ceed-7e21-490b-b5ad-3a66b4e4cfbb.json' filename = 'whipper.release.6109ceed-7e21-490b-b5ad-3a66b4e4cfbb.json'
path = os.path.join(os.path.dirname(__file__), filename) path = os.path.join(os.path.dirname(__file__), filename)
handle = open(path, "rb") handle = open(path, "rb")
response = json.loads(handle.read()) response = json.loads(handle.read().decode('utf-8'))
handle.close() handle.close()
discid = "cHW1Uutl_kyWNaLJsLmTGTe4rnE-" discid = "cHW1Uutl_kyWNaLJsLmTGTe4rnE-"

View File

@@ -13,7 +13,7 @@ class RenameInFileTestcase(unittest.TestCase):
def setUp(self): def setUp(self):
(fd, self._path) = tempfile.mkstemp(suffix='.whipper.renamer.infile') (fd, self._path) = tempfile.mkstemp(suffix='.whipper.renamer.infile')
os.write(fd, 'This is a test\nThis is another\n') os.write(fd, 'This is a test\nThis is another\n'.encode())
os.close(fd) os.close(fd)
def testVerify(self): def testVerify(self):
@@ -43,7 +43,7 @@ class RenameFileTestcase(unittest.TestCase):
def setUp(self): def setUp(self):
(fd, self._source) = tempfile.mkstemp(suffix='.whipper.renamer.file') (fd, self._source) = tempfile.mkstemp(suffix='.whipper.renamer.file')
os.write(fd, 'This is a test\nThis is another\n') os.write(fd, 'This is a test\nThis is another\n'.encode())
os.close(fd) os.close(fd)
(fd, self._destination) = tempfile.mkstemp( (fd, self._destination) = tempfile.mkstemp(
suffix='.whipper.renamer.file') suffix='.whipper.renamer.file')
@@ -87,7 +87,7 @@ class OperatorTestCase(unittest.TestCase):
(fd, self._source) = tempfile.mkstemp( (fd, self._source) = tempfile.mkstemp(
suffix='.whipper.renamer.operator') suffix='.whipper.renamer.operator')
os.write(fd, 'This is a test\nThis is another\n') os.write(fd, 'This is a test\nThis is another\n'.encode())
os.close(fd) os.close(fd)
(fd, self._destination) = tempfile.mkstemp( (fd, self._destination) = tempfile.mkstemp(
suffix='.whipper.renamer.operator') suffix='.whipper.renamer.operator')

View File

@@ -364,7 +364,7 @@ class StrokesTestCase(common.TestCase):
ref = self._filterCue( ref = self._filterCue(
open(os.path.join( open(os.path.join(
os.path.dirname(__file__), os.path.dirname(__file__),
'strokes-someday.eac.cue')).read()).decode('utf-8') 'strokes-someday.eac.cue')).read())
common.diffStrings(ref, cue) common.diffStrings(ref, cue)
@staticmethod @staticmethod