Пример #1
0
    def test_get_generator(self):
        pba = argument.ProgressBarArgument(parsed_name='--progress')
        pba.value = None
        msg, msg_len = 'message', 40
        with patch('%s.KamakiProgressBar.start' % arg_path) as start:
            try:
                pba.get_generator(msg, msg_len)
                self.assertTrue(isinstance(pba.bar,
                                           argument.KamakiProgressBar))
                self.assertNotEqual(pba.bar.message, msg)
                self.assertEqual(pba.bar.message,
                                 '%s%s' % (msg, ' ' * (msg_len - len(msg))))
                self.assertEqual(pba.bar.suffix, '%(percent)d%% - %(eta)ds')
                assert start.call_count == 1

                pba.get_generator(msg, msg_len, countdown=True)
                self.assertTrue(isinstance(pba.bar,
                                           argument.KamakiProgressBar))
                self.assertNotEqual(pba.bar.message, msg)
                self.assertEqual(pba.bar.message,
                                 '%s%s' % (msg, ' ' * (msg_len - len(msg))))
                self.assertEqual(pba.bar.suffix, '%(remaining)ds to timeout')
            finally:
                try:
                    pba.finish()
                except Exception:
                    pass
Пример #2
0
 def test_finish(self):
     pba = argument.ProgressBarArgument(parsed_name='--progress')
     pba.value = None
     self.assertEqual(pba.finish(), None)
     pba.bar = argument.KamakiProgressBar()
     with patch('%s.KamakiProgressBar.finish' % arg_path) as finish:
         pba.finish()
         assert finish.call_count == 1
Пример #3
0
 def test_clone(self):
     pba = argument.ProgressBarArgument(parsed_name='--progress')
     pba.value = None
     pba_clone = pba.clone()
     self.assertTrue(isinstance(pba, argument.ProgressBarArgument))
     self.assertTrue(isinstance(pba_clone, argument.ProgressBarArgument))
     self.assertNotEqual(pba, pba_clone)
     self.assertEqual(pba.parsed_name, pba_clone.parsed_name)
Пример #4
0
 def test___init__(self, init):
     help, pname, default = 'help', '--progress', 'default'
     pba = argument.ProgressBarArgument(help, pname, default)
     self.assertTrue(isinstance(pba, argument.ProgressBarArgument))
     self.assertEqual(pba.suffix, '%(percent)d%%')
     init.assert_called_once_with(help, pname, default)