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>
91 lines
2.4 KiB
Python
91 lines
2.4 KiB
Python
# -*- Mode: Python -*-
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
import re
|
|
import os
|
|
import sys
|
|
|
|
import whipper
|
|
|
|
# twisted's unittests have skip support, standard unittest don't
|
|
from twisted.trial import unittest
|
|
|
|
# lifted from flumotion
|
|
|
|
|
|
def _diff(old, new, desc):
|
|
import difflib
|
|
lines = difflib.unified_diff(old, new)
|
|
lines = list(lines)
|
|
if not lines:
|
|
return
|
|
output = ''
|
|
for line in lines:
|
|
output += '%s: %s\n' % (desc, line[:-1])
|
|
|
|
raise AssertionError(
|
|
("\nError while comparing strings:\n"
|
|
"%s") % (output.encode('utf-8'), ))
|
|
|
|
|
|
def diffStrings(orig, new, desc='input'):
|
|
|
|
assert isinstance(orig, type(new)), 'type %s and %s are different' % (
|
|
type(orig), type(new))
|
|
|
|
def _tolines(s):
|
|
return [line + '\n' for line in s.split('\n')]
|
|
|
|
return _diff(_tolines(orig),
|
|
_tolines(new),
|
|
desc=desc)
|
|
|
|
|
|
class TestCase(unittest.TestCase):
|
|
# unittest.TestCase.failUnlessRaises does not return the exception,
|
|
# and we'd like to check for the actual exception under TaskException,
|
|
# so override the way twisted.trial.unittest does, without failure
|
|
|
|
# XXX: Pylint, method could be a function (no-self-use)
|
|
def failUnlessRaises(self, exception, f, *args, **kwargs):
|
|
try:
|
|
result = f(*args, **kwargs)
|
|
except exception as inst:
|
|
return inst
|
|
except exception as e:
|
|
raise Exception('%s raised instead of %s:\n %s' %
|
|
(sys.exc_info()[0], exception.__name__, str(e))
|
|
)
|
|
else:
|
|
raise Exception('%s not raised (%r returned)' %
|
|
(exception.__name__, result)
|
|
)
|
|
|
|
assertRaises = failUnlessRaises
|
|
|
|
@staticmethod
|
|
def readCue(name):
|
|
"""
|
|
Read a .cue file, and replace the version comment with the current
|
|
version so we can use it in comparisons.
|
|
"""
|
|
cuefile = os.path.join(os.path.dirname(__file__), name)
|
|
ret = open(cuefile).read()
|
|
ret = re.sub(
|
|
'REM COMMENT "whipper.*',
|
|
'REM COMMENT "whipper %s"' % whipper.__version__,
|
|
ret, re.MULTILINE)
|
|
|
|
return ret
|
|
|
|
|
|
class UnicodeTestMixin:
|
|
# A helper mixin to skip tests if we're not in a UTF-8 locale
|
|
|
|
try:
|
|
os.stat('whipper.test.B\xeate Noire.empty')
|
|
except UnicodeEncodeError:
|
|
skip = 'No UTF-8 locale'
|
|
except OSError:
|
|
pass
|