def test_format_pair(self): """Test that format_pair works as expected.""" testdata = [ ["%d", 0, 0, {}, "0/0"], ["%d", 0, 1, {}, "0/1"], ["%d", 1, 100, {}, " 1/100"], ["%d", 1000, 1000, {}, "1000/1000"], ["%.1f", 0, 1000, {}, " 0.0/1000.0"], ["%.1f", 1000, 1000, {}, "1000.0/1000.0"], ["%.1f", 1012.512, 2000.912, {}, "1012.5/2000.9"], ["%.1f", 20.32, 1000.23, {"targetwidth": 6, "format2": "%d"}, " 20.3/1000.2"], ["%.1f", 20.322, 1000.23, {"targetwidth": 5, "format2": "%d"}, " 20/1000"], ["%.1f", 20.322, 1000.23, {"targetwidth": 4, "format2": "%d"}, " 20/1000"], ["%.1f", 20.322, 99.23, {"targetwidth": 5, "format2": "%d"}, "20.3/99.2"], ["%.1f", 2032, 9923, {"targetwidth": 5, "format2": "%d", "scale": 100}, "20.3/99.2"], ] for (formatstr, item, goal, kwargs, expresult) in testdata: result = progress.format_pair(formatstr, item, goal, **kwargs) self.assertEqual(result, expresult, "expected: %s != result: %s" % (expresult, result))
def test_format_pair(self): """Test that format_pair works as expected.""" testdata = [ ["{0:d}", 0, 0, {}, "0/0"], ["{0:d}", 0, 1, {}, "0/1"], ["{0:d}", 1, 100, {}, " 1/100"], ["{0:d}", 1000, 1000, {}, "1000/1000"], ["{0:.1f}", 0, 1000, {}, " 0.0/1000.0"], ["{0:.1f}", 1000, 1000, {}, "1000.0/1000.0"], ["{0:.1f}", 1012.512, 2000.912, {}, "1012.5/2000.9"], ["{0:.1f}", 20.32, 1000.23, {"targetwidth": 6, "format2": "{0:d}"}, " 20.3/1000.2"], ["{0:.1f}", 20.322, 1000.23, {"targetwidth": 5, "format2": "{0:d}"}, " 20/1000"], ["{0:.1f}", 20.322, 1000.23, {"targetwidth": 4, "format2": "{0:d}"}, " 20/1000"], ["{0:.1f}", 20.322, 99.23, {"targetwidth": 5, "format2": "{0:d}"}, "20.3/99.2"], ["{0:.1f}", 2032, 9923, {"targetwidth": 5, "format2": "{0:d}", "scale": 100}, "20.3/99.2"], ] for (formatstr, item, goal, kwargs, expresult) in testdata: result = progress.format_pair(formatstr, item, goal, **kwargs) self.assertEqual(result, expresult, "expected: {0} != result: {1}".format(expresult, result))
def _li_recurse_status_output(self, done): if self.linked_pkg_op == pkgdefs.PKG_OP_PUBCHECK: return i = "level1" if self.indent else "" total = len(self.linked_running) + done running = " ".join([str(s) for s in self.linked_running]) msg = _("Linked images: %s done; %d working: %s\n") % \ (progress.format_pair("%d", done, total), len(self.linked_running), running) self.update_details_text(msg, i)
def _li_recurse_status_output(self, done): if self.linked_pkg_op == pkgdefs.PKG_OP_PUBCHECK: return i = "level1" if self.indent else "" running = " ".join([str(s) for s in self.linked_running]) msg = _("Linked images: %(num)s done; %(numworking)d working: " "%(running)s\n") % \ {"num": progress.format_pair("%d", done, self.linked_total), "numworking": len(self.linked_running), "running": running} self.update_details_text(msg, i)