From 645279e022c203608c84616443dc123b70c59ed8 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sat, 22 Feb 2014 14:52:33 -0800 Subject: [PATCH] remove old _showdiff Totally replaced now, including tests! Woohoo. --- beets/ui/commands.py | 19 ----------- test/test_ui.py | 79 ++++++++++++++++++++++---------------------- 2 files changed, 40 insertions(+), 58 deletions(-) diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 49f64bd3b..d6caf9ff0 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -76,25 +76,6 @@ def _do_query(lib, query, album, also_items=True): FLOAT_EPSILON = 0.01 -def _showdiff(field, oldval, newval): - """Print out a human-readable field difference line if `oldval` and - `newval` differ. Return a boolean indicating whether anything was printed - (i.e., if any change needs to be made). - """ - # Considering floats incomparable for perfect equality, introduce - # an epsilon tolerance. - if isinstance(oldval, float) and isinstance(newval, float) and \ - abs(oldval - newval) < FLOAT_EPSILON: - return False - - if newval != oldval: - oldval, newval = ui.colordiff(oldval, newval) - print_(u' %s: %s -> %s' % (field, oldval, newval)) - return True - - return False - - def _field_diff(field, old, new): """Given two Model objects, format their values for `field` and highlight changes among them. Return a human-readable string. If the diff --git a/test/test_ui.py b/test/test_ui.py index 14898879d..db4711132 100644 --- a/test/test_ui.py +++ b/test/test_ui.py @@ -714,56 +714,57 @@ class ConfigTest(_common.TestCase): os.path.join(self.beetsdir, 'state')) -class ShowdiffTest(_common.TestCase): +class ShowModelChangeTest(_common.TestCase): def setUp(self): - super(ShowdiffTest, self).setUp() + super(ShowModelChangeTest, self).setUp() self.io.install() + self.a = _common.item() + self.b = _common.item() + self.a.path = self.b.path - def test_showdiff_strings(self): - commands._showdiff('field', 'old', 'new') + def _show(self, **kwargs): + change = commands._show_model_changes(self.a, self.b, **kwargs) out = self.io.getoutput() - self.assertTrue('field' in out) + return change, out - def test_showdiff_identical(self): - commands._showdiff('field', 'old', 'old') - out = self.io.getoutput() - self.assertFalse('field' in out) + def test_identical(self): + change, out = self._show() + self.assertFalse(change) + self.assertEqual(out, '') - def test_showdiff_ints(self): - commands._showdiff('field', 2, 3) - out = self.io.getoutput() - self.assertTrue('field' in out) + def test_string_fixed_field_change(self): + self.b.title = 'x' + change, out = self._show() + self.assertTrue(change) + self.assertTrue('title' in out) - def test_showdiff_ints_no_color(self): - config['color'] = False - commands._showdiff('field', 2, 3) - out = self.io.getoutput() - self.assertTrue('field' in out) + def test_int_fixed_field_change(self): + self.b.track = 9 + change, out = self._show() + self.assertTrue(change) + self.assertTrue('track' in out) - def test_showdiff_shows_both(self): - commands._showdiff('field', 'old', 'new') - out = self.io.getoutput() - self.assertTrue('old' in out) - self.assertTrue('new' in out) + def test_floats_close_to_identical(self): + self.a.length = 1.00001 + self.b.length = 1.00005 + change, out = self._show() + self.assertFalse(change) + self.assertEqual(out, '') - def test_showdiff_floats_close_to_identical(self): - commands._showdiff('field', 1.999, 2.001) - out = self.io.getoutput() - self.assertFalse('field' in out) + def test_floats_different(self): + self.a.length = 1.00001 + self.b.length = 2.00001 + change, out = self._show() + self.assertTrue(change) + self.assertTrue('length' in out) - def test_showdiff_floats_differenct(self): - commands._showdiff('field', 1.999, 4.001) - out = self.io.getoutput() - self.assertTrue('field' in out) + def test_both_values_shown(self): + self.a.title = 'foo' + self.b.title = 'bar' + change, out = self._show() + self.assertTrue('foo' in out) + self.assertTrue('bar' in out) - def test_showdiff_ints_colorizing_is_not_stringwise(self): - commands._showdiff('field', 222, 333) - complete_diff = self.io.getoutput().split()[1] - - commands._showdiff('field', 222, 232) - partial_diff = self.io.getoutput().split()[1] - - self.assertEqual(complete_diff, partial_diff) class ShowChangeTest(_common.TestCase): def setUp(self):