Skip to content

Commit 44fe4e8

Browse files
authored
fix docs tests gateway endpoint (#475)
* fix docs tests gateway endpoint * update comments * delete docs endpoints after test
1 parent cddb597 commit 44fe4e8

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

integration_tests/test_docs.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@
99
import pytest
1010
from _pytest.assertion.rewrite import AssertionRewritingHook
1111

12+
from .rest_api_utils import (
13+
BASE_PATH,
14+
SERVICE_IDENTIFIER,
15+
delete_existing_endpoints,
16+
ensure_gateway_ready,
17+
)
18+
1219
ROOT_DIR = Path(__file__).parent.parent
1320

1421
TEST_SKIP_MAGIC_STRING = "# test='skip'"
15-
SERVICE_IDENTIFIER = os.environ.get("SERVICE_IDENTIFIER", "")
1622

1723

1824
@pytest.fixture
@@ -56,11 +62,17 @@ def integration_test_user_id() -> str:
5662

5763

5864
def modify_source(source: str) -> str:
59-
# Adds some custom logic to update code from docs to comply with some requirements.
60-
source = re.sub(r"('team'|\"team\"): ('\w+'|\"\w+\")", r"'team': 'infra'", source)
65+
"""Modify the source code from docs to be compatible with the integration tests."""
66+
67+
# Ensure the correct base path is used
6168
source = re.sub(
62-
r"('product'|\"product\"): ('\w+'|\"\w+\")",
63-
r"'product': 'launch-integration-test'",
69+
r"get_launch_client\((.*)\)\n",
70+
rf'get_launch_client(\g<1>, gateway_endpoint="{BASE_PATH}")\n',
71+
source,
72+
)
73+
source = re.sub(
74+
r"LaunchClient\((.*)\)\n",
75+
rf'LaunchClient(\g<1>, endpoint="{BASE_PATH}")\n',
6476
source,
6577
)
6678

@@ -81,6 +93,15 @@ def modify_source(source: str) -> str:
8193
source,
8294
)
8395

96+
# Set particular tag values for cost tracking
97+
source = re.sub(r"('team'|\"team\"): ('\w+'|\"\w+\")", r"'team': 'infra'", source)
98+
source = re.sub(
99+
r"('product'|\"product\"): ('\w+'|\"\w+\")",
100+
r"'product': 'launch-integration-test'",
101+
source,
102+
)
103+
104+
# Fill in empty values in docs
84105
source = re.sub(r'"repository": "..."', '"repository": "launch_rearch"', source)
85106
source = re.sub(
86107
r'"tag": "..."', '"tag": "11d9d42047cc9a0c6435b19e5e91bc7e0ad31efc-cpu"', source
@@ -203,7 +224,11 @@ def test_docs_examples(
203224

204225
env("LAUNCH_API_KEY", os.getenv("LAUNCH_TEST_API_KEY", integration_test_user_id))
205226

227+
ensure_gateway_ready()
228+
206229
try:
207230
import_execute(module_name, source_code, True)
208231
except Exception:
209232
raise
233+
finally:
234+
delete_existing_endpoints()

0 commit comments

Comments
 (0)