From 657611beb42c0e5844afd4cdb3ce538e18f7559f Mon Sep 17 00:00:00 2001 From: Jason Madden Date: Tue, 16 Jun 2026 09:32:48 -0500 Subject: [PATCH] Remove unused/unneeded legacy code, which gets our code coverage numbers up; enforce this. --- .coveragerc | 2 ++ src/sphinxcontrib/programoutput/__init__.py | 11 ++----- .../programoutput/tests/__init__.py | 29 ------------------- 3 files changed, 4 insertions(+), 38 deletions(-) diff --git a/.coveragerc b/.coveragerc index d0e7df9..aba4e63 100644 --- a/.coveragerc +++ b/.coveragerc @@ -8,3 +8,5 @@ exclude_lines = pragma: no cover if __name__ == .__main__.: def test_suite() + +fail_under = 99 diff --git a/src/sphinxcontrib/programoutput/__init__.py b/src/sphinxcontrib/programoutput/__init__.py index 8ca1b36..feb8c27 100644 --- a/src/sphinxcontrib/programoutput/__init__.py +++ b/src/sphinxcontrib/programoutput/__init__.py @@ -167,7 +167,7 @@ def run(self): _Command = namedtuple( - 'Command', 'command shell hide_standard_error working_directory') + '_Command', 'command shell hide_standard_error working_directory') class Command(_Command): @@ -191,14 +191,7 @@ def __new__(cls, command, shell=False, hide_standard_error=False, @staticmethod def __normalize_command(command, shell): # pylint:disable=unused-private-member - # Returns either a native string, to a tuple. - if (bytes is str - and not isinstance(command, str) - and hasattr(command, 'encode')): - # Python 2, given a unicode string - command = command.encode(sys.getfilesystemencoding()) - assert isinstance(command, str) - + # Returns either a native string, or a tuple. if not shell and isinstance(command, str): command = shlex.split(command) diff --git a/src/sphinxcontrib/programoutput/tests/__init__.py b/src/sphinxcontrib/programoutput/tests/__init__.py index 7e8c0f7..3151082 100644 --- a/src/sphinxcontrib/programoutput/tests/__init__.py +++ b/src/sphinxcontrib/programoutput/tests/__init__.py @@ -3,7 +3,6 @@ import shutil import tempfile -from docutils import nodes from docutils.parsers.rst import directives from docutils.parsers.rst import roles from sphinx.application import Sphinx @@ -53,26 +52,6 @@ def __get__(self, inst, class_): html_theme = 'default' """ -def _find_duplicate_default_nodes(): - from sphinx import addnodes # pylint:disable=import-outside-toplevel - - class App(object): - - def __init__(self): - self.nodes = set() - - def add_node(self, node): - self.nodes.add(node.__name__) - - - app = App() - try: - addnodes.setup(app) - except AttributeError: - # Sphinx 1 doesn't have this - pass - - return app.nodes class AppMixin(object): @@ -87,8 +66,6 @@ class AppMixin(object): document_encoding = 'utf-8' - duplicate_nodes_to_remove = _find_duplicate_default_nodes() - def setUp(self): # Avoid "WARNING: while setting up extension # sphinxcontrib.programoutput: directive u'program-output' is @@ -98,12 +75,6 @@ def setUp(self): # Likewise for 'eq' self.roles = roles._roles.copy() - # Avoid "node class 'toctree' is already registered, its visitors will be overridden" - # By default this class has *no* `visit_` methods - for node in self.duplicate_nodes_to_remove: - if hasattr(nodes.GenericNodeVisitor, 'visit_' + node): - delattr(nodes.GenericNodeVisitor, 'visit_' + node) - def tearDown(self): directives._directives = self.directives roles._roles = self.roles