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

                self.assertIsInstance(
                    newfset,
                    FrameSet,
                    msg=(
                        'Adding {} to a FrameSet did not return a FrameSet.'
                    ).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(FrameSet()) did not match.'
                )
예제 #2
0
    def test_frame_delay(self):
        """ FrameSet delays should be honored, unless overridden. """

        fset = FrameSet('test', name='test_frames', delay=0.7)
        p = AnimatedProgress(
            'message',
            frames=fset,
            file=TestFile(),
        )

        self.assertAlmostEqual(
            p.delay,
            fset.delay,
            delta=0.1,
            msg='FrameSet delay was not honored.',
        )

        # Overridden frame delays:
        manual_delay = 0.9
        p_manual = AnimatedProgress(
            'message',
            frames=fset,
            delay=manual_delay,
            file=TestFile(),
        )

        self.assertAlmostEqual(
            p_manual.delay,
            manual_delay,
            delta=0.1,
            msg='FrameSet delay was not overridden.',
        )
예제 #3
0
 def test_hash(self):
     """ hash(FrameSet()) should return a unique hash for self.data. """
     a, b = hash(FrameSet('test')), hash(FrameSet('test'))
     self.assertCallEqual(
         a,
         b,
         func=hash,
         args=[a],
         otherargs=[b],
         msg='Mismatched hash values.',
     )
     b = hash(FrameSet('another'))
     self.assertCallNotEqual(
         a,
         b,
         func=hash,
         args=[a],
         otherargs=[b],
         msg='Hash values should not match.',
     )
예제 #4
0
 def test_register(self):
     """ Frames.register should register new FrameSets. """
     name = 'test_frameset'
     fset = FrameSet('abc', name=name)
     Frames.register(fset)
     if getattr(Frames, name, None) is None:
         self.fail(
             self.call_msg(
                 'Failed to register FrameSet attribute.',
                 name,
                 func=Frames.register,
             ))
예제 #5
0
 def test_as_rainbow(self):
     """ FrameSet.as_rainbow() should Colrize all frames. """
     fset = FrameSet('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 FrameSet length was mismatched.',
     )
     for item in colrfset:
         self.assertCallIsInstance(
             item,
             Colr,
             func=FrameSet.as_rainbow,
             args=(item, ),
             msg='Colorized FrameSet item is not a Colr.',
         )
예제 #6
0
    def test_init(self):
        """ FrameSets 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(
                FrameSet(itertype),
                FrameSet,
                func=FrameSet,
                args=(itertype, ),
                msg='Failed to initialize from a good iterable ({}).'.format(
                    type(itertype).__name__, ),
            )
예제 #7
0
 def test_bytes(self):
     """ bytes(FrameSet()) should encode self.data. """
     s = 'test'
     a = s.encode()
     b = bytes(FrameSet(s))
     self.assertEqual(a, b, msg='Encoded FrameSet is not the same.')