コード例 #1
0
    def test_add(self):
        """ Controls should be added to each other, Colrs, or strs. """
        types = {
            'BarSet': BarSet(('a', 'b', 'c')),
            'list': ['a', 'b', 'c'],
            'tuple': ('a', 'b', 'c'),
        }
        for othername, other in types.items():
            fset = BarSet(('1', '2', '3'))
            try:
                newfset = fset + other
            except TypeError as ex:
                self.fail(
                    'BarSet + {} should not raise a TypeError.'.format(
                        othername
                    ))
            else:

                self.assertIsInstance(
                    newfset,
                    BarSet,
                    msg=(
                        'Adding {} to a BarSet did not return a BarSet.'
                    ).format(othername)
                )
                ctl_str_result = ''.join((
                    self.iterable_str(fset),
                    self.iterable_str(other),
                ))
                s = str(newfset)
                self.assertEqual(
                    ctl_str_result,
                    s,
                    msg='str(BarSet()) did not match.'
                )
コード例 #2
0
ファイル: test_progress.py プロジェクト: welbornprod/colr
 def test_from_str(self):
     """ BarSet.from_str should create a set of bar frames. """
     s = 'abcd'
     name = 'test_bars'
     expected = BarSet(
         (
             'a   ',
             'ab  ',
             'abc ',
             'abcd',
         ),
         name=name,
     )
     bset = BarSet.from_str(s, name=name)
     self.assertEqual(bset,
                      expected,
                      msg='Failed to create BarSet from str.')
コード例 #3
0
 def test_hash(self):
     """ hash(BarSet()) should return a unique hash for self.data. """
     a, b = hash(BarSet('test')), hash(BarSet('test'))
     self.assertCallEqual(
         a,
         b,
         func=hash,
         args=[a],
         otherargs=[b],
         msg='Mismatched hash values.',
     )
     b = hash(BarSet('another'))
     self.assertCallNotEqual(
         a,
         b,
         func=hash,
         args=[a],
         otherargs=[b],
         msg='Hash values should not match.',
     )
コード例 #4
0
ファイル: test_progress.py プロジェクト: welbornprod/colr
 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,
             ))
コード例 #5
0
 def test_as_rainbow(self):
     """ BarSet.as_rainbow() should Colrize all frames. """
     fset = BarSet('abc', name='test_frameset')
     colrfset = fset.as_rainbow()
     fsetlen = len(fset)
     colrfsetlen = len(colrfset)
     self.assertCallEqual(
         colrfsetlen,
         fsetlen,
         func=len,
         args=(colrfsetlen, ),
         otherargs=(fsetlen, ),
         msg='Colorized BarSet length was mismatched.',
     )
     for item in colrfset:
         self.assertCallIsInstance(
             item,
             Colr,
             func=BarSet.as_rainbow,
             args=(item, ),
             msg='Colorized BarSet item is not a Colr.',
         )
コード例 #6
0
ファイル: test_progress.py プロジェクト: welbornprod/colr
    def test_init(self):
        """ BarSets can be initialized with several types of iterables. """
        def generator(s):
            yield from s

        teststr = 'test'
        types = (
            teststr,
            list(teststr),
            tuple(teststr),
            generator(teststr),
        )
        for itertype in types:
            self.assertCallIsInstance(
                BarSet(itertype),
                BarSet,
                func=BarSet,
                args=(itertype, ),
                msg='Failed to initialize from a good iterable ({}).'.format(
                    type(itertype).__name__, ),
            )
コード例 #7
0
 def test_bytes(self):
     """ bytes(BarSet()) should encode self.data. """
     s = 'test'
     a = s.encode()
     b = bytes(BarSet(s))
     self.assertEqual(a, b, msg='Encoded BarSet is not the same.')