File: test_text.py

package info (click to toggle)
python-vispy 0.6.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 21,344 kB
  • sloc: python: 57,412; javascript: 6,810; makefile: 63; sh: 5
file content (58 lines) | stat: -rw-r--r-- 1,767 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# -*- coding: utf-8 -*-

import numpy as np
from numpy.testing import assert_allclose

from vispy.scene.visuals import Text
from vispy.testing import (requires_application, TestingCanvas,
                           run_tests_if_main)
from vispy.testing.image_tester import assert_image_approved


@requires_application()
def test_text():
    """Test basic text support"""

    with TestingCanvas(bgcolor='w', size=(92, 92), dpi=92) as c:
        pos = [92 // 2] * 2
        text = Text('testing', font_size=20, color='k',
                    pos=pos, anchor_x='center', anchor_y='baseline',
                    parent=c.scene)
        # Test image created in Illustrator CS5, 1"x1" output @ 92 DPI
        assert_image_approved(c.render(), 'visuals/text1.png')

        text.text = ['foo', 'bar']
        text.pos = [10, 10]  # should auto-replicate
        text.rotation = [180, 270]
        try:
            text.pos = [10]
        except Exception:
            pass
        else:
            raise AssertionError('Exception not raised')
        c.update()
        c.app.process_events()
        text.pos = [[10, 10], [10, 20]]
        text.text = 'foobar'
        c.update()
        c.app.process_events()


@requires_application()
def test_text_rotation_update():

    # Regression test for a bug that caused text labels to not be redrawn
    # if the rotation angle was updated

    with TestingCanvas() as c:
        text = Text('testing', pos=(100, 100), parent=c.scene)
        c.update()
        c.app.process_events()
        assert_allclose(text.shared_program['a_rotation'], 0.)
        text.rotation = 30.
        c.update()
        c.app.process_events()
        assert_allclose(text.shared_program['a_rotation'], np.radians(30.))


run_tests_if_main()