2929import unittest
3030from unittest .mock import patch as Patch
3131
32-
33- from docutils .nodes import caption , container , literal_block , system_message
34-
32+ from docutils .nodes import caption
33+ from docutils .nodes import container
34+ from docutils .nodes import literal_block
35+ from docutils .nodes import system_message
3536from sphinxcontrib .programoutput import Command
3637
3738from . import AppMixin
@@ -42,6 +43,8 @@ def with_content(content, **kwargs):
4243 Always use a bare 'python' in the *content* string.
4344
4445 It will be replaced with ``sys.executable``.
46+
47+ Keyword arguments go directly into the Sphinx configuration.
4548 """
4649 if 'python' in content :
4750 # XXX: This probably breaks if there are spaces in sys.executable.
@@ -439,7 +442,6 @@ def test_name_with_caption(self):
439442 self .assert_output (self .doctree , 'spam' , caption = 'mycaption' , name = 'myname' )
440443 self .assert_cache (self .app , 'echo spam' , 'spam' )
441444
442-
443445 @with_content ("""\
444446 .. program-output:: python -c 'import json; d = {"foo": "bar"}; print(json.dumps(d))'
445447 :language: json""" ,
@@ -450,7 +452,6 @@ def test_language_json(self):
450452 self .assertEqual (literal .astext (), '{"foo": "bar"}' )
451453 self .assertEqual (literal ["language" ], "json" )
452454
453-
454455 @with_content ("""\
455456 .. program-output:: echo spam""" ,
456457 programoutput_use_ansi = True )
@@ -464,24 +465,39 @@ def test_use_ansi_config_forwarded(self):
464465 self .assertTrue (create_output_node .call_args .args [1 ])
465466 self .assert_cache (self .app , 'echo spam' , 'spam' )
466467
467-
468468 @with_content ("""\
469469 .. program-output:: python -c 'print("\\ x1b[31mspam\\ x1b[0m")'""" ,
470470 programoutput_use_ansi = True )
471- def test_use_ansi_missing_dependency (self ):
471+ def test_use_ansi_missing_extension (self ):
472472 with Patch ('sphinxcontrib.programoutput.logger.warning' ) as patch_warning :
473473 doctree = self .doctree
474474
475475 self .assert_output (doctree , 'spam' )
476476 patch_warning .assert_called_once ()
477477 warning = patch_warning .call_args .args [0 ]
478478 self .assertIn ('programoutput_use_ansi is enabled' , warning )
479+ self .assertIn ("but 'erbsland.sphinx.ansi' is not enabled" , warning )
479480 self .assert_cache (
480481 self .app ,
481482 sys .executable + " -c 'print(\" \\ x1b[31mspam\\ x1b[0m\" )'" ,
482483 '\x1b [31mspam\x1b [0m'
483484 )
484485
486+ @with_content ("""\
487+ .. program-output:: python -c 'print("\\ x1b[31mspam\\ x1b[0m")'""" ,
488+ programoutput_use_ansi = True ,
489+ extensions = ['sphinxcontrib.programoutput' , 'erbsland.sphinx.ansi' ])
490+ def test_use_ansi_enabled_extension (self ):
491+ with Patch ('sphinxcontrib.programoutput.logger.warning' ) as patch_warning :
492+ doctree = self .doctree
493+
494+ self .assert_output (doctree , '\x1b [31mspam\x1b [0m' )
495+ patch_warning .assert_not_called ()
496+ self .assert_cache (
497+ self .app ,
498+ sys .executable + " -c 'print(\" \\ x1b[31mspam\\ x1b[0m\" )'" ,
499+ '\x1b [31mspam\x1b [0m'
500+ )
485501
486502def test_suite ():
487503 return unittest .defaultTestLoader .loadTestsFromName (__name__ )
0 commit comments