示例#1
0
def test_anim_heaviside(clock):
    animation = anim(1, 3, 0, clock, delay=1)
    assert animation == 1
    clock.advance_sync(1)
    assert animation == 3
    clock.advance_sync(1)
    assert animation == 3
示例#2
0
def test_anim_strength(clock, n):
    animation = anim(1, 3, 2, clock, strength=n)
    assert animation == 1
    clock.advance_sync(1)
    assert animation == 1 + n
    clock.advance_sync(1)
    assert animation == 1 + n * 2
示例#3
0
def test_anim_basic_vector(clock):
    animation = anim((1, 2), (3, 4), 2, clock)
    assert all(animation == (1, 2))
    clock.advance_sync(1)
    assert all(animation == (2, 3))
    clock.advance_sync(1)
    assert all(animation == (3, 4))
示例#4
0
def test_anim_negative_duration(clock):
    animation = anim(1, 3, -2, clock, delay=2)
    assert animation == 3
    clock.advance_sync(1)
    assert animation == 2
    clock.advance_sync(1)
    assert animation == 1
    clock.advance_sync(1)
    assert animation == 1
示例#5
0
def test_easing_name(clock):
    animation = anim(1, 3, 2, clock, easing='quad')
    assert animation == 1
    clock.advance_sync(1)
    assert animation == 1.5
    clock.advance_sync(1)
    assert animation == 3
    clock.advance_sync(1)
    assert animation == 3
示例#6
0
def test_anim_basic(clock):
    animation = anim(1, 3, 2, clock)
    assert animation == 1
    clock.advance_sync(1)
    assert animation == 2
    clock.advance_sync(1)
    assert animation == 3
    clock.advance_sync(1)
    assert animation == 3
示例#7
0
def test_anim_infinite(clock):
    animation = anim(1, 3, 2, clock, infinite=True)
    assert animation == 1
    clock.advance_sync(1)
    assert animation == 2
    clock.advance_sync(1)
    assert animation == 3
    clock.advance_sync(1)
    assert animation == 4
    clock.advance_sync(1)
    assert animation == 5
示例#8
0
def test_anim_delay(clock):
    animation = anim(1, 3, 2, clock, delay=1)
    assert animation == 1
    clock.advance_sync(1)
    assert animation == 1
    clock.advance_sync(1)
    assert animation == 2
    clock.advance_sync(1)
    assert animation == 3
    clock.advance_sync(1)
    assert animation == 3
示例#9
0
def test_done(clock):
    lst = []
    animation = anim(1, 3, 2, clock)
    animation.done.add_done_callback(lambda fut: lst.append('done'))
    assert lst == []
    clock.advance_sync(1)
    assert lst == []
    clock.advance_sync(1)
    assert lst == ['done']
    clock.advance_sync(1)
    assert lst == ['done']
    clock.advance_sync(1)
    assert lst == ['done']
示例#10
0
def test_easing_func_infinite(clock):
    animation = anim(1, 3, 2, clock, easing=math.sin, infinite=True)
    assert abs(float(animation) - 1) < ε
    clock.advance_sync(τ / 4)
    assert abs(float(animation) - (1 + 2 / math.sqrt(2))) < ε
    clock.advance_sync(τ / 4)
    assert abs(float(animation) - 3) < ε
    clock.advance_sync(τ / 4)
    assert abs(float(animation) - (1 + 2 / math.sqrt(2))) < ε
    clock.advance_sync(τ / 4)
    assert abs(float(animation) - 1) < ε
    clock.advance_sync(τ / 4)
    assert abs(float(animation) - (1 - 2 / math.sqrt(2))) < ε
    clock.advance_sync(τ / 4)
    assert abs(float(animation) - -1) < ε
    clock.advance_sync(τ / 4)
    assert abs(float(animation) - (1 - 2 / math.sqrt(2))) < ε
    clock.advance_sync(τ / 4)
    assert abs(float(animation) - 1) < ε
示例#11
0
    def anim(self, target, duration=0, clock=None, *,
             delay=0, easing=None, infinite=False, strength=1):
        """Animate this property

        Causes this property's value to gradually become *target*
        in *duration* time units.

        for convenience, if *clock* is not given,
        the ``clock`` attribute from the object
        this property is on is used as the clock.
        A :exc:`TypeError` is raised if that attribute doesn't exist.

        See the :ref:`Animation <property-anim>` section of the documentation
        for a discussion.

        For detailed description of the arguments, see
        :func:`gillcup.animations.anim`.

        Returns a :class:`~asyncio.Future`-like object
        that is done when the animation is finished.
        """
        instance = self._instance
        if clock is None:
            try:
                clock = instance.clock
            except AttributeError:
                raise TypeError('{} does not have a clock. '
                                'Pass a clock to anim() explicitly.'.format(
                                    instance))
        animation = anim(
            start=self.replacement,
            end=target,
            duration=duration,
            clock=clock,
            delay=delay,
            easing=easing,
            infinite=infinite,
            strength=strength,
        )
        self._parent_property.__set__(instance, animation)
        return animation.done
示例#12
0
def test_anim_negative_duration_past(clock):
    animation = anim(1, 3, -2, clock)
    assert animation == 1
    clock.advance_sync(1)
    assert animation == 1
示例#13
0
def test_anim_heaviside_infinite(clock):
    with pytest.raises(ValueError):
        anim(1, 3, 0, clock, infinite=True)