Skip to content

Commit

Permalink
0.8.1
Browse files Browse the repository at this point in the history
- (#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>
  • Loading branch information
mballance committed Nov 15, 2022
1 parent 83b0e70 commit 158c720
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

## 0.8.1
- (#135) Add an 'original_module' field to randobj classes so true declaration
location can be determined

## 0.8.0
- (#166) Correct rand-size list support for composite elements

Expand Down
2 changes: 1 addition & 1 deletion etc/ivpm.info
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

name=pyvsc
version=0.8.0
version=0.8.1

3 changes: 3 additions & 0 deletions src/vsc/rand_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ def randobj(*args, **kwargs):
if len(args) == 1 and len(kwargs) == 0 and callable(args[0]):
# Called without arguments
obj = _randobj({})
# Capture the original module, since our inheritance
# trick causes the module to not match the user's module
args[0].original_module = args[0].__module__
return obj(args[0])
else:
obj = _randobj(kwargs)
Expand Down
21 changes: 21 additions & 0 deletions ve/unit/test_randobj_srcinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,25 @@ def my_c(self):

self.assertEqual(len(obj_m.constraint_model_l), 1)
self.assertIsNone(obj_m.constraint_model_l[0].constraint_l[0].srcinfo)

def test_original_module_1(self):

@vsc.randobj
class my_c(object):

def __init__(self):
self.a = vsc.rand_uint8_t()
self.b = vsc.rand_uint8_t()
pass

@vsc.constraint
def my_c(self):
self.a < self.b

obj = my_c()
self.assertIsNot(my_c.__module__, my_c.original_module)
self.assertEqual(str(my_c.original_module), "test_randobj_srcinfo")
obj_m : FieldCompositeModel = obj.get_model()

self.assertEqual(len(obj_m.constraint_model_l), 1)
self.assertIsNone(obj_m.constraint_model_l[0].constraint_l[0].srcinfo)

0 comments on commit 158c720

Please sign in to comment.