diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 257df93a4..fee3f4340 100755 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -65,8 +65,15 @@ def _do_query(lib, query, album, also_items=True): return items, albums +FLOAT_EPSILON = 0.01 def _showdiff(field, oldval, newval, color): """Prints out a human-readable field difference line.""" + # 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 + if newval != oldval: oldval = unicode(oldval) newval = unicode(newval) diff --git a/test/test_ui.py b/test/test_ui.py index a19a19d6f..2e8dfbe7c 100644 --- a/test/test_ui.py +++ b/test/test_ui.py @@ -530,6 +530,16 @@ class UtilTest(unittest.TestCase): self.assertTrue('old' in out) self.assertTrue('new' in out) + def test_showdiff_floats_close_to_identical(self): + commands._showdiff('field', 1.999, 2.001, True) + out = self.io.getoutput() + self.assertFalse('field' in out) + + def test_showdiff_floats_differenct(self): + commands._showdiff('field', 1.999, 4.001, True) + out = self.io.getoutput() + self.assertTrue('field' in out) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__)