File: test_dcDrawLinesFromBuffer.py

package info (click to toggle)
wxpython4.0 4.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 221,752 kB
  • sloc: cpp: 962,555; python: 230,573; ansic: 170,731; makefile: 51,756; sh: 9,342; perl: 1,564; javascript: 584; php: 326; xml: 200
file content (65 lines) | stat: -rw-r--r-- 1,520 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
59
60
61
62
63
64
65
import unittest
from unittests import wtc
import wx
import random
try:
    import numpy as np
    haveNumpy = True
except ImportError:
    haveNumpy = False

#---------------------------------------------------------------------------

w = 600
h = 400

def makeRandomLines():
    lines = []

    for i in range(num):
        x1 = random.randint(0, w)
        y1 = random.randint(0, h)
        x2 = random.randint(0, w)
        y2 = random.randint(0, h)
        lines.append( (x1,y1, x2,y2) )

    return lines





#---------------------------------------------------------------------------


class dcDrawLists_Tests(wtc.WidgetTestCase):

    @unittest.skipIf(not haveNumpy, "Numpy required for this test")
    def test_dcDrawLinesFromBuffer(self):
        pnl = wx.Panel(self.frame)
        self.frame.SetSize((w,h))
        dc = wx.ClientDC(pnl)
        dc.SetPen(wx.Pen("BLACK", 1))

        xs = np.linspace(0, w, w + 1)
        ys = np.sin(xs / w * 2 * np.pi)
        
        xs.shape = xs.size, 1
        ys.shape = ys.size, 1
        pts = np.append(xs, ys, 1)

        dc.DrawLinesFromBuffer(pts.astype('intc'))
        self.assertRaises(TypeError, dc.DrawLinesFromBuffer, 
                          pts.astype('int64') if np.intc(1).nbytes != np.int64(1).nbytes else pts.astype('int32'))
        self.assertRaises(TypeError, dc.DrawLinesFromBuffer, pts.tolist())
        del dc






#---------------------------------------------------------------------------

if __name__ == '__main__':
    unittest.main()