File: test_misc.py

package info (click to toggle)
psyco 1.5.1-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,864 kB
  • ctags: 3,295
  • sloc: ansic: 24,491; python: 5,573; perl: 1,309; makefile: 166; sh: 1
file content (39 lines) | stat: -rw-r--r-- 838 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
import py, sys, psyco


def test_index():
    if sys.version_info < (2, 5):
        py.test.skip("for Python 2.5")

    class X(object):
        def __index__(self):
            return -3

    def f(x):
        return (12, 23, 34, 45)[x]

    res = psyco.proxy(f)(X())
    assert res == 23


def test_index_slice():
    if sys.version_info < (2, 5):
        py.test.skip("for Python 2.5")

    class Observer(object):
        def __getslice__(self, i, j):
            return "slice", i, j
        def __getitem__(self, x):
            raise Exception("in __getitem__")
    class X(object):
        def __index__(self):
            return 5
    class Y(object):
        def __index__(self):
            return -2

    def f(o, x, y):
        return o[x:y]

    res = psyco.proxy(f)(Observer(), X(), Y())
    assert res == ("slice", 5, -2)