File: TestOperators.py

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 205,916 kB
  • sloc: cpp: 2,336,565; ansic: 327,116; python: 111,200; yacc: 4,104; java: 3,977; sh: 3,032; xml: 2,771; perl: 2,189; lex: 1,787; makefile: 178; javascript: 165; objc: 153; tcl: 59
file content (58 lines) | stat: -rw-r--r-- 1,516 bytes parent folder | download | duplicates (3)
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
"""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
from vtkmodules.vtkCommonCore import (
    vtkArrayCoordinates,
    vtkArrayExtents,
    vtkArrayRange,
)
from vtkmodules.test import Testing

class TestOperators(Testing.vtkTest):

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

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

    def testSequence(self):
        """Use sequence operators"""
        c1 = 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 = vtkArrayRange(3,4)
        e = vtkArrayExtents()
        e.SetDimensions(2)
        e[0] = r
        s = e[0]
        self.assertEqual(s, r)

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