From e8edf4175fcdc4146884f1f978938d44e79c7db4 Mon Sep 17 00:00:00 2001 From: Sh1nku <42642351+Sh1nku@users.noreply.github.com> Date: Fri, 1 Nov 2024 18:12:10 +0100 Subject: [PATCH] Fix error in how doctests were ran --- wrappers/python/solrstice/__init__.pyi | 213 +++++++++++++------------ wrappers/python/tests/test_doctest.py | 22 ++- 2 files changed, 127 insertions(+), 108 deletions(-) diff --git a/wrappers/python/solrstice/__init__.pyi b/wrappers/python/solrstice/__init__.pyi index 2e225ec..8f489c2 100644 --- a/wrappers/python/solrstice/__init__.pyi +++ b/wrappers/python/solrstice/__init__.pyi @@ -582,8 +582,8 @@ class AsyncSolrCloudClient: :param context: The context of the Solr server. >>> from solrstice import SolrServerContext, SolrBasicAuth, AsyncSolrCloudClient - ... context = SolrServerContext("http://localhost:8983", SolrBasicAuth("user", "pass")) - ... client = AsyncSolrCloudClient(context) + >>> context = SolrServerContext("http://localhost:8983", SolrBasicAuth("user", "pass")) + >>> client = AsyncSolrCloudClient(context) """ @@ -599,9 +599,9 @@ class AsyncSolrCloudClient: :param config_path: Path to the config >>> from solrstice import SolrServerContext, AsyncSolrCloudClient - ... context = SolrServerContext("http://localhost:8983") - ... client = AsyncSolrCloudClient(context) - ... async def upload_config() -> None: + >>> context = SolrServerContext("http://localhost:8983") + >>> client = AsyncSolrCloudClient(context) + >>> async def upload_config() -> None: ... await client.upload_config("config_name", "/path/to/config") """ @@ -611,10 +611,10 @@ class AsyncSolrCloudClient: :returns: A list of Solr configs >>> from solrstice import SolrServerContext, AsyncSolrCloudClient - ... from typing import List - ... context = SolrServerContext("http://localhost:8983") - ... client = AsyncSolrCloudClient(context) - ... async def get_configs() -> List[str]: + >>> from typing import List + >>> context = SolrServerContext("http://localhost:8983") + >>> client = AsyncSolrCloudClient(context) + >>> async def get_configs() -> List[str]: ... return await client.get_configs() """ @@ -626,9 +626,9 @@ class AsyncSolrCloudClient: :returns: True if the config exists, False otherwise >>> from solrstice import SolrServerContext, AsyncSolrCloudClient - ... context = SolrServerContext("http://localhost:8983") - ... client = AsyncSolrCloudClient(context) - ... async def config_exists() -> bool: + >>> context = SolrServerContext("http://localhost:8983") + >>> client = AsyncSolrCloudClient(context) + >>> async def config_exists() -> bool: ... return await client.config_exists("config_name") """ @@ -638,9 +638,9 @@ class AsyncSolrCloudClient: :param config_name: Name of the config >>> from solrstice import SolrServerContext, AsyncSolrCloudClient - ... context = SolrServerContext("http://localhost:8983") - ... client = AsyncSolrCloudClient(context) - ... async def delete_config() -> None: + >>> context = SolrServerContext("http://localhost:8983") + >>> client = AsyncSolrCloudClient(context) + >>> async def delete_config() -> None: ... await client.delete_config("config_name") """ @@ -662,9 +662,9 @@ class AsyncSolrCloudClient: :param replication_factor: The replication factor to use. >>> from solrstice import SolrServerContext, AsyncSolrCloudClient - ... context = SolrServerContext("http://localhost:8983") - ... client = AsyncSolrCloudClient(context) - ... async def create_collection() -> None: + >>> context = SolrServerContext("http://localhost:8983") + >>> client = AsyncSolrCloudClient(context) + >>> async def create_collection() -> None: ... await client.create_collection("collection_name", "config_name", 1, 1) """ @@ -676,10 +676,10 @@ class AsyncSolrCloudClient: :return: The list of collections on the Solr server. >>> from solrstice import SolrServerContext, AsyncSolrCloudClient - ... from typing import List - ... context = SolrServerContext("http://localhost:8983") - ... client = AsyncSolrCloudClient(context) - ... async def get_collections() -> List[str]: + >>> from typing import List + >>> context = SolrServerContext("http://localhost:8983") + >>> client = AsyncSolrCloudClient(context) + >>> async def get_collections() -> List[str]: ... return await client.get_collections() """ @@ -692,9 +692,9 @@ class AsyncSolrCloudClient: :return: True if the collection exists, False otherwise. >>> from solrstice import SolrServerContext, AsyncSolrCloudClient - ... context = SolrServerContext("http://localhost:8983") - ... client = AsyncSolrCloudClient(context) - ... async def collection_exists() -> bool: + >>> context = SolrServerContext("http://localhost:8983") + >>> client = AsyncSolrCloudClient(context) + >>> async def collection_exists() -> bool: ... return await client.collection_exists("collection_name") """ @@ -705,9 +705,9 @@ class AsyncSolrCloudClient: :param name: The name of the collection to delete. >>> from solrstice import SolrServerContext, AsyncSolrCloudClient - ... context = SolrServerContext("http://localhost:8983") - ... client = AsyncSolrCloudClient(context) - ... async def delete_collection() -> None: + >>> context = SolrServerContext("http://localhost:8983") + >>> client = AsyncSolrCloudClient(context) + >>> async def delete_collection() -> None: ... await client.delete_collection("collection_name") """ @@ -720,9 +720,9 @@ class AsyncSolrCloudClient: :param collections: The collections to alias >>> from solrstice import SolrServerContext, AsyncSolrCloudClient - ... context = SolrServerContext("http://localhost:8983") - ... client = AsyncSolrCloudClient(context) - ... async def create_alias() -> None: + >>> context = SolrServerContext("http://localhost:8983") + >>> client = AsyncSolrCloudClient(context) + >>> async def create_alias() -> None: ... await client.create_alias("alias_name", ["collection_name"]) """ @@ -734,10 +734,10 @@ class AsyncSolrCloudClient: :return: A dictionary of aliases to collections >>> from solrstice import SolrServerContext, AsyncSolrCloudClient - ... from typing import Dict, List - ... context = SolrServerContext("http://localhost:8983") - ... client = AsyncSolrCloudClient(context) - ... async def get_aliases() -> Dict[str, List[str]]: + >>> from typing import Dict, List + >>> context = SolrServerContext("http://localhost:8983") + >>> client = AsyncSolrCloudClient(context) + >>> async def get_aliases() -> Dict[str, List[str]]: ... return await client.get_aliases() """ @@ -750,9 +750,9 @@ class AsyncSolrCloudClient: :return: True if the alias exists, False otherwise >>> from solrstice import SolrServerContext, AsyncSolrCloudClient - ... context = SolrServerContext("http://localhost:8983") - ... client = AsyncSolrCloudClient(context) - ... async def alias_exists() -> bool: + >>> context = SolrServerContext("http://localhost:8983") + >>> client = AsyncSolrCloudClient(context) + >>> async def alias_exists() -> bool: ... return await client.alias_exists("alias_name") """ @@ -764,9 +764,9 @@ class AsyncSolrCloudClient: :param name: The name of the alias to delete >>> from solrstice import SolrServerContext, AsyncSolrCloudClient - ... context = SolrServerContext("http://localhost:8983") - ... client = AsyncSolrCloudClient(context) - ... async def delete_alias() -> None: + >>> context = SolrServerContext("http://localhost:8983") + >>> client = AsyncSolrCloudClient(context) + >>> async def delete_alias() -> None: ... await client.delete_alias("alias_name") """ @@ -781,10 +781,10 @@ class AsyncSolrCloudClient: :returns: The response from the query >>> from solrstice import SolrServerContext, AsyncSolrCloudClient, SelectQuery - ... from solrstice.models import SolrResponse - ... context = SolrServerContext("http://localhost:8983") - ... client = AsyncSolrCloudClient(context) - ... async def select() -> SolrResponse: + >>> from solrstice.models import SolrResponse + >>> context = SolrServerContext("http://localhost:8983") + >>> client = AsyncSolrCloudClient(context) + >>> async def select() -> SolrResponse: ... query = SelectQuery(q="*:*", rows=10) ... return await client.select(query, "collection_name") @@ -803,10 +803,10 @@ class AsyncSolrCloudClient: :returns: The response from the query >>> from solrstice import SolrServerContext, AsyncSolrCloudClient, UpdateQuery - ... from solrstice.models import SolrResponse - ... context = SolrServerContext("http://localhost:8983") - ... client = AsyncSolrCloudClient(context) - ... async def index() -> SolrResponse: + >>> from solrstice.models import SolrResponse + >>> context = SolrServerContext("http://localhost:8983") + >>> client = AsyncSolrCloudClient(context) + >>> async def index() -> SolrResponse: ... query = UpdateQuery() ... data_to_index = [{"id": "1", "name": "test"}] ... return await client.index(query, "collection_name", data_to_index) @@ -823,10 +823,10 @@ class AsyncSolrCloudClient: :returns: The response from the query >>> from solrstice import SolrServerContext, AsyncSolrCloudClient, DeleteQuery - ... from solrstice.models import SolrResponse - ... context = SolrServerContext("http://localhost:8983") - ... client = AsyncSolrCloudClient(context) - ... async def delete() -> SolrResponse: + >>> from solrstice.models import SolrResponse + >>> context = SolrServerContext("http://localhost:8983") + >>> client = AsyncSolrCloudClient(context) + >>> async def delete() -> SolrResponse: ... query = DeleteQuery(ids=["1"]) ... return await client.delete(query, "collection_name") @@ -839,8 +839,8 @@ class BlockingSolrCloudClient: :param context: The context of the Solr server. >>> from solrstice import SolrServerContext, SolrBasicAuth, BlockingSolrCloudClient - ... context = SolrServerContext("http://localhost:8983", SolrBasicAuth("user", "pass")) - ... client = BlockingSolrCloudClient(context) + >>> context = SolrServerContext("http://localhost:8983", SolrBasicAuth("user", "pass")) + >>> client = BlockingSolrCloudClient(context) """ @@ -856,9 +856,9 @@ class BlockingSolrCloudClient: :param config_path: Path to the config >>> from solrstice import SolrServerContext, BlockingSolrCloudClient - ... context = SolrServerContext("http://localhost:8983") - ... client = BlockingSolrCloudClient(context) - ... def upload_config() -> None: + >>> context = SolrServerContext("http://localhost:8983") + >>> client = BlockingSolrCloudClient(context) + >>> def upload_config() -> None: ... client.upload_config("config_name", "/path/to/config") """ @@ -869,10 +869,10 @@ class BlockingSolrCloudClient: :returns: A list of Solr configs >>> from solrstice import SolrServerContext, BlockingSolrCloudClient - ... from typing import List - ... context = SolrServerContext("http://localhost:8983") - ... client = BlockingSolrCloudClient(context) - ... def get_configs() -> List[str]: + >>> from typing import List + >>> context = SolrServerContext("http://localhost:8983") + >>> client = BlockingSolrCloudClient(context) + >>> def get_configs() -> List[str]: ... return client.get_configs() """ @@ -884,9 +884,9 @@ class BlockingSolrCloudClient: :returns: True if the config exists, False otherwise >>> from solrstice import SolrServerContext, BlockingSolrCloudClient - ... context = SolrServerContext("http://localhost:8983") - ... client = BlockingSolrCloudClient(context) - ... def config_exists() -> bool: + >>> context = SolrServerContext("http://localhost:8983") + >>> client = BlockingSolrCloudClient(context) + >>> def config_exists() -> bool: ... return client.config_exists("config_name") """ @@ -897,9 +897,9 @@ class BlockingSolrCloudClient: :param config_name: Name of the config >>> from solrstice import SolrServerContext, BlockingSolrCloudClient - ... context = SolrServerContext("http://localhost:8983") - ... client = BlockingSolrCloudClient(context) - ... def delete_config() -> None: + >>> context = SolrServerContext("http://localhost:8983") + >>> client = BlockingSolrCloudClient(context) + >>> def delete_config() -> None: ... client.delete_config("config_name") """ @@ -920,9 +920,9 @@ class BlockingSolrCloudClient: :param replication_factor: The replication factor to use. >>> from solrstice import SolrServerContext, BlockingSolrCloudClient - ... context = SolrServerContext("http://localhost:8983") - ... client = BlockingSolrCloudClient(context) - ... def create_collection() -> None: + >>> context = SolrServerContext("http://localhost:8983") + >>> client = BlockingSolrCloudClient(context) + >>> def create_collection() -> None: ... client.create_collection("collection_name", "config_name", 1, 1) """ @@ -934,10 +934,10 @@ class BlockingSolrCloudClient: :return: The list of collections on the Solr server. >>> from solrstice import SolrServerContext, BlockingSolrCloudClient - ... from typing import List - ... context = SolrServerContext("http://localhost:8983") - ... client = BlockingSolrCloudClient(context) - ... def get_collections() -> List[str]: + >>> from typing import List + >>> context = SolrServerContext("http://localhost:8983") + >>> client = BlockingSolrCloudClient(context) + >>> def get_collections() -> List[str]: ... return client.get_collections() """ @@ -950,9 +950,9 @@ class BlockingSolrCloudClient: :return: True if the collection exists, False otherwise. >>> from solrstice import SolrServerContext, BlockingSolrCloudClient - ... context = SolrServerContext("http://localhost:8983") - ... client = BlockingSolrCloudClient(context) - ... def collection_exists() -> bool: + >>> context = SolrServerContext("http://localhost:8983") + >>> client = BlockingSolrCloudClient(context) + >>> def collection_exists() -> bool: ... return client.collection_exists("collection_name") """ @@ -965,9 +965,10 @@ class BlockingSolrCloudClient: :param name: The name of the collection to delete. >>> from solrstice import SolrServerContext, BlockingSolrCloudClient - ... context = SolrServerContext("http://localhost:8983") - ... client = BlockingSolrCloudClient(context) - ... def delete_collection() -> None: + >>> context = SolrServerContext("http://localhost:8983") + >>> client = BlockingSolrCloudClient(context) + + >>> def delete_collection() -> None: ... client.delete_collection("collection_name") """ @@ -980,9 +981,9 @@ class BlockingSolrCloudClient: :param collections: The collections to alias >>> from solrstice import SolrServerContext, BlockingSolrCloudClient - ... context = SolrServerContext("http://localhost:8983") - ... client = BlockingSolrCloudClient(context) - ... def create_alias() -> None: + >>> context = SolrServerContext("http://localhost:8983") + >>> client = BlockingSolrCloudClient(context) + >>> def create_alias() -> None: ... client.create_alias("alias_name", ["collection_name"]) """ @@ -994,10 +995,10 @@ class BlockingSolrCloudClient: :return: A dictionary of aliases to collections >>> from solrstice import SolrServerContext, BlockingSolrCloudClient - ... from typing import Dict, List - ... context = SolrServerContext("http://localhost:8983") - ... client = BlockingSolrCloudClient(context) - ... def get_aliases() -> Dict[str, List[str]]: + >>> from typing import Dict, List + >>> context = SolrServerContext("http://localhost:8983") + >>> client = BlockingSolrCloudClient(context) + >>> def get_aliases() -> Dict[str, List[str]]: ... return client.get_aliases() """ @@ -1010,9 +1011,9 @@ class BlockingSolrCloudClient: :return: True if the alias exists, False otherwise >>> from solrstice import SolrServerContext, BlockingSolrCloudClient - ... context = SolrServerContext("http://localhost:8983") - ... client = BlockingSolrCloudClient(context) - ... def alias_exists() -> bool: + >>> context = SolrServerContext("http://localhost:8983") + >>> client = BlockingSolrCloudClient(context) + >>> def alias_exists() -> bool: ... return client.alias_exists("alias_name") """ @@ -1024,9 +1025,9 @@ class BlockingSolrCloudClient: :param name: The name of the alias to delete >>> from solrstice import SolrServerContext, BlockingSolrCloudClient - ... context = SolrServerContext("http://localhost:8983") - ... client = BlockingSolrCloudClient(context) - ... def delete_alias() -> None: + >>> context = SolrServerContext("http://localhost:8983") + >>> client = BlockingSolrCloudClient(context) + >>> def delete_alias() -> None: ... client.delete_alias("alias_name") """ @@ -1041,10 +1042,10 @@ class BlockingSolrCloudClient: :returns: The response from the query >>> from solrstice import SolrServerContext, BlockingSolrCloudClient, SelectQuery - ... from solrstice.models import SolrResponse - ... context = SolrServerContext("http://localhost:8983") - ... client = BlockingSolrCloudClient(context) - ... def select() -> SolrResponse: + >>> from solrstice.models import SolrResponse + >>> context = SolrServerContext("http://localhost:8983") + >>> client = BlockingSolrCloudClient(context) + >>> def select() -> SolrResponse: ... query = SelectQuery(q="*:*", rows=10) ... return client.select(query, "collection_name") @@ -1062,10 +1063,10 @@ class BlockingSolrCloudClient: :param data: The data to index >>> from solrstice import SolrServerContext, BlockingSolrCloudClient, UpdateQuery - ... from solrstice.models import SolrResponse - ... context = SolrServerContext("http://localhost:8983") - ... client = BlockingSolrCloudClient(context) - ... def index() -> SolrResponse: + >>> from solrstice.models import SolrResponse + >>> context = SolrServerContext("http://localhost:8983") + >>> client = BlockingSolrCloudClient(context) + >>> def index() -> SolrResponse: ... query = UpdateQuery() ... data_to_index = [{"id": "1", "name": "test"}] ... return client.index(query, "collection_name", data_to_index) @@ -1080,10 +1081,10 @@ class BlockingSolrCloudClient: :returns: The response from the query >>> from solrstice import SolrServerContext, BlockingSolrCloudClient, DeleteQuery - ... from solrstice.models import SolrResponse - ... context = SolrServerContext("http://localhost:8983") - ... client = BlockingSolrCloudClient(context) - ... def delete() -> SolrResponse: + >>> from solrstice.models import SolrResponse + >>> context = SolrServerContext("http://localhost:8983") + >>> client = BlockingSolrCloudClient(context) + >>> def delete() -> SolrResponse: ... query = DeleteQuery(ids=["1"]) ... return client.delete(query, "collection_name") diff --git a/wrappers/python/tests/test_doctest.py b/wrappers/python/tests/test_doctest.py index 2941a0b..d93f15e 100644 --- a/wrappers/python/tests/test_doctest.py +++ b/wrappers/python/tests/test_doctest.py @@ -2,7 +2,7 @@ import tempfile from pathlib import Path from sys import stderr -from typing import List, Dict +from typing import List, Dict, Optional import solrstice import doctest @@ -18,7 +18,7 @@ def find_mypy_config() -> Path: def get_doctests_from_solrstice() -> Dict[str, List[doctest.Example]]: to_parse = [Path(solrstice.__path__[0])] # type: ignore doctest_parser = doctest.DocTestParser() - doctest_examples = {} + doctest_examples: Dict[str, List[doctest.Example]] = {} while to_parse: path = Path(to_parse.pop()) for file in path.iterdir(): @@ -28,6 +28,24 @@ def get_doctests_from_solrstice() -> Dict[str, List[doctest.Example]]: with open(file) as f: doctests = doctest_parser.get_doctest(f.read(), {}, str(file), str(file), 0) doctest_examples[file.name] = doctests.examples + + # Merge examples that are from the same code block + for examples in doctest_examples.values(): + if examples: + finished_examples = [] + current_example: doctest.Example = examples[0] + current_lineno: int = current_example.lineno + for example in examples[1:]: + # Allow for a single whitespace between code blocks + if example.lineno < current_lineno + 3: + current_example.source += example.source + current_lineno = example.lineno + else: + finished_examples.append(current_example) + current_example = example + current_lineno = example.lineno + examples.clear() + examples.extend(finished_examples) return doctest_examples