Skip to content

Commit e9392fe

Browse files
committed
0.9.4
- (#233) - Propagate docstring and modulename across `randobj` inheritance Signed-off-by: Matthew Ballance <[email protected]>
1 parent 1cf5ff3 commit e9392fe

File tree

5 files changed

+68
-6
lines changed

5 files changed

+68
-6
lines changed

doc/Changelog.md

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

2+
## 0.9.4
3+
- (#233) - Propagate docstring and modulename across `randobj` inheritance
4+
25
## 0.9.3
36
- () - Properly apply ignore bins to single-value bins
47

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.9.3
3+
version=0.9.4
44

src/vsc/rand_obj.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ def __init__(self, *args, **kwargs):
8484

8585
# Add the interposer class
8686
ret = type(T.__name__, (randobj_interposer,), dict())
87+
88+
ret.__doc__ = T.__doc__
89+
ret.__module__ = T.__module__
90+
ret.__qualname__ = T.__qualname__
8791

8892
if not hasattr(T, "_ro_init"):
8993
def __getattribute__(self, a):
@@ -333,10 +337,10 @@ def randobj(*args, **kwargs):
333337
# Capture the original module, since our inheritance
334338
# trick causes the module to not match the user's module
335339
args[0].original_module = args[0].__module__
336-
return obj(args[0])
340+
ret = obj(args[0])
337341
else:
338-
obj = _randobj(kwargs)
339-
return obj
342+
ret = _randobj(kwargs)
343+
return ret
340344

341345
def generator(T):
342346
"""Mark a class as a generator"""

ve/unit/test_coverage_report.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,18 @@ def __init__(self):
233233
print(">================== XML Report =======================")
234234
reporter.report()
235235
print("<================== XML Report =======================")
236-
236+
237+
def test_type_inst_report(self):
238+
@vsc.covergroup
239+
class PARNET_COV(object):
240+
def __init__(self, name, hit_value):
241+
self.name = name
242+
self.coverpoint = vsc.coverpoint(hit_value,
243+
bins=dict(name=vsc.bin(1)),
244+
)
245+
246+
cg1 = PARNET_COV("CHILD_1", 1)
247+
report = vsc.get_coverage_report_model()
248+
print(f"instname {report.covergroups[0].instname} == name {report.covergroups[0].name}")
249+
print(f"instname {report.covergroups[0].covergroups[0].instname} == name {report.covergroups[0].name}")
250+
vsc.report_coverage(details=True)

ve/unit/test_randobj_srcinfo.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,50 @@ def my_c(self):
8484
self.a < self.b
8585

8686
obj = my_c()
87-
self.assertIsNot(my_c.__module__, my_c.original_module)
8887
self.assertEqual(str(my_c.original_module), "test_randobj_srcinfo")
8988
obj_m : FieldCompositeModel = obj.get_model()
9089

9190
self.assertEqual(len(obj_m.constraint_model_l), 1)
9291
self.assertIsNone(obj_m.constraint_model_l[0].constraint_l[0].srcinfo)
92+
93+
def test_doc_preserved_noarg(self):
94+
95+
class my_plain_c(object):
96+
pass
97+
98+
@vsc.randobj
99+
class my_c(object):
100+
"""my_c doc"""
101+
102+
def __init__(self):
103+
self.a = vsc.rand_uint8_t()
104+
self.b = vsc.rand_uint8_t()
105+
pass
106+
107+
@vsc.constraint
108+
def my_c(self):
109+
self.a < self.b
110+
111+
self.assertEqual(my_c.__doc__, "my_c doc")
112+
113+
def test_doc_preserved_arg(self):
114+
115+
class my_plain_c(object):
116+
pass
117+
118+
@vsc.randobj(srcinfo=False)
119+
class my_c(object):
120+
"""my_c doc"""
121+
122+
def __init__(self):
123+
self.a = vsc.rand_uint8_t()
124+
self.b = vsc.rand_uint8_t()
125+
pass
126+
127+
@vsc.constraint
128+
def my_c(self):
129+
self.a < self.b
130+
131+
self.assertEqual(my_c.__doc__, "my_c doc")
132+
133+

0 commit comments

Comments
 (0)