ut: cli - test_upload_progress_callback

This commit is contained in:
Yuming Zhu 2016-10-11 19:13:48 +00:00 committed by Mike McLean
parent 90d723b01a
commit dcb2d2336e
2 changed files with 48 additions and 2 deletions

View file

@ -149,7 +149,7 @@ Try "%(progname)s help" to get all available commands
Try "%(progname)s <command> --help" for help about the options of a particular command
Try "%(progname)s help <category>" to get commands under a particular category
Available categories are: %(categories)s
''' % ({'progname': progname, 'categories': categories_ordered})
''' % ({'progname': progname, 'categories': categories_ordered})
return _(epilog_str)
def get_options():
@ -889,7 +889,7 @@ def _format_size(size):
def _format_secs(t):
h = t / 3600
t = t % 3600
t %= 3600
m = t / 60
s = t % 60
return "%02d:%02d:%02d" % (h, m, s)
@ -962,6 +962,7 @@ def handle_build(options, session, args):
parser.error(_("Destination tag %s is locked" % dest_tag['name']))
source = args[1]
opts = {}
print build_opts
if build_opts.arch_override:
opts['arch_override'] = ' '.join(build_opts.arch_override.replace(',',' ').split())
for key in ('skip_tag', 'scratch', 'repo_id'):

View file

@ -0,0 +1,45 @@
import unittest
import mock
import sys
import StringIO as stringio
import loadcli
cli = loadcli.cli
class TestUploadProgressCallBack(unittest.TestCase):
maxDiff = None
def test_format_size(self):
self.assertEqual(cli._format_size(2000000000), '1.86 GiB')
self.assertEqual(cli._format_size(1073741824), '1.00 GiB')
self.assertEqual(cli._format_size(3000000), '2.86 MiB')
self.assertEqual(cli._format_size(1048576), '1.00 MiB')
self.assertEqual(cli._format_size(4000), '3.91 KiB')
self.assertEqual(cli._format_size(1024), '1.00 KiB')
self.assertEqual(cli._format_size(500), '500.00 B')
def test_format_secs(self):
self.assertEqual(cli._format_secs(0), '00:00:00')
self.assertEqual(cli._format_secs(60), '00:01:00')
self.assertEqual(cli._format_secs(3600), '01:00:00')
self.assertEqual(cli._format_secs(7283294), '2023:08:14')
self.assertEqual(cli._format_secs(1234), '00:20:34')
self.assertEqual(cli._format_secs(4321), '01:12:01')
self.assertEqual(cli._format_secs(4321.567), '01:12:01')
@mock.patch('sys.stdout', new_callable=stringio.StringIO)
def test_progress_callback(self, stdout):
cli._progress_callback(12300, 234000, 5670, 80, 900)
cli._progress_callback(45600, 234000, 5670, 0, 900)
cli._progress_callback(234000, 234000, 5670, 80, 900)
self.assertMultiLineEqual(stdout.getvalue(),
'[= ] 05% 00:15:00 12.01 KiB 70.88 B/sec\r'
'[======= ] 19% 00:15:00 44.53 KiB - B/sec\r'
'[====================================] 100% 00:15:00 228.52 KiB 260.00 B/sec\r')
if __name__ == '__main__':
unittest.main()