File: TestOperators.py

package info (click to toggle)
vtk 5.8.0-13
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 130,524 kB
  • sloc: cpp: 1,129,256; ansic: 708,203; tcl: 48,526; python: 20,875; xml: 6,779; yacc: 4,208; perl: 3,121; java: 2,788; lex: 931; sh: 660; asm: 471; makefile: 299
file content (55 lines) | stat: -rw-r--r-- 1,456 bytes parent folder | download | duplicates (10)
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
"""Test operator support in VTK-Python

The following operators are supported:
- The << operator becomes python str() and print()
- The < <= == != > >= operators become richcompare
- The [int] operator become the sequence protocol

The following operators are not yet supported:
- The () operator
- The [] operator for the mapping protocol
- Arithmetic operators + - * / %

Created on May 7, 2011 by David Gobbi

"""

import sys
import exceptions
import vtk
from vtk.test import Testing

class TestOperators(Testing.vtkTest):

    def testPrint(self):
        """Use str slot"""
        c1 = vtk.vtkArrayRange(3,4)
        s1 = str(c1)
        s2 = '[3, 4)'
        self.assertEqual(s1, s2)

    def testCompare(self):
        """Use comparison operators"""
        c1 = vtk.vtkArrayRange(3,4)
        c2 = vtk.vtkArrayRange(3,4)
        # will fail if the "==" operator is not wrapped
        self.assertEqual(c1, c2)

    def testSequence(self):
        """Use sequence operators"""
        c1 = vtk.vtkArrayCoordinates()
        c1.SetDimensions(3)
        n = len(c1) # sq_length slot
        self.assertEqual(n, 3)
        c1[1] = 5  # sq_ass_item slot
        n = c1[1]  # sq_item slot
        self.assertEqual(n, 5)
        r = vtk.vtkArrayRange(3,4)
        e = vtk.vtkArrayExtents()
        e.SetDimensions(2)
        e[0] = r
        s = e[0]
        self.assertEqual(s, r)

if __name__ == "__main__":
    Testing.main([(TestOperators, 'test')])