참고소스 수정본
This commit is contained in:
79
참고/instructor-main/tests/docs/_concept_groups.py
Normal file
79
참고/instructor-main/tests/docs/_concept_groups.py
Normal file
@@ -0,0 +1,79 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import glob
|
||||
import os
|
||||
from collections.abc import Iterable
|
||||
|
||||
from pytest_examples import find_examples
|
||||
|
||||
CORE = {
|
||||
"alias.md",
|
||||
"dictionary_operations.md",
|
||||
"distillation.md",
|
||||
"enums.md",
|
||||
"fastapi.md",
|
||||
"fields.md",
|
||||
"index.md",
|
||||
"iterable.md",
|
||||
"lists.md",
|
||||
"logging.md",
|
||||
"maybe.md",
|
||||
"models.md",
|
||||
"parallel.md",
|
||||
"partial.md",
|
||||
"philosophy.md",
|
||||
"prompting.md",
|
||||
"typeadapter.md",
|
||||
"typeddicts.md",
|
||||
"types.md",
|
||||
"union.md",
|
||||
"unions.md",
|
||||
"validation.md",
|
||||
}
|
||||
|
||||
OPERATIONS = {
|
||||
"caching.md",
|
||||
"prompt_caching.md",
|
||||
"raw_response.md",
|
||||
"retrying.md",
|
||||
"error_handling.md",
|
||||
}
|
||||
|
||||
PROVIDERS = {
|
||||
"from_provider.md",
|
||||
"migration.md",
|
||||
"mode-migration.md",
|
||||
"patching.md",
|
||||
"usage.md",
|
||||
}
|
||||
|
||||
ADVANCED = {
|
||||
"batch.md",
|
||||
"hooks.md",
|
||||
"multimodal.md",
|
||||
"reask_validation.md",
|
||||
"semantic_validation.md",
|
||||
"templating.md",
|
||||
}
|
||||
|
||||
|
||||
def concept_paths(names: Iterable[str]) -> list[str]:
|
||||
return [os.path.join("docs", "concepts", name) for name in names]
|
||||
|
||||
|
||||
def all_concept_files() -> list[str]:
|
||||
return sorted(glob.glob("docs/concepts/*.md"))
|
||||
|
||||
|
||||
def core_concept_files() -> list[str]:
|
||||
excluded = OPERATIONS | PROVIDERS | ADVANCED
|
||||
return [
|
||||
path for path in all_concept_files() if os.path.basename(path) not in excluded
|
||||
]
|
||||
|
||||
|
||||
def collect_examples(files: Iterable[str]):
|
||||
examples = []
|
||||
for markdown_file in files:
|
||||
examples.extend(find_examples(markdown_file))
|
||||
return examples
|
||||
62
참고/instructor-main/tests/docs/_example_groups.py
Normal file
62
참고/instructor-main/tests/docs/_example_groups.py
Normal file
@@ -0,0 +1,62 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import glob
|
||||
import os
|
||||
from collections.abc import Iterable
|
||||
|
||||
from pytest_examples import find_examples
|
||||
|
||||
EXCLUDED = {
|
||||
"ollama.md",
|
||||
"watsonx.md",
|
||||
"local_classification.md",
|
||||
}
|
||||
|
||||
BATCH = {
|
||||
"batch_classification_langsmith.md",
|
||||
"batch_in_memory.md",
|
||||
"batch_job_oai.md",
|
||||
}
|
||||
|
||||
MULTIMODAL = {
|
||||
"audio_extraction.md",
|
||||
"extract_slides.md",
|
||||
"extracting_receipts.md",
|
||||
"image_to_ad_copy.md",
|
||||
"multi_modal_gemini.md",
|
||||
"tables_from_vision.md",
|
||||
"youtube_clips.md",
|
||||
}
|
||||
|
||||
PROVIDERS = {
|
||||
"groq.md",
|
||||
"mistral.md",
|
||||
"open_source.md",
|
||||
}
|
||||
|
||||
INTEGRATIONS = {
|
||||
"search.md",
|
||||
"tracing_with_langfuse.md",
|
||||
}
|
||||
|
||||
|
||||
def example_paths(names: Iterable[str]) -> list[str]:
|
||||
return [os.path.join("docs", "examples", name) for name in names]
|
||||
|
||||
|
||||
def all_example_files() -> list[str]:
|
||||
return sorted(glob.glob("docs/examples/*.md"))
|
||||
|
||||
|
||||
def core_example_files() -> list[str]:
|
||||
excluded = EXCLUDED | BATCH | MULTIMODAL | PROVIDERS | INTEGRATIONS
|
||||
return [
|
||||
path for path in all_example_files() if os.path.basename(path) not in excluded
|
||||
]
|
||||
|
||||
|
||||
def collect_examples(files: Iterable[str]):
|
||||
examples = []
|
||||
for markdown_file in files:
|
||||
examples.extend(find_examples(markdown_file))
|
||||
return examples
|
||||
40
참고/instructor-main/tests/docs/conftest.py
Normal file
40
참고/instructor-main/tests/docs/conftest.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from pytest_examples import CodeExample, EvalExample
|
||||
|
||||
|
||||
def pytest_addoption(parser: pytest.Parser) -> None:
|
||||
group = parser.getgroup("docs")
|
||||
group.addoption(
|
||||
"--run-doc-examples",
|
||||
action="store_true",
|
||||
help="Execute doc code examples (requires network access and API keys).",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(name="eval_example")
|
||||
def eval_example(
|
||||
tmp_path: Path,
|
||||
request: pytest.FixtureRequest,
|
||||
_examples_to_update: list[CodeExample],
|
||||
):
|
||||
eval_ex = EvalExample(tmp_path=tmp_path, pytest_request=request)
|
||||
run_live = bool(
|
||||
request.config.getoption("run_doc_examples")
|
||||
or request.config.getoption("update_examples")
|
||||
)
|
||||
if not run_live:
|
||||
|
||||
def _skip_run(_example: CodeExample) -> None:
|
||||
return None
|
||||
|
||||
eval_ex.run = _skip_run # type: ignore[assignment]
|
||||
eval_ex.run_print_update = _skip_run # type: ignore[assignment]
|
||||
|
||||
yield eval_ex
|
||||
|
||||
if request.config.getoption("update_examples"):
|
||||
_examples_to_update.extend(eval_ex.to_update)
|
||||
16
참고/instructor-main/tests/docs/test_concepts.py
Normal file
16
참고/instructor-main/tests/docs/test_concepts.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import pytest
|
||||
from pytest_examples import CodeExample, EvalExample
|
||||
|
||||
from tests.docs._concept_groups import collect_examples, core_concept_files
|
||||
|
||||
code_examples = collect_examples(core_concept_files())
|
||||
|
||||
|
||||
@pytest.mark.parametrize("example", code_examples, ids=str)
|
||||
def test_format_concepts_core(example: CodeExample, eval_example: EvalExample):
|
||||
if eval_example.update_examples:
|
||||
eval_example.format(example)
|
||||
eval_example.run_print_update(example)
|
||||
else:
|
||||
eval_example.lint(example)
|
||||
eval_example.run(example)
|
||||
15
참고/instructor-main/tests/docs/test_concepts_advanced.py
Normal file
15
참고/instructor-main/tests/docs/test_concepts_advanced.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import pytest
|
||||
from pytest_examples import CodeExample, EvalExample
|
||||
|
||||
from tests.docs._concept_groups import ADVANCED, collect_examples, concept_paths
|
||||
|
||||
code_examples = collect_examples(concept_paths(ADVANCED))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("example", code_examples, ids=str)
|
||||
def test_format_concepts_advanced(example: CodeExample, eval_example: EvalExample):
|
||||
if eval_example.update_examples:
|
||||
eval_example.format(example)
|
||||
eval_example.run_print_update(example)
|
||||
else:
|
||||
eval_example.lint(example)
|
||||
15
참고/instructor-main/tests/docs/test_concepts_operations.py
Normal file
15
참고/instructor-main/tests/docs/test_concepts_operations.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import pytest
|
||||
from pytest_examples import CodeExample, EvalExample
|
||||
|
||||
from tests.docs._concept_groups import OPERATIONS, collect_examples, concept_paths
|
||||
|
||||
code_examples = collect_examples(concept_paths(OPERATIONS))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("example", code_examples, ids=str)
|
||||
def test_format_concepts_operations(example: CodeExample, eval_example: EvalExample):
|
||||
if eval_example.update_examples:
|
||||
eval_example.format(example)
|
||||
eval_example.run_print_update(example)
|
||||
else:
|
||||
eval_example.lint(example)
|
||||
15
참고/instructor-main/tests/docs/test_concepts_providers.py
Normal file
15
참고/instructor-main/tests/docs/test_concepts_providers.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import pytest
|
||||
from pytest_examples import CodeExample, EvalExample
|
||||
|
||||
from tests.docs._concept_groups import PROVIDERS, collect_examples, concept_paths
|
||||
|
||||
code_examples = collect_examples(concept_paths(PROVIDERS))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("example", code_examples, ids=str)
|
||||
def test_format_concepts_providers(example: CodeExample, eval_example: EvalExample):
|
||||
if eval_example.update_examples:
|
||||
eval_example.format(example)
|
||||
eval_example.run_print_update(example)
|
||||
else:
|
||||
eval_example.lint(example)
|
||||
18
참고/instructor-main/tests/docs/test_docs.py
Normal file
18
참고/instructor-main/tests/docs/test_docs.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import pytest
|
||||
from pytest_examples import find_examples, CodeExample, EvalExample
|
||||
|
||||
|
||||
@pytest.mark.parametrize("example", find_examples("README.md"), ids=str)
|
||||
def test_readme(example: CodeExample, eval_example: EvalExample):
|
||||
if eval_example.update_examples:
|
||||
eval_example.format(example)
|
||||
else:
|
||||
eval_example.lint(example)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("example", find_examples("docs/index.md"), ids=str)
|
||||
def test_index(example: CodeExample, eval_example: EvalExample):
|
||||
if eval_example.update_examples:
|
||||
eval_example.format(example)
|
||||
else:
|
||||
eval_example.lint(example)
|
||||
14
참고/instructor-main/tests/docs/test_examples.py
Normal file
14
참고/instructor-main/tests/docs/test_examples.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import pytest
|
||||
from pytest_examples import CodeExample, EvalExample
|
||||
from tests.docs._example_groups import collect_examples, core_example_files
|
||||
|
||||
code_examples = collect_examples(core_example_files())
|
||||
|
||||
|
||||
@pytest.mark.parametrize("example", code_examples, ids=str)
|
||||
def test_index(example: CodeExample, eval_example: EvalExample):
|
||||
if eval_example.update_examples:
|
||||
eval_example.format(example)
|
||||
eval_example.run_print_update(example)
|
||||
else:
|
||||
eval_example.lint(example)
|
||||
15
참고/instructor-main/tests/docs/test_examples_batch.py
Normal file
15
참고/instructor-main/tests/docs/test_examples_batch.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import pytest
|
||||
from pytest_examples import CodeExample, EvalExample
|
||||
|
||||
from tests.docs._example_groups import BATCH, collect_examples, example_paths
|
||||
|
||||
code_examples = collect_examples(example_paths(BATCH))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("example", code_examples, ids=str)
|
||||
def test_examples_batch(example: CodeExample, eval_example: EvalExample):
|
||||
if eval_example.update_examples:
|
||||
eval_example.format(example)
|
||||
eval_example.run_print_update(example)
|
||||
else:
|
||||
eval_example.lint(example)
|
||||
15
참고/instructor-main/tests/docs/test_examples_integrations.py
Normal file
15
참고/instructor-main/tests/docs/test_examples_integrations.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import pytest
|
||||
from pytest_examples import CodeExample, EvalExample
|
||||
|
||||
from tests.docs._example_groups import INTEGRATIONS, collect_examples, example_paths
|
||||
|
||||
code_examples = collect_examples(example_paths(INTEGRATIONS))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("example", code_examples, ids=str)
|
||||
def test_examples_integrations(example: CodeExample, eval_example: EvalExample):
|
||||
if eval_example.update_examples:
|
||||
eval_example.format(example)
|
||||
eval_example.run_print_update(example)
|
||||
else:
|
||||
eval_example.lint(example)
|
||||
15
참고/instructor-main/tests/docs/test_examples_multimodal.py
Normal file
15
참고/instructor-main/tests/docs/test_examples_multimodal.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import pytest
|
||||
from pytest_examples import CodeExample, EvalExample
|
||||
|
||||
from tests.docs._example_groups import MULTIMODAL, collect_examples, example_paths
|
||||
|
||||
code_examples = collect_examples(example_paths(MULTIMODAL))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("example", code_examples, ids=str)
|
||||
def test_examples_multimodal(example: CodeExample, eval_example: EvalExample):
|
||||
if eval_example.update_examples:
|
||||
eval_example.format(example)
|
||||
eval_example.run_print_update(example)
|
||||
else:
|
||||
eval_example.lint(example)
|
||||
15
참고/instructor-main/tests/docs/test_examples_providers.py
Normal file
15
참고/instructor-main/tests/docs/test_examples_providers.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import pytest
|
||||
from pytest_examples import CodeExample, EvalExample
|
||||
|
||||
from tests.docs._example_groups import PROVIDERS, collect_examples, example_paths
|
||||
|
||||
code_examples = collect_examples(example_paths(PROVIDERS))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("example", code_examples, ids=str)
|
||||
def test_examples_providers(example: CodeExample, eval_example: EvalExample):
|
||||
if eval_example.update_examples:
|
||||
eval_example.format(example)
|
||||
eval_example.run_print_update(example)
|
||||
else:
|
||||
eval_example.lint(example)
|
||||
25
참고/instructor-main/tests/docs/test_hub.py
Normal file
25
참고/instructor-main/tests/docs/test_hub.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import pytest
|
||||
from pytest_examples import CodeExample, EvalExample
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Hub functionality is being removed")
|
||||
def test_format_blog(example: CodeExample, eval_example: EvalExample) -> None:
|
||||
"""This test is being skipped as the hub functionality is being removed."""
|
||||
excluded_sources: list[str] = [
|
||||
"mistral",
|
||||
"ollama",
|
||||
"llama_cpp",
|
||||
"groq",
|
||||
"youtube",
|
||||
"contact",
|
||||
"langsmith",
|
||||
] # sources that are not supported in testing
|
||||
if any(source in example.source for source in excluded_sources):
|
||||
return
|
||||
|
||||
if eval_example.update_examples:
|
||||
eval_example.format(example)
|
||||
eval_example.run_print_update(example)
|
||||
else:
|
||||
eval_example.lint(example)
|
||||
eval_example.run(example)
|
||||
16
참고/instructor-main/tests/docs/test_mkdocs.py
Normal file
16
참고/instructor-main/tests/docs/test_mkdocs.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import pathlib
|
||||
import pytest
|
||||
import importlib
|
||||
from typing import Any, cast
|
||||
|
||||
|
||||
# Note the use of `str`, makes for pretty output
|
||||
@pytest.mark.parametrize(
|
||||
"fpath", pathlib.Path("docs/examples").glob("**/*.md"), ids=str
|
||||
)
|
||||
@pytest.mark.skip(reason="This test is not yet implemented")
|
||||
def test_files_good(fpath):
|
||||
mktestdocs = cast(Any, importlib.import_module("mktestdocs"))
|
||||
check_md_file = mktestdocs.check_md_file
|
||||
|
||||
check_md_file(fpath=fpath, memory=True)
|
||||
11
참고/instructor-main/tests/docs/test_posts.py
Normal file
11
참고/instructor-main/tests/docs/test_posts.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import pytest
|
||||
from pytest_examples import find_examples, CodeExample, EvalExample
|
||||
|
||||
|
||||
@pytest.mark.parametrize("example", find_examples("docs/blog/posts"), ids=str)
|
||||
def test_index(example: CodeExample, eval_example: EvalExample):
|
||||
if eval_example.update_examples:
|
||||
eval_example.format(example)
|
||||
eval_example.run_print_update(example)
|
||||
else:
|
||||
eval_example.lint(example)
|
||||
13
참고/instructor-main/tests/docs/test_prompt_tips.py
Normal file
13
참고/instructor-main/tests/docs/test_prompt_tips.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import pytest
|
||||
from pytest_examples import find_examples, CodeExample, EvalExample
|
||||
|
||||
|
||||
@pytest.mark.parametrize("example", find_examples("docs/prompting"), ids=str)
|
||||
@pytest.mark.skip(reason="Skipping this for now")
|
||||
def test_format_concepts(example: CodeExample, eval_example: EvalExample):
|
||||
if eval_example.update_examples:
|
||||
eval_example.format(example)
|
||||
# eval_example.run_print_update(example)
|
||||
else:
|
||||
eval_example.lint(example)
|
||||
# eval_example.run(example)
|
||||
Reference in New Issue
Block a user