-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pyevil.py
75 lines (61 loc) · 1.75 KB
/
test_pyevil.py
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
66
67
68
69
70
71
72
73
74
75
import pyevil
def test_int_copy():
"""
If you're mutating ints, you might want copies...
"""
newone = pyevil.int_copy(1)
assert newone == 1
assert not (newone is 1)
def test_int_copy_neg():
"""
Because Python has a weird representation for negative ints,
test this, too...
"""
someneg = pyevil.int_copy(-10)
assert someneg == -10
assert not (someneg is -10)
def test_int_mutate():
one = pyevil.int_copy(1)
assert one == 1
pyevil.int_mutate(one, 2)
assert one != 1
assert one == 2
assert one + one == 4
def test_evil_int_mutate():
"""
Not impressed with mutating copies?
Why not mutate literals?
(If you're bold, try changing the value of 1 and see how many libraries you can break.)
"""
assert 800 != 900
pyevil.int_mutate(800, 900, force=True)
assert 800 == 900
assert 400 + 400 != 800 # *evil laugh*
def test_float_mutate():
"""
Let's mess with floats, too.
"""
pyevil.float_mutate(2.0, 1.5)
assert 2.0 * 2 == 3
def test_float_mutate_copy():
"""
We can use copies, too...
"""
three = pyevil.float_copy(3.0)
still_three = three
pyevil.float_mutate(three, 4.0)
# We've taken a float object and changed its value.
# This is different from reassigning to a new object,
# On the surface, it looks kind of the same as `three = 4.0`
assert three != 3.0
assert three == 4
# but all references were updated
assert still_three == 4
def test_tuple_set_item():
"""
If only you could do this with tuples...
data[0] = 4 # Gives TypeError: 'tuple' object does not support item assignment
"""
data = (1,2,3)
pyevil.tuple_set_item(data, index=0, value=4)
assert data == (4,2,3)