Beispiel #1
0
def FormatProgress(progress):
  """Formats progress information for user consumption

  """
  (mbytes, throughput, percent, eta) = progress

  parts = [
    utils.FormatUnit(mbytes, "h"),

    # Not using FormatUnit as it doesn't support kilobytes
    "%0.1f MiB/s" % throughput,
    ]

  if percent is not None:
    parts.append("%d%%" % percent)

  if eta is not None:
    parts.append("ETA %s" % utils.FormatSeconds(eta))

  return utils.CommaJoin(parts)
 def testFloat(self):
     self.assertEqual(utils.FormatSeconds(1.3), "1s")
     self.assertEqual(utils.FormatSeconds(1.9), "2s")
     self.assertEqual(utils.FormatSeconds(3912.12311), "1h 5m 12s")
     self.assertEqual(utils.FormatSeconds(3912.8), "1h 5m 13s")
 def test(self):
     self.assertEqual(utils.FormatSeconds(1), "1s")
     self.assertEqual(utils.FormatSeconds(3600), "1h 0m 0s")
     self.assertEqual(utils.FormatSeconds(3599), "59m 59s")
     self.assertEqual(utils.FormatSeconds(7200), "2h 0m 0s")
     self.assertEqual(utils.FormatSeconds(7201), "2h 0m 1s")
     self.assertEqual(utils.FormatSeconds(7281), "2h 1m 21s")
     self.assertEqual(utils.FormatSeconds(29119), "8h 5m 19s")
     self.assertEqual(utils.FormatSeconds(19431228), "224d 21h 33m 48s")
     self.assertEqual(utils.FormatSeconds(-1), "-1s")
     self.assertEqual(utils.FormatSeconds(-282), "-282s")
     self.assertEqual(utils.FormatSeconds(-29119), "-29119s")