File tree Expand file tree Collapse file tree 3 files changed +65
-0
lines changed
test_data/driver-examples Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -347,6 +347,31 @@ def handle_directive(
347347 msg = f'Invalid "literalinclude": { err } '
348348 self .diagnostics .append (Diagnostic .error (msg , util .get_line (node )))
349349 return
350+ elif name == "include" :
351+ if argument_text is None :
352+ self .diagnostics .append (
353+ Diagnostic .error (
354+ f'"{ name } " expected a path argument' , util .get_line (node )
355+ )
356+ )
357+ return
358+
359+ fileid , path = util .reroot_path (
360+ Path (argument_text ), self .docpath , self .source_path
361+ )
362+
363+ # Validate if file exists
364+ if not path .is_file ():
365+ # Check if file is snooty-generated
366+ if (
367+ fileid .match ("steps/*.rst" )
368+ or fileid .match ("extracts/*.rst" )
369+ or fileid .match ("release/*.rst" )
370+ ):
371+ pass
372+ else :
373+ msg = f'"{ name } " could not open "{ argument_text } : No such file exists"'
374+ self .diagnostics .append (Diagnostic .error (msg , util .get_line (node )))
350375
351376 if options :
352377 doc ["options" ] = options
Original file line number Diff line number Diff line change @@ -178,6 +178,46 @@ def test_literalinclude() -> None:
178178 assert len (diagnostics ) == 1
179179
180180
181+ def test_include () -> None :
182+ root = Path ("test_data" )
183+ path = Path (root ).joinpath (Path ("test.rst" ))
184+ project_config = ProjectConfig (root , "" , source = "./" )
185+ parser = rstparser .Parser (project_config , JSONVisitor )
186+
187+ # Test good include
188+ page , diagnostics = parse_rst (
189+ parser ,
190+ path ,
191+ """
192+ .. include:: /driver-examples/rstexample.rst
193+ """ ,
194+ )
195+ page .finish (diagnostics )
196+ assert diagnostics == []
197+
198+ # Test generated include
199+ page , diagnostics = parse_rst (
200+ parser ,
201+ path ,
202+ """
203+ .. include:: /driver-examples/steps/generated-include.rst
204+ """ ,
205+ )
206+ page .finish (diagnostics )
207+ assert diagnostics == []
208+
209+ # Test bad include
210+ page , diagnostics = parse_rst (
211+ parser ,
212+ path ,
213+ """
214+ .. include:: /driver-examples/fake-include.rst
215+ """ ,
216+ )
217+ page .finish (diagnostics )
218+ assert len (diagnostics ) == 1
219+
220+
181221def test_admonition () -> None :
182222 root = Path ("test_data" )
183223 path = Path (root ).joinpath (Path ("test.rst" ))
You can’t perform that action at this time.
0 commit comments