示例#1
0
 def test_rollover_before_prefix_change(self):
     self.assertEqual(
         "{num.real:0.02f} {num.prefix}B".format(
             num=numfmt(897306, rollover=0.9)),
         "897.31 kB",
     )
     self.assertEqual(
         "{num.real:0.02f} {num.prefix}B".format(
             num=numfmt(973829, rollover=0.9)),
         "0.97 MB",
     )
示例#2
0
 def test_rollover_after_prefix_change(self):
     self.assertEqual(
         "{num.real:0.02f} {num.prefix}B".format(
             num=numfmt(1032456, rollover=1.1)),
         "1032.46 kB",
     )
     self.assertEqual(
         "{num.real:0.02f} {num.prefix}B".format(
             num=numfmt(1122334, rollover=1.1)),
         "1.12 MB",
     )
示例#3
0
 def test_str(self):
     self.assertEqual(str(numfmt(12345)), "12.35 k")
示例#4
0
 def test_negative(self):
     self.assertEqual("{}".format(numfmt(-12345)), "-12.35 k")
示例#5
0
 def test_limit_prefix_changes(self):
     self.assertEqual(
         "{num.real:0.02f} {num.prefix}B".format(
             num=numfmt(123000000000, limit=2)),
         "123000.00 MB",
     )
示例#6
0
 def test_fstring(self):
     num = numfmt(12345)
     self.assertEqual(f"{num.real:0.04f} {num.prefix}B", "12.3450 kB")
示例#7
0
 def test_binary_si_prefix(self):
     self.assertEqual(
         "{num.real:0.02f} {num.prefix}B".format(
             num=numfmt(12345, binary=True)),
         "12.06 KiB",
     )
示例#8
0
 def test_positional_named(self):
     self.assertEqual(
         "{num.real:0.01f} {num.prefix}B/s".format(num=numfmt(12345)),
         "12.3 kB/s")
示例#9
0
 def test_positional_num(self):
     self.assertEqual("{0.real:0.03f} {0.prefix}B".format(numfmt(12345)),
                      "12.345 kB")
示例#10
0
 def test_numfmt_fmt(self):
     self.assertEqual(
         "{}".format(numfmt(12345, fmt="{num.real:0.09f} {num.prefix}")),
         "12.345000000 k",
     )
示例#11
0
 def test_format(self):
     self.assertEqual("{}".format(numfmt(12345)), "12.35 k")
示例#12
0
 def test_repr(self):
     self.assertEqual(repr(numfmt(12345)), "12.35 k")