From dcb2d2336ee2c3d554cafaf629426c79152381c3 Mon Sep 17 00:00:00 2001 From: Yuming Zhu Date: Oct 26 2016 17:41:12 +0000 Subject: ut: cli - test_upload_progress_callback --- diff --git a/cli/koji b/cli/koji index 16f9939..34e4920 100755 --- a/cli/koji +++ b/cli/koji @@ -149,7 +149,7 @@ Try "%(progname)s help" to get all available commands Try "%(progname)s --help" for help about the options of a particular command Try "%(progname)s help " 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'): diff --git a/tests/test_cli/test_upload_progress_callback.py b/tests/test_cli/test_upload_progress_callback.py new file mode 100644 index 0000000..f0e1fe7 --- /dev/null +++ b/tests/test_cli/test_upload_progress_callback.py @@ -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()