-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtestImmutableStruct.py
More file actions
43 lines (36 loc) · 1.25 KB
/
testImmutableStruct.py
File metadata and controls
43 lines (36 loc) · 1.25 KB
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
## Copyright (c) 2020-2023 The PyUnity Team
## This file is licensed under the MIT License.
## See https://docs.pyunity.x10.bz/en/latest/license.html
from pyunity import ImmutableStruct, PyUnityException
from . import TestCase
class Struct(metaclass=ImmutableStruct):
_names = ["x", "y"]
x = 5
y = 6
class TestImmutableStruct(TestCase):
def testInternalSet(self):
assert Struct.x == 5
assert Struct.y == 6
Struct._set("x", 1)
assert Struct.x == 1
with self.assertRaises(PyUnityException) as exc:
Struct._set("a", 1)
assert exc.value == "No field named 'a'"
def testException(self):
with self.assertRaises(PyUnityException) as exc:
Struct.x = 1
assert exc.value == "Field 'x' is read-only"
with self.assertRaises(PyUnityException) as exc:
del Struct.x
assert exc.value == "Field 'x' is read-only"
def testSetOther(self):
global Struct
Struct.n = 5
del Struct.n
with self.assertRaises(AttributeError) as exc:
del Struct.f
with self.assertRaises(AttributeError) as example:
class Struct:
pass
del Struct.f
assert exc.value == example.value