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:
@@ -193,7 +193,8 @@ def _match_responses(tracks, responses):
|
||||
for i, track in enumerate(tracks):
|
||||
for v in ('v1', 'v2'):
|
||||
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]['DBConfidence'] = r.confidences[i]
|
||||
logger.debug(
|
||||
@@ -242,7 +243,8 @@ def print_report(result):
|
||||
track.AR['v2']['DBCRC']
|
||||
) if _f])
|
||||
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 < track.AR['DBMaxConfidence']:
|
||||
|
||||
@@ -98,7 +98,7 @@ class Persister:
|
||||
if not os.path.exists(self._path):
|
||||
return
|
||||
|
||||
handle = open(self._path)
|
||||
handle = open(self._path, 'rb')
|
||||
import pickle
|
||||
|
||||
try:
|
||||
|
||||
@@ -44,7 +44,7 @@ class Config:
|
||||
# Open the file with the correct encoding
|
||||
if os.path.exists(self._path):
|
||||
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',
|
||||
len(self._parser.sections()))
|
||||
|
||||
@@ -91,7 +91,7 @@ class Operator:
|
||||
Execute the operations
|
||||
"""
|
||||
|
||||
def next(self):
|
||||
def __next__(self):
|
||||
operation = self._todo[len(self._done)]
|
||||
if self._resuming:
|
||||
operation.redo()
|
||||
@@ -199,7 +199,8 @@ class RenameInFile(Operation):
|
||||
(fd, name) = tempfile.mkstemp(suffix='.whipper')
|
||||
|
||||
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.rename(name, self._path)
|
||||
|
||||
@@ -220,10 +220,12 @@ class Table:
|
||||
# if on a session border, subtract the session leadin
|
||||
thisTrack = self.tracks[number - 1]
|
||||
nextTrack = self.tracks[number]
|
||||
if None not in [thisTrack.session, nextTrack.session]:
|
||||
if nextTrack.session > thisTrack.session:
|
||||
gap = self._getSessionGap(nextTrack.session)
|
||||
end -= gap
|
||||
# The session attribute of a track is None by default (session 1)
|
||||
# with value > 1 if the track is in another session. Py3 doesn't
|
||||
# allow NoneType comparisons so we compare against 1 in that case
|
||||
if int(nextTrack.session or 1) > int(thisTrack.session or 1):
|
||||
gap = self._getSessionGap(nextTrack.session)
|
||||
end -= gap
|
||||
|
||||
return end
|
||||
|
||||
@@ -286,7 +288,7 @@ class Table:
|
||||
offset = self.getTrackStart(track.number) + delta
|
||||
offsets.append(offset)
|
||||
debug.append(str(offset))
|
||||
seconds = offset / common.FRAMES_PER_SECOND
|
||||
seconds = offset // common.FRAMES_PER_SECOND
|
||||
n += self._cddbSum(seconds)
|
||||
|
||||
# the 'real' leadout, not offset by 150 frames
|
||||
@@ -389,11 +391,11 @@ class Table:
|
||||
discid = self.getMusicBrainzDiscId()
|
||||
values = self._getMusicBrainzValues()
|
||||
|
||||
query = urlencode({
|
||||
'id': discid,
|
||||
'toc': ' '.join([str(v) for v in values]),
|
||||
'tracks': self.getAudioTracks(),
|
||||
})
|
||||
query = urlencode([
|
||||
('toc', ' '.join([str(v) for v in values])),
|
||||
('tracks', self.getAudioTracks()),
|
||||
('id', discid),
|
||||
])
|
||||
|
||||
return urlunparse((
|
||||
'https', host, '/cdtoc/attach', '', query, ''))
|
||||
|
||||
@@ -70,7 +70,7 @@ class TestCase(unittest.TestCase):
|
||||
version so we can use it in comparisons.
|
||||
"""
|
||||
cuefile = os.path.join(os.path.dirname(__file__), name)
|
||||
ret = open(cuefile).read().decode('utf-8')
|
||||
ret = open(cuefile).read()
|
||||
ret = re.sub(
|
||||
'REM COMMENT "whipper.*',
|
||||
'REM COMMENT "whipper %s"' % whipper.__version__,
|
||||
|
||||
@@ -16,7 +16,7 @@ class MBLookupTestCase(unittest.TestCase):
|
||||
"""Mock function for whipper.common.mbngs.musicbrainz function."""
|
||||
filename = "whipper.discid.{}.pickle".format(discid)
|
||||
path = os.path.join(os.path.dirname(__file__), filename)
|
||||
with open(path) as p:
|
||||
with open(path, "rb") as p:
|
||||
return pickle.load(p)
|
||||
|
||||
def testMissingReleaseType(self):
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
|
||||
import sys
|
||||
from StringIO import StringIO
|
||||
from io import StringIO
|
||||
from os import chmod, makedirs
|
||||
from os.path import dirname, exists, join
|
||||
from shutil import copy, rmtree
|
||||
@@ -22,7 +22,7 @@ class TestAccurateRipResponse(TestCase):
|
||||
def setUpClass(cls):
|
||||
cls.path = 'c/1/2/dBAR-002-0000f21c-00027ef8-05021002.bin'
|
||||
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'
|
||||
|
||||
@@ -101,7 +101,7 @@ class TestVerifyResult(TestCase):
|
||||
def setUpClass(cls):
|
||||
path = 'c/1/2/dBAR-002-0000f21c-00027ef8-05021002.bin'
|
||||
cls.responses = _split_responses(
|
||||
open(join(dirname(__file__), path[6:])).read()
|
||||
open(join(dirname(__file__), path[6:]), "rb").read()
|
||||
)
|
||||
cls.checksums = {
|
||||
'v1': ['284fc705', '9cc1f32e'],
|
||||
|
||||
@@ -18,7 +18,7 @@ class MetadataTestCase(unittest.TestCase):
|
||||
filename = 'whipper.release.c56ff16e-1d81-47de-926f-ba22891bd2bd.json'
|
||||
path = os.path.join(os.path.dirname(__file__), filename)
|
||||
handle = open(path, "rb")
|
||||
response = json.loads(handle.read())
|
||||
response = json.loads(handle.read().decode('utf-8'))
|
||||
handle.close()
|
||||
discid = "b.yqPuCBdsV5hrzDvYrw52iK_jE-"
|
||||
|
||||
@@ -31,7 +31,7 @@ class MetadataTestCase(unittest.TestCase):
|
||||
filename = 'whipper.release.a76714e0-32b1-4ed4-b28e-f86d99642193.json'
|
||||
path = os.path.join(os.path.dirname(__file__), filename)
|
||||
handle = open(path, "rb")
|
||||
response = json.loads(handle.read())
|
||||
response = json.loads(handle.read().decode('utf-8'))
|
||||
handle.close()
|
||||
discid = "f7XO36a7n1LCCskkCiulReWbwZA-"
|
||||
|
||||
@@ -59,7 +59,7 @@ class MetadataTestCase(unittest.TestCase):
|
||||
filename = 'whipper.release.e32ae79a-336e-4d33-945c-8c5e8206dbd3.json'
|
||||
path = os.path.join(os.path.dirname(__file__), filename)
|
||||
handle = open(path, "rb")
|
||||
response = json.loads(handle.read())
|
||||
response = json.loads(handle.read().decode('utf-8'))
|
||||
handle.close()
|
||||
discid = "xAq8L4ELMW14.6wI6tt7QAcxiDI-"
|
||||
|
||||
@@ -93,7 +93,7 @@ class MetadataTestCase(unittest.TestCase):
|
||||
filename = 'whipper.release.61c6fd9b-18f8-4a45-963a-ba3c5d990cae.json'
|
||||
path = os.path.join(os.path.dirname(__file__), filename)
|
||||
handle = open(path, "rb")
|
||||
response = json.loads(handle.read())
|
||||
response = json.loads(handle.read().decode('utf-8'))
|
||||
handle.close()
|
||||
discid = "u0aKVpO.59JBy6eQRX2vYcoqQZ0-"
|
||||
|
||||
@@ -130,7 +130,7 @@ class MetadataTestCase(unittest.TestCase):
|
||||
filename = 'whipper.release.8478d4da-0cda-4e46-ae8c-1eeacfa5cf37.json'
|
||||
path = os.path.join(os.path.dirname(__file__), filename)
|
||||
handle = open(path, "rb")
|
||||
response = json.loads(handle.read())
|
||||
response = json.loads(handle.read().decode('utf-8'))
|
||||
handle.close()
|
||||
discid = "RhrwgVb0hZNkabQCw1dZIhdbMFg-"
|
||||
|
||||
@@ -167,7 +167,7 @@ class MetadataTestCase(unittest.TestCase):
|
||||
filename = 'whipper.release.f484a9fc-db21-4106-9408-bcd105c90047.json'
|
||||
path = os.path.join(os.path.dirname(__file__), filename)
|
||||
handle = open(path, "rb")
|
||||
response = json.loads(handle.read())
|
||||
response = json.loads(handle.read().decode('utf-8'))
|
||||
handle.close()
|
||||
discid = "X2c2IQ5vUy5x6Jh7Xi_DGHtA1X8-"
|
||||
|
||||
@@ -214,7 +214,7 @@ class MetadataTestCase(unittest.TestCase):
|
||||
filename = 'whipper.release.d8e6153a-2c47-4804-9d73-0aac1081c3b1.json'
|
||||
path = os.path.join(os.path.dirname(__file__), filename)
|
||||
handle = open(path, "rb")
|
||||
response = json.loads(handle.read())
|
||||
response = json.loads(handle.read().decode('utf-8'))
|
||||
handle.close()
|
||||
discid = "xu338_M8WukSRi0J.KTlDoflB8Y-" # disc 4
|
||||
|
||||
@@ -228,7 +228,7 @@ class MetadataTestCase(unittest.TestCase):
|
||||
filename = 'whipper.release.6109ceed-7e21-490b-b5ad-3a66b4e4cfbb.json'
|
||||
path = os.path.join(os.path.dirname(__file__), filename)
|
||||
handle = open(path, "rb")
|
||||
response = json.loads(handle.read())
|
||||
response = json.loads(handle.read().decode('utf-8'))
|
||||
handle.close()
|
||||
discid = "cHW1Uutl_kyWNaLJsLmTGTe4rnE-"
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class RenameInFileTestcase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
(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)
|
||||
|
||||
def testVerify(self):
|
||||
@@ -43,7 +43,7 @@ class RenameFileTestcase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
(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)
|
||||
(fd, self._destination) = tempfile.mkstemp(
|
||||
suffix='.whipper.renamer.file')
|
||||
@@ -87,7 +87,7 @@ class OperatorTestCase(unittest.TestCase):
|
||||
|
||||
(fd, self._source) = tempfile.mkstemp(
|
||||
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)
|
||||
(fd, self._destination) = tempfile.mkstemp(
|
||||
suffix='.whipper.renamer.operator')
|
||||
|
||||
@@ -364,7 +364,7 @@ class StrokesTestCase(common.TestCase):
|
||||
ref = self._filterCue(
|
||||
open(os.path.join(
|
||||
os.path.dirname(__file__),
|
||||
'strokes-someday.eac.cue')).read()).decode('utf-8')
|
||||
'strokes-someday.eac.cue')).read())
|
||||
common.diffStrings(ref, cue)
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user