Skip to content

Commit f8453b0

Browse files
committed
fix(docs): Use repo-agnostic examples in compat.py doctests
Replace tmuxp-specific examples with inline test module creation that works in any repository without external dependencies
1 parent ea78fb0 commit f8453b0

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

docs/_ext/sphinx_argparse_neo/compat.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,24 @@ def get_parser_from_module(
191191
192192
Examples
193193
--------
194-
Load tmuxp's parser factory:
194+
Load a parser from a module with a factory function:
195195
196-
>>> parser = get_parser_from_module("tmuxp.cli", "create_parser")
196+
>>> import argparse
197+
>>> import sys
198+
>>> # Create a test module with a parser factory
199+
>>> import types
200+
>>> test_mod = types.ModuleType("_test_parser_mod")
201+
>>> def _create_parser():
202+
... p = argparse.ArgumentParser(prog="test")
203+
... return p
204+
>>> test_mod.create_parser = _create_parser
205+
>>> sys.modules["_test_parser_mod"] = test_mod
206+
>>> parser = get_parser_from_module("_test_parser_mod", "create_parser")
197207
>>> parser.prog
198-
'tmuxp'
208+
'test'
199209
>>> hasattr(parser, 'parse_args')
200210
True
211+
>>> del sys.modules["_test_parser_mod"]
201212
"""
202213
ctx = mock_imports(mock_modules) if mock_modules else contextlib.nullcontext()
203214

@@ -250,11 +261,20 @@ def get_parser_from_entry_point(
250261
251262
Examples
252263
--------
253-
Load tmuxp's parser using entry point syntax:
264+
Load a parser using entry point syntax:
254265
255-
>>> parser = get_parser_from_entry_point("tmuxp.cli:create_parser")
266+
>>> import argparse
267+
>>> import sys
268+
>>> import types
269+
>>> test_mod = types.ModuleType("_test_ep_mod")
270+
>>> def _create_parser():
271+
... return argparse.ArgumentParser(prog="test-ep")
272+
>>> test_mod.create_parser = _create_parser
273+
>>> sys.modules["_test_ep_mod"] = test_mod
274+
>>> parser = get_parser_from_entry_point("_test_ep_mod:create_parser")
256275
>>> parser.prog
257-
'tmuxp'
276+
'test-ep'
277+
>>> del sys.modules["_test_ep_mod"]
258278
259279
Invalid format raises ValueError:
260280

0 commit comments

Comments
 (0)