Skip to content

Commit 156f2b8

Browse files
committed
test(version-scanner): parametrize targets file failure tests
1 parent d26715a commit 156f2b8

1 file changed

Lines changed: 19 additions & 29 deletions

File tree

scripts/version_scanner/tests/unit/test_version_scanner.py

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -795,37 +795,27 @@ def test_parse_targets_file(tmp_path):
795795
targets = parse_targets_file(str(yaml_file))
796796
assert targets == [("python", "3.7"), ("python", "3.8"), ("protobuf", "4.25.8")]
797797

798-
def test_parse_targets_file_not_found():
799-
from version_scanner import parse_targets_file
800-
with pytest.raises(SystemExit) as excinfo:
801-
parse_targets_file("nonexistent_file.yaml")
802-
assert excinfo.value.code == 1
803-
804-
def test_parse_targets_file_invalid_yaml(tmp_path):
805-
from version_scanner import parse_targets_file
806-
yaml_file = tmp_path / "targets.yaml"
807-
yaml_file.write_text("invalid: {")
808-
with pytest.raises(SystemExit) as excinfo:
809-
parse_targets_file(str(yaml_file))
810-
assert excinfo.value.code == 1
811-
812-
def test_parse_targets_file_invalid_structure(tmp_path):
813-
from version_scanner import parse_targets_file
814-
yaml_file = tmp_path / "targets.yaml"
815-
yaml_file.write_text("- not_a_mapping")
816-
with pytest.raises(SystemExit) as excinfo:
817-
parse_targets_file(str(yaml_file))
818-
assert excinfo.value.code == 1
819-
820-
def test_parse_targets_file_invalid_version_type(tmp_path):
798+
@pytest.mark.parametrize(
799+
"file_content, file_exists",
800+
[
801+
(None, False), # File not found
802+
("invalid: {", True), # Invalid YAML
803+
("- not_a_mapping", True), # Invalid structure (list instead of map)
804+
("python:\n - null", True), # Invalid version type (null/None value)
805+
]
806+
)
807+
def test_parse_targets_file_failures(tmp_path, file_content, file_exists):
821808
from version_scanner import parse_targets_file
822-
yaml_file = tmp_path / "targets.yaml"
823-
yaml_file.write_text("""
824-
python:
825-
- null
826-
""")
809+
810+
if file_exists:
811+
yaml_file = tmp_path / "targets_failures.yaml"
812+
yaml_file.write_text(file_content)
813+
path = str(yaml_file)
814+
else:
815+
path = "nonexistent_file.yaml"
816+
827817
with pytest.raises(SystemExit) as excinfo:
828-
parse_targets_file(str(yaml_file))
818+
parse_targets_file(path)
829819
assert excinfo.value.code == 1
830820

831821
def test_scan_repository_multi_targets(tmp_path):

0 commit comments

Comments
 (0)