Esempio n. 1
0
 def test_register(self):
     """ Bars.register should register new BarSets. """
     name = 'test_barset'
     fset = BarSet('abc', name=name)
     Bars.register(fset)
     if getattr(Bars, name, None) is None:
         self.fail(
             self.call_msg(
                 'Failed to register BarSet attribute.',
                 name,
                 func=Bars.register,
             ))
Esempio n. 2
0
def run_bar_name(name,
                 delay=None,
                 char_delay=None,
                 file=sys.stdout,
                 min_run_time=5,
                 timeout=None):
    """ Run a single animated progress BarSet by name. """
    try:
        bars = Bars.get_by_name(name)
    except ValueError as ex:
        print_err(ex)
        return 1
    delay = delay or (min_run_time / 20)
    p = ProgressBar(
        'Testing progress bar: {}'.format(bars.name),
        bars=bars,
        show_time=True,
        timeout=timeout,
        file=file,
    )
    try:
        with p:
            for x in range(0, 55, 5):
                p.update(x)
                sleep(delay)
            p.message = 'Almost through with: {}'.format(bars.name)
            for x in range(50, 105, 5):
                p.update(x)
                sleep(delay)
        p.stop()
    except ProgressTimedOut as ex:
        print_err('\n{}'.format(ex))
        return 1
    return 0
Esempio n. 3
0
 def test_names(self):
     """ Bars.names() sould return a non-empty list of names. """
     names = Bars.names()
     nameslen = len(names)
     self.assertCallNotEqual(
         nameslen,
         0,
         func=len,
         args=(names),
         msg='Bars.names() returned an empty list.',
     )
Esempio n. 4
0
 def test_get_by_name(self):
     """ Bars.get_by_name() should return known BarSets. """
     for name in ('blocks', ):
         try:
             blocks = Bars.get_by_name(name)
         except ValueError:
             self.fail(
                 self.call_msg(
                     'Failed to get known name.',
                     name,
                     func=Bars.get_by_name,
                 ))
         self.assertCallIsInstance(
             blocks,
             BarSet,
             func=Bars.get_by_name,
             args=(name, ),
             msg='Returned non-BarSet object.',
         )