Skip to content

Commit 158c720

Browse files
committed
0.8.1
- (#135) Add an 'original_module' field to randobj classes so true declaration location can be determined Signed-off-by: Matthew Ballance <matt.ballance@gmail.com>
1 parent 83b0e70 commit 158c720

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

doc/Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
## 0.8.1
3+
- (#135) Add an 'original_module' field to randobj classes so true declaration
4+
location can be determined
5+
26
## 0.8.0
37
- (#166) Correct rand-size list support for composite elements
48

etc/ivpm.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22
name=pyvsc
3-
version=0.8.0
3+
version=0.8.1
44

src/vsc/rand_obj.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ def randobj(*args, **kwargs):
330330
if len(args) == 1 and len(kwargs) == 0 and callable(args[0]):
331331
# Called without arguments
332332
obj = _randobj({})
333+
# Capture the original module, since our inheritance
334+
# trick causes the module to not match the user's module
335+
args[0].original_module = args[0].__module__
333336
return obj(args[0])
334337
else:
335338
obj = _randobj(kwargs)

ve/unit/test_randobj_srcinfo.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,25 @@ def my_c(self):
6868

6969
self.assertEqual(len(obj_m.constraint_model_l), 1)
7070
self.assertIsNone(obj_m.constraint_model_l[0].constraint_l[0].srcinfo)
71+
72+
def test_original_module_1(self):
7173

74+
@vsc.randobj
75+
class my_c(object):
76+
77+
def __init__(self):
78+
self.a = vsc.rand_uint8_t()
79+
self.b = vsc.rand_uint8_t()
80+
pass
81+
82+
@vsc.constraint
83+
def my_c(self):
84+
self.a < self.b
85+
86+
obj = my_c()
87+
self.assertIsNot(my_c.__module__, my_c.original_module)
88+
self.assertEqual(str(my_c.original_module), "test_randobj_srcinfo")
89+
obj_m : FieldCompositeModel = obj.get_model()
90+
91+
self.assertEqual(len(obj_m.constraint_model_l), 1)
92+
self.assertIsNone(obj_m.constraint_model_l[0].constraint_l[0].srcinfo)

0 commit comments

Comments
 (0)