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

@@ -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, ''))