fix visual diff for non-string values (#235)

This commit is contained in:
Adrian Sampson 2011-09-15 14:45:31 -07:00
parent 94569a774e
commit e2b7a7514d
2 changed files with 24 additions and 0 deletions

View file

@ -68,6 +68,8 @@ def _do_query(lib, query, album, also_items=True):
def _showdiff(field, oldval, newval, color):
"""Prints out a human-readable field difference line."""
if newval != oldval:
oldval = unicode(newval)
newval = unicode(newval)
if color:
oldval, newval = ui.colordiff(oldval, newval)
print_(u' %s: %s -> %s' % (field, oldval, newval))

View file

@ -502,6 +502,28 @@ class ConfigTest(unittest.TestCase):
library: /xxx/yyy/not/a/real/path
"""), func)
class UtilTest(unittest.TestCase):
def setUp(self):
self.io = _common.DummyIO()
self.io.install()
def tearDown(self):
self.io.restore()
def test_showdiff_strings(self):
commands._showdiff('field', 'old', 'new', True)
out = self.io.getoutput()
self.assertTrue('field' in out)
def test_showdiff_identical(self):
commands._showdiff('field', 'old', 'old', True)
out = self.io.getoutput()
self.assertFalse('field' in out)
def test_showdiff_ints(self):
commands._showdiff('field', 2, 3, True)
out = self.io.getoutput()
self.assertTrue('field' in out)
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)