Skip to content

Commit 575d859

Browse files
committed
tests: check dynamic loading of instance with custom doc
1 parent afded50 commit 575d859

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

quartodoc/tests/example_dynamic.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@ def dynamic_doc(self, x):
2929

3030

3131
class InstanceAttrs:
32+
"""Some InstanceAttrs class"""
33+
3234
z: int
3335
"""The z attribute"""
3436

3537
def __init__(self, a: int, b: str):
3638
self.a = a
3739
self.b = b
3840
"""The b attribute"""
41+
42+
43+
some_instance = InstanceAttrs(1, 1)
44+
some_instance.__doc__ = "Dynamic instance doc"

quartodoc/tests/test_basic.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_get_object_dynamic_class_method_doc():
7979
assert meth.docstring.value == "A dynamic method"
8080

8181

82-
def test_get_object_dynamic_class_method_doc():
82+
def test_get_object_dynamic_class_method_doc_partial():
8383
obj = get_object("quartodoc.tests.example_dynamic:AClass", dynamic=True)
8484

8585
meth = obj.members["dynamic_create"]
@@ -92,7 +92,28 @@ def test_get_object_dynamic_class_instance_attr_doc():
9292
assert obj.members["b"].docstring.value == "The b attribute"
9393

9494

95-
def test_get_object_dynamic_class_instance_attr_doc():
95+
def test_get_object_dynamic_class_instance_attr_doc_class_attr_valueless():
9696
obj = get_object("quartodoc.tests.example_dynamic:InstanceAttrs", dynamic=True)
9797

9898
assert obj.members["z"].docstring.value == "The z attribute"
99+
100+
101+
def test_get_object_dynamic_module_attr_str():
102+
# a key behavior here is that it does not error attempting to look up
103+
# str.__module__, which does not exist
104+
obj = get_object("quartodoc.tests.example_dynamic:NOTE", dynamic=True)
105+
106+
assert obj.name == "NOTE"
107+
108+
# this case is weird, but we are dynamically looking up a string
109+
# so our __doc__ is technically str.__doc__
110+
assert obj.docstring.value == str.__doc__
111+
112+
113+
def test_get_object_dynamic_module_attr_class_instance():
114+
# a key behavior here is that it does not error attempting to look up
115+
# str.__module__, which does not exist
116+
obj = get_object("quartodoc.tests.example_dynamic:some_instance", dynamic=True)
117+
118+
assert obj.path == "quartodoc.tests.example_dynamic.some_instance"
119+
assert obj.docstring.value == "Dynamic instance doc"

0 commit comments

Comments
 (0)