Skip to content

Commit 4fcaebd

Browse files
committed
Detect mismatched generated tests and requested tests
1 parent 0ada777 commit 4fcaebd

3 files changed

Lines changed: 70 additions & 2 deletions

File tree

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
44

55
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
66

7-
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "nbsapi_verify"
3-
version = "0.1.5"
3+
version = "0.1.6"
44
description = "Verify an nbsinfra API implementation"
55
readme = "README.md"
66
license = {text = "MIT License"}
@@ -12,6 +12,9 @@ dependencies = [
1212
authors = [
1313
{ name = "Stephan Hügel", email = "urschrei@gmail.com" },
1414
]
15+
maintainers = [
16+
{ name = "Hrishi Ballal", email = "hrishi@geodesignhub.com" },
17+
]
1518
keywords = ["nbsinfra", "nbsapi"]
1619

1720
[project.urls]

src/nbsapi_verify/cli.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,23 @@ def cli(
148148
err=True,
149149
)
150150
sys.exit(1)
151+
152+
# Load config to check available test types
153+
with open(config_path) as f:
154+
config = yaml.safe_load(f)
155+
156+
# Check for test type mismatch
157+
has_auth_config = "username" in config.get("variables", {}) and "password" in config.get("variables", {})
158+
159+
# Detect test type mismatch
160+
if test_type in (TestType.AUTH, TestType.ALL) and not has_auth_config:
161+
click.echo(
162+
f"Error: Test type '{test_type}' requested but auth configuration is missing.\n"
163+
"Auth tests require 'username' and 'password' in the configuration.\n"
164+
"Please regenerate the configuration with --username and --password parameters.",
165+
err=True,
166+
)
167+
sys.exit(1)
151168

152169
# Get the package's test directory
153170
package_dir = Path(__file__).parent
@@ -157,6 +174,54 @@ def cli(
157174
click.echo(f"Error: Test directory not found at {test_dir}", err=True)
158175
sys.exit(1)
159176

177+
# Verify that requested test types have matching test files
178+
import glob
179+
180+
# Get all test files and check for their markers
181+
test_files = glob.glob(str(test_dir / "*.tavern.yaml"))
182+
183+
# Check if there are any test files with requested markers
184+
has_auth_tests = False
185+
has_public_tests = False
186+
187+
for test_file in test_files:
188+
with open(test_file) as f:
189+
content = f.read()
190+
if "marks:\n- auth" in content:
191+
has_auth_tests = True
192+
if "marks:\n- public" in content:
193+
has_public_tests = True
194+
195+
# Verify requested test type has matching test files
196+
if test_type == TestType.AUTH and not has_auth_tests:
197+
click.echo(
198+
f"Error: Test type '{test_type}' requested but no auth test files found.\n"
199+
"Make sure auth test files are generated and properly marked.",
200+
err=True,
201+
)
202+
sys.exit(1)
203+
204+
if test_type == TestType.PUBLIC and not has_public_tests:
205+
click.echo(
206+
f"Error: Test type '{test_type}' requested but no public test files found.\n"
207+
"Make sure public test files are generated and properly marked.",
208+
err=True,
209+
)
210+
sys.exit(1)
211+
212+
if test_type == TestType.ALL and not (has_auth_tests and has_public_tests):
213+
missing = []
214+
if not has_auth_tests:
215+
missing.append("auth")
216+
if not has_public_tests:
217+
missing.append("public")
218+
click.echo(
219+
f"Error: Test type '{test_type}' requested but some test types are missing: {', '.join(missing)}.\n"
220+
"Make sure all test types are generated before running 'all' tests.",
221+
err=True,
222+
)
223+
sys.exit(1)
224+
160225
# Prepare pytest arguments
161226
pytest_args = [
162227
str(test_dir),

0 commit comments

Comments
 (0)