File: test_docstrings.py

package info (click to toggle)
pydantic-core 2.41.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 3,836 kB
  • sloc: python: 35,821; javascript: 211; makefile: 128
file content (38 lines) | stat: -rw-r--r-- 1,488 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import sys

import pytest

try:
    from pytest_examples import CodeExample, EvalExample, find_examples
except ImportError:
    # pytest_examples is not installed on emscripten
    CodeExample = EvalExample = None

    def find_examples(*_directories):
        return []


@pytest.mark.skipif(CodeExample is None or sys.platform not in {'linux', 'darwin'}, reason='Only on linux and macos')
@pytest.mark.parametrize('example', find_examples('python/pydantic_core/core_schema.py'), ids=str)
@pytest.mark.thread_unsafe  # TODO investigate why pytest_examples seems to be thread unsafe here
def test_docstrings(example: CodeExample, eval_example: EvalExample):
    eval_example.set_config(quotes='single')

    if eval_example.update_examples:
        eval_example.format(example)
        eval_example.run_print_update(example)
    else:
        eval_example.lint(example)
        eval_example.run_print_check(example)


@pytest.mark.skipif(CodeExample is None or sys.platform not in {'linux', 'darwin'}, reason='Only on linux and macos')
@pytest.mark.parametrize('example', find_examples('README.md'), ids=str)
@pytest.mark.thread_unsafe  # TODO investigate why pytest_examples seems to be thread unsafe here
def test_readme(example: CodeExample, eval_example: EvalExample):
    eval_example.set_config(line_length=100, quotes='single')
    if eval_example.update_examples:
        eval_example.format(example)
    else:
        eval_example.lint(example)
        eval_example.run(example)