@@ -106,25 +106,21 @@ class CliTest(unittest.TestCase):
106
106
"""
107
107
ALL_FILES = [
108
108
'example_pkg' ,
109
- 'example_pkg/ index.html' ,
110
- 'example_pkg/ index.m.html' ,
111
- 'example_pkg/ module.html' ,
112
- 'example_pkg/ _private' ,
113
- 'example_pkg/ _private/ index.html' ,
114
- 'example_pkg/ _private/ module.html' ,
115
- 'example_pkg/ subpkg' ,
116
- 'example_pkg/ subpkg/ _private.html' ,
117
- 'example_pkg/ subpkg/ index.html' ,
118
- 'example_pkg/ subpkg2' ,
119
- 'example_pkg/ subpkg2/ _private.html' ,
120
- 'example_pkg/ subpkg2/ module.html' ,
121
- 'example_pkg/ subpkg2/ index.html' ,
109
+ os . path . join ( 'example_pkg' , ' index.html') ,
110
+ os . path . join ( 'example_pkg' , ' index.m.html') ,
111
+ os . path . join ( 'example_pkg' , ' module.html') ,
112
+ os . path . join ( 'example_pkg' , ' _private') ,
113
+ os . path . join ( 'example_pkg' , ' _private' , ' index.html') ,
114
+ os . path . join ( 'example_pkg' , ' _private' , ' module.html') ,
115
+ os . path . join ( 'example_pkg' , ' subpkg') ,
116
+ os . path . join ( 'example_pkg' , ' subpkg' , ' _private.html') ,
117
+ os . path . join ( 'example_pkg' , ' subpkg' , ' index.html') ,
118
+ os . path . join ( 'example_pkg' , ' subpkg2') ,
119
+ os . path . join ( 'example_pkg' , ' subpkg2' , ' _private.html') ,
120
+ os . path . join ( 'example_pkg' , ' subpkg2' , ' module.html') ,
121
+ os . path . join ( 'example_pkg' , ' subpkg2' , ' index.html') ,
122
122
]
123
- PUBLIC_FILES = [f for f in ALL_FILES if '/_' not in f ]
124
-
125
- if os .name == 'nt' :
126
- ALL_FILES = [i .replace ('/' , '\\ ' ) for i in ALL_FILES ]
127
- PUBLIC_FILES = [i .replace ('/' , '\\ ' ) for i in PUBLIC_FILES ]
123
+ PUBLIC_FILES = [f for f in ALL_FILES if (os .path .sep + '_' ) not in f ]
128
124
129
125
def setUp (self ):
130
126
pdoc .reset ()
@@ -190,7 +186,7 @@ def test_html(self):
190
186
'.subpkg2' : [f for f in self .PUBLIC_FILES
191
187
if 'subpkg2' in f or f == EXAMPLE_MODULE ],
192
188
'._private' : [f for f in self .ALL_FILES
193
- if EXAMPLE_MODULE + '/ _private' in f or f == EXAMPLE_MODULE ],
189
+ if EXAMPLE_MODULE + os . path . sep + ' _private' in f or f == EXAMPLE_MODULE ],
194
190
}
195
191
for package , expected_files in package_files .items ():
196
192
with self .subTest (package = package ):
@@ -203,7 +199,8 @@ def test_html(self):
203
199
filenames_files = {
204
200
('module.py' ,): ['module.html' ],
205
201
('module.py' , 'subpkg2' ): ['module.html' , 'subpkg2' ,
206
- 'subpkg2/index.html' , 'subpkg2/module.html' ],
202
+ os .path .join ('subpkg2' , 'index.html' ),
203
+ os .path .join ('subpkg2' , 'module.html' )],
207
204
}
208
205
with chdir (TESTS_BASEDIR ):
209
206
for filenames , expected_files in filenames_files .items ():
@@ -216,9 +213,11 @@ def test_html(self):
216
213
217
214
def test_html_multiple_files (self ):
218
215
with chdir (TESTS_BASEDIR ):
219
- with run_html (EXAMPLE_MODULE + '/module.py' , EXAMPLE_MODULE + '/subpkg2' ):
220
- self ._basic_html_assertions (
221
- ['module.html' , 'subpkg2' , 'subpkg2/index.html' , 'subpkg2/module.html' ])
216
+ with run_html (os .path .join (EXAMPLE_MODULE , 'module.py' ),
217
+ os .path .join (EXAMPLE_MODULE , 'subpkg2' )):
218
+ self ._basic_html_assertions (['module.html' , 'subpkg2' ,
219
+ os .path .join ('subpkg2' , 'index.html' ),
220
+ os .path .join ('subpkg2' , 'module.html' )])
222
221
223
222
def test_html_identifier (self ):
224
223
for package in ('' , '._private' ):
@@ -232,7 +231,7 @@ def test_html_identifier(self):
232
231
def test_html_ref_links (self ):
233
232
with run_html (EXAMPLE_MODULE , config = 'show_source_code=False' ):
234
233
self ._check_files (
235
- file_pattern = EXAMPLE_MODULE + '/ index.html' ,
234
+ file_pattern = os . path . join ( EXAMPLE_MODULE , ' index.html') ,
236
235
include_patterns = [
237
236
'href="#example_pkg.B">' ,
238
237
'href="#example_pkg.A">' ,
@@ -1099,6 +1098,39 @@ def func(self):
1099
1098
self .assertIsInstance (cls .doc ['name' ], pdoc .Variable )
1100
1099
self .assertEqual (cls .doc ['name' ].type_annotation (), 'str' )
1101
1100
1101
+ def test_doc_comment_docstrings (self ):
1102
+ with temp_dir () as path :
1103
+ filename = os .path .join (path , 'doc_comment_docstrs.py' )
1104
+ with open (filename , 'w' ) as f :
1105
+ f .write ('''#: Not included
1106
+
1107
+ #: Line 1
1108
+ #: Line 2
1109
+ var1 = 1 #: Line 3
1110
+
1111
+ #: Not included
1112
+ var2 = 1
1113
+ """PEP-224 takes precedence"""
1114
+
1115
+ #: This should not appear
1116
+ class C:
1117
+ #: class var
1118
+ class_var = 1
1119
+
1120
+ #: This also should not show
1121
+ def __init__(self):
1122
+ #: instance var
1123
+ self.instance_var = 1
1124
+ ''' )
1125
+
1126
+ mod = pdoc .Module (pdoc .import_module (filename ))
1127
+
1128
+ self .assertEqual (mod .doc ['var1' ].docstring , 'Line 1\n Line 2\n Line 3' )
1129
+ self .assertEqual (mod .doc ['var2' ].docstring , 'PEP-224 takes precedence' )
1130
+ self .assertEqual (mod .doc ['C' ].docstring , '' )
1131
+ self .assertEqual (mod .doc ['C' ].doc ['class_var' ].docstring , 'class var' )
1132
+ self .assertEqual (mod .doc ['C' ].doc ['instance_var' ].docstring , 'instance var' )
1133
+
1102
1134
1103
1135
class HtmlHelpersTest (unittest .TestCase ):
1104
1136
"""
0 commit comments