nvidia-nat-test 1.3.0a20250826__py3-none-any.whl → 1.3.0a20250827__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nat/test/plugin.py +100 -0
- nat/test/test_env_fixtures.py +60 -0
- {nvidia_nat_test-1.3.0a20250826.dist-info → nvidia_nat_test-1.3.0a20250827.dist-info}/METADATA +2 -2
- {nvidia_nat_test-1.3.0a20250826.dist-info → nvidia_nat_test-1.3.0a20250827.dist-info}/RECORD +7 -6
- {nvidia_nat_test-1.3.0a20250826.dist-info → nvidia_nat_test-1.3.0a20250827.dist-info}/WHEEL +0 -0
- {nvidia_nat_test-1.3.0a20250826.dist-info → nvidia_nat_test-1.3.0a20250827.dist-info}/entry_points.txt +0 -0
- {nvidia_nat_test-1.3.0a20250826.dist-info → nvidia_nat_test-1.3.0a20250827.dist-info}/top_level.txt +0 -0
nat/test/plugin.py
CHANGED
@@ -13,6 +13,8 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
|
+
import os
|
17
|
+
|
16
18
|
import pytest
|
17
19
|
|
18
20
|
|
@@ -42,6 +44,14 @@ def pytest_addoption(parser: pytest.Parser):
|
|
42
44
|
help="Run end to end tests that would otherwise be skipped",
|
43
45
|
)
|
44
46
|
|
47
|
+
parser.addoption(
|
48
|
+
"--fail_missing",
|
49
|
+
action="store_true",
|
50
|
+
dest="fail_missing",
|
51
|
+
help=("Tests requiring unmet dependencies are normally skipped. "
|
52
|
+
"Setting this flag will instead cause them to be reported as a failure"),
|
53
|
+
)
|
54
|
+
|
45
55
|
|
46
56
|
def pytest_runtest_setup(item):
|
47
57
|
if (not item.config.getoption("--run_e2e")):
|
@@ -94,3 +104,93 @@ def function_registry_fixture():
|
|
94
104
|
|
95
105
|
with GlobalTypeRegistry.push() as registry:
|
96
106
|
yield registry
|
107
|
+
|
108
|
+
|
109
|
+
@pytest.fixture(scope="session", name="fail_missing")
|
110
|
+
def fail_missing_fixture(pytestconfig: pytest.Config) -> bool:
|
111
|
+
"""
|
112
|
+
Returns the value of the `fail_missing` flag, when false tests requiring unmet dependencies will be skipped, when
|
113
|
+
True they will fail.
|
114
|
+
"""
|
115
|
+
yield pytestconfig.getoption("fail_missing")
|
116
|
+
|
117
|
+
|
118
|
+
def require_env_variables(varnames: list[str], reason: str, fail_missing: bool = False) -> dict[str, str]:
|
119
|
+
"""
|
120
|
+
Checks if the given environment variable is set, and returns its value if it is. If the variable is not set, and
|
121
|
+
`fail_missing` is False the test will ve skipped, otherwise a `RuntimeError` will be raised.
|
122
|
+
"""
|
123
|
+
env_variables = {}
|
124
|
+
try:
|
125
|
+
for varname in varnames:
|
126
|
+
env_variables[varname] = os.environ[varname]
|
127
|
+
except KeyError as e:
|
128
|
+
if fail_missing:
|
129
|
+
raise RuntimeError(reason) from e
|
130
|
+
|
131
|
+
pytest.skip(reason=reason)
|
132
|
+
|
133
|
+
return env_variables
|
134
|
+
|
135
|
+
|
136
|
+
@pytest.fixture(name="openai_api_key", scope='session')
|
137
|
+
def openai_api_key_fixture(fail_missing: bool):
|
138
|
+
"""
|
139
|
+
Use for integration tests that require an Openai API key.
|
140
|
+
"""
|
141
|
+
yield require_env_variables(
|
142
|
+
varnames=["OPENAI_API_KEY"],
|
143
|
+
reason="openai integration tests require the `OPENAI_API_KEY` environment variable to be defined.",
|
144
|
+
fail_missing=fail_missing)
|
145
|
+
|
146
|
+
|
147
|
+
@pytest.fixture(name="nvidia_api_key", scope='session')
|
148
|
+
def nvidia_api_key_fixture(fail_missing: bool):
|
149
|
+
"""
|
150
|
+
Use for integration tests that require an Nvidia API key.
|
151
|
+
"""
|
152
|
+
yield require_env_variables(
|
153
|
+
varnames=["NVIDIA_API_KEY"],
|
154
|
+
reason="Nvidia integration tests require the `NVIDIA_API_KEY` environment variable to be defined.",
|
155
|
+
fail_missing=fail_missing)
|
156
|
+
|
157
|
+
|
158
|
+
@pytest.fixture(name="aws_keys", scope='session')
|
159
|
+
def aws_keys_fixture(fail_missing: bool):
|
160
|
+
"""
|
161
|
+
Use for integration tests that require AWS credentials.
|
162
|
+
"""
|
163
|
+
|
164
|
+
yield require_env_variables(
|
165
|
+
varnames=["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"],
|
166
|
+
reason=
|
167
|
+
"AWS integration tests require the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables to be "
|
168
|
+
"defined.",
|
169
|
+
fail_missing=fail_missing)
|
170
|
+
|
171
|
+
|
172
|
+
@pytest.fixture(name="azure_openai_keys", scope='session')
|
173
|
+
def azure_openai_keys_fixture(fail_missing: bool):
|
174
|
+
"""
|
175
|
+
Use for integration tests that require Azure OpenAI credentials.
|
176
|
+
"""
|
177
|
+
yield require_env_variables(
|
178
|
+
varnames=["AZURE_OPENAI_API_KEY", "AZURE_OPENAI_ENDPOINT"],
|
179
|
+
reason="Azure integration tests require the `AZURE_OPENAI_API_KEY` and `AZURE_OPENAI_ENDPOINT` environment "
|
180
|
+
"variable to be defined.",
|
181
|
+
fail_missing=fail_missing)
|
182
|
+
|
183
|
+
|
184
|
+
@pytest.fixture(name="restore_environ")
|
185
|
+
def restore_environ_fixture():
|
186
|
+
orig_vars = os.environ.copy()
|
187
|
+
yield os.environ
|
188
|
+
|
189
|
+
for key, value in orig_vars.items():
|
190
|
+
os.environ[key] = value
|
191
|
+
|
192
|
+
# Delete any new environment variables
|
193
|
+
# Iterating over a copy of the keys as we will potentially be deleting keys in the loop
|
194
|
+
for key in list(os.environ.keys()):
|
195
|
+
if key not in orig_vars:
|
196
|
+
del (os.environ[key])
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
"""
|
16
|
+
Comprehensive tests for environment variable handling and API key fixtures.
|
17
|
+
"""
|
18
|
+
|
19
|
+
import os
|
20
|
+
|
21
|
+
import pytest
|
22
|
+
|
23
|
+
from nat.test.plugin import require_env_variables
|
24
|
+
|
25
|
+
|
26
|
+
@pytest.mark.usefixtures("restore_environ")
|
27
|
+
@pytest.mark.parametrize("fail_on_missing", [True, False])
|
28
|
+
@pytest.mark.parametrize("env_vars",
|
29
|
+
[{
|
30
|
+
"SOME_KEY": "xyz"
|
31
|
+
}, {
|
32
|
+
"SOME_KEY": "xyz", "OTHER_KEY": "abc"
|
33
|
+
}, {
|
34
|
+
"SOME_KEY": "xyz", "OTHER_KEY": "abc", "MISSING_KEY": None
|
35
|
+
}, {
|
36
|
+
"SOME_KEY": "xyz", "OTHER_KEY": "abc", "MISSING_KEY": None, "EMPTY_KEY": None
|
37
|
+
}])
|
38
|
+
def test_require_env_variables(fail_on_missing: bool, env_vars: dict[str, str | None]):
|
39
|
+
# Note the variable name `fail_on_missing` is used to avoid conflict with the `fail_missing` fixture
|
40
|
+
has_missing = False
|
41
|
+
var_names = []
|
42
|
+
for (env_var, value) in env_vars.items():
|
43
|
+
var_names.append(env_var)
|
44
|
+
if value is not None:
|
45
|
+
os.environ[env_var] = value
|
46
|
+
else:
|
47
|
+
has_missing = True
|
48
|
+
os.environ.pop(env_var, None)
|
49
|
+
|
50
|
+
if has_missing:
|
51
|
+
if fail_on_missing:
|
52
|
+
expected_exception = RuntimeError
|
53
|
+
else:
|
54
|
+
expected_exception = pytest.skip.Exception
|
55
|
+
|
56
|
+
with pytest.raises(expected_exception, match="unittest"):
|
57
|
+
require_env_variables(varnames=var_names, reason="unittest", fail_missing=fail_on_missing)
|
58
|
+
|
59
|
+
else:
|
60
|
+
assert require_env_variables(varnames=var_names, reason="unittest", fail_missing=fail_on_missing) == env_vars
|
{nvidia_nat_test-1.3.0a20250826.dist-info → nvidia_nat_test-1.3.0a20250827.dist-info}/METADATA
RENAMED
@@ -1,12 +1,12 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: nvidia-nat-test
|
3
|
-
Version: 1.3.
|
3
|
+
Version: 1.3.0a20250827
|
4
4
|
Summary: Testing utilities for NeMo Agent toolkit
|
5
5
|
Keywords: ai,rag,agents
|
6
6
|
Classifier: Programming Language :: Python
|
7
7
|
Requires-Python: <3.13,>=3.11
|
8
8
|
Description-Content-Type: text/markdown
|
9
|
-
Requires-Dist: nvidia-nat==v1.3.
|
9
|
+
Requires-Dist: nvidia-nat==v1.3.0a20250827
|
10
10
|
Requires-Dist: langchain-community~=0.3
|
11
11
|
Requires-Dist: pytest~=8.3
|
12
12
|
|
{nvidia_nat_test-1.3.0a20250826.dist-info → nvidia_nat_test-1.3.0a20250827.dist-info}/RECORD
RENAMED
@@ -4,11 +4,12 @@ nat/test/embedder.py,sha256=ClDyK1kna4hCBSlz71gK1B-ZjlwcBHTDQRekoNM81Bs,1809
|
|
4
4
|
nat/test/functions.py,sha256=0ScrdsjcxCsPRLnyb5gfwukmvZxFi_ptCswLSIG0DVY,3095
|
5
5
|
nat/test/memory.py,sha256=xki_A2yiMhEZuQk60K7t04QRqf32nQqnfzD5Iv7fkvw,1456
|
6
6
|
nat/test/object_store_tests.py,sha256=PyJioOtoSzILPq6LuD-sOZ_89PIcgXWZweoHBQpK2zQ,4281
|
7
|
-
nat/test/plugin.py,sha256=
|
7
|
+
nat/test/plugin.py,sha256=sMZ7xupCgEpQCuwUksUDYMjbBj0VNlhR6SK5UcOrBzg,6953
|
8
8
|
nat/test/register.py,sha256=fbCLr3E4u8PYMFUlkRNlg53Td2YJ80iQCyxpRIbGId4,859
|
9
|
+
nat/test/test_env_fixtures.py,sha256=zGhFBiZmdDYuj8kOU__RL9LOrood3L58KG8OWXnyOjQ,2375
|
9
10
|
nat/test/tool_test_runner.py,sha256=EP5Zo_YmfCOeeifzSv1ztx6xF-E-GVGYktN5hkZIBSc,17405
|
10
|
-
nvidia_nat_test-1.3.
|
11
|
-
nvidia_nat_test-1.3.
|
12
|
-
nvidia_nat_test-1.3.
|
13
|
-
nvidia_nat_test-1.3.
|
14
|
-
nvidia_nat_test-1.3.
|
11
|
+
nvidia_nat_test-1.3.0a20250827.dist-info/METADATA,sha256=dhwJgvCZzsH9kqhCygerDpW-9i1cxO3GfbZzR_8uxnA,1466
|
12
|
+
nvidia_nat_test-1.3.0a20250827.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
13
|
+
nvidia_nat_test-1.3.0a20250827.dist-info/entry_points.txt,sha256=7dOP9XB6iMDqvav3gYx9VWUwA8RrFzhbAa8nGeC8e4Y,99
|
14
|
+
nvidia_nat_test-1.3.0a20250827.dist-info/top_level.txt,sha256=8-CJ2cP6-f0ZReXe5Hzqp-5pvzzHz-5Ds5H2bGqh1-U,4
|
15
|
+
nvidia_nat_test-1.3.0a20250827.dist-info/RECORD,,
|
File without changes
|
File without changes
|
{nvidia_nat_test-1.3.0a20250826.dist-info → nvidia_nat_test-1.3.0a20250827.dist-info}/top_level.txt
RENAMED
File without changes
|