GithubHelp home page GithubHelp logo

Allow test setup/cleanup about sybil HOT 6 CLOSED

simplistix avatar simplistix commented on August 19, 2024
Allow test setup/cleanup

from sybil.

Comments (6)

cjw296 avatar cjw296 commented on August 19, 2024

What's your use case for keeping support for sphinx.ext.doctest?

from sybil.

nstarman avatar nstarman commented on August 19, 2024

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.

cjw296 avatar cjw296 commented on August 19, 2024

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.

nstarman avatar nstarman commented on August 19, 2024

@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.

cjw296 avatar cjw296 commented on August 19, 2024

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.

nstarman avatar nstarman commented on August 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.