File: test_patch.py

package info (click to toggle)
codespeak-lib 0.9.1-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,212 kB
  • ctags: 5,409
  • sloc: python: 33,390; ansic: 961; xml: 582; makefile: 90
file content (31 lines) | stat: -rw-r--r-- 609 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
from py.test import raises
from py.magic import patch, revert

def test_patch_revert():
    class a:
        pass
    raises(AttributeError, "patch(a, 'i', 42)")

    a.i = 42
    patch(a, 'i', 23)
    assert a.i == 23
    revert(a, 'i')
    assert a.i == 42

def test_double_patch():
    class a:
        i = 42
    assert patch(a, 'i', 2) == 42
    assert patch(a, 'i', 3) == 2
    assert a.i == 3
    assert revert(a, 'i') == 3
    assert a.i == 2
    assert revert(a, 'i') == 2
    assert a.i == 42

def test_valueerror():
    class a:
        i = 2
        pass
    raises(ValueError, "revert(a, 'i')")