Comments (6)
What's your use case for keeping support for sphinx.ext.doctest
?
from sybil.
Primarily pytest-doctestplus
, which uses most of the sphinx.ext.doctest
syntax. It. would be easier to discuss docs with collaborators who are used to pytest-doctestplus
if the testsetup
<-> invisible-code-block
mapping were done behind-the-scenes.
from sybil.
My recommendation would be pick one tool and stick with it: if you want to use Sybil, then switch to it, if you want to use pytest-doctestplus, then use that.
Trying to support multiple example testing tools with subtly different semantics is not something I'd recommend, so while there's nothing stopping you doing what you suggest in your own code base, it's not something I'll land in a release.
from sybil.
@cjw296, I got it working with
class ExtendedPythonCodeBlockParser(AbstractCodeBlockParser):
def __init__(self, future_imports=()) -> None:
super().__init__(
[
DirectiveLexer(directive=r"code-block"),
DirectiveLexer(directive=r"testsetup"),
DirectiveLexer(directive=r"testcleanup"),
DirectiveInCommentLexer(directive=r"(invisible-)?code(-block)?"),
],
"python", PythonEvaluator(future_imports)
)
pad = staticmethod(pad)
using this class to replace the standard PythonCodeBlockParser
Sybil provides.
While this works, it's somewhat inelegant. I tried instead making a custom DirectiveParser
, using DocTestDirectiveParser
as my template, but it didn't work.
class TestSetupDirectiveParser:
def __init__(self, optionflags=0) -> None:
self.lexer = DirectiveLexer(directive="testsetup")
self.string_parser = DocTestStringParser(DocTestEvaluator(optionflags))
def __call__(self, document: Document) -> Iterable[Region]:
for lexed in self.lexer(document):
source = lexed.lexemes["source"]
for doctest_region in self.string_parser(source, document.path):
doctest_region.adjust(lexed, source)
yield doctest_region
My conftest
looked like
pytest_collect_file = Sybil(
parsers=[
DocTestParser(optionflags=ELLIPSIS),
TestSetupDirectiveParser(),
PythonCodeBlockParser(),
SkipParser(),
],
patterns=["*.rst", "*.py"],
).pytest()
Do you have any recommendations to make the DocTestDirectiveParser
-variant work?
from sybil.
I'm surprised your ExtendedPythonCodeBlockParser
works, given that your codeblocks have doctest rather than python in them judging by https://github.com/search?q=repo%3Aastropy%2Fastropy+testsetup&type=code?
As for TestSetupDirectiveParser
, if you get it right, I don't think you'll need to override __call__
.
from sybil.
Thanks! I'll give it another shot.
This is for https://cosmology-compat-astropy--15.org.readthedocs.build/en/15/.
from sybil.
Related Issues (20)
- `skip: next` now seems to require an empty line after it HOT 2
- Pytest 8 error: FixtureManager.getfixtureclosure() missing 1 required positional argument: 'ignore_args' HOT 14
- Support for `testcode` and `testoutput` in `DocTestDirectiveParser`s HOT 6
- MyST lexer can't handle code fences with additional backticks HOT 5
- sdist is missing some files needed for testing HOT 3
- AttributeError: 'NoneType' object has no attribute 'end' HOT 5
- isinstance with `Protocol` fails in doctest HOT 3
- Codeblock Lexer pattern doesn't work if codeblock ends with close comment (end of input to the lexer) HOT 2
- Markdown forces an empty line at the end HOT 9
- tests/helpers.py not in PyPI tarball HOT 1
- Have a badge HOT 1
- Doesn't work with namespace packages HOT 3
- Unhelpful error with missing final linefeed HOT 4
- Warnings on Python 3.12 about ast.Str HOT 2
- Feature request: Add type hints HOT 3
- ModuleNotFoundError if pytest is not installed HOT 5
- Support GitHub Flavored Markdown (GFM)
- Request: Add test which fails if `self.evaluator = None` is removed HOT 2
- Parse and export directive options, too HOT 18
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sybil.