Skip to content

Commit d01af72

Browse files
fholgerarmintaenzertng
authored andcommitted
Add tests for the examples to ensure they are working in principle
Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
1 parent 02bb169 commit d01af72

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

examples/spdx2_convert_to_spdx3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
# Convert original document to an SPDX3 payload
1919
spdx3_payload = bump_spdx_document(spdx2_document)
2020
# Write SPDX3 payload in json-ld format
21-
write_payload(spdx3_payload, "spdx2_to_3.json")
21+
write_payload(spdx3_payload, "spdx2_to_3")
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SPDX-FileCopyrightText: 2023 spdx contributors
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
import os.path
5+
import runpy
6+
7+
import pytest
8+
9+
10+
@pytest.fixture
11+
def cleanup_output_files():
12+
yield
13+
14+
files_to_delete = ["spdx2_to_3.jsonld", "my_spdx_document.spdx.json"]
15+
for file in files_to_delete:
16+
output_file = os.path.join(os.path.dirname(__file__), file)
17+
if os.path.exists(output_file):
18+
os.remove(output_file)
19+
20+
21+
def run_example(example_file: str):
22+
file_path = os.path.join(os.path.dirname(__file__), "../../../examples/", example_file)
23+
runpy.run_path(file_path)
24+
25+
26+
def test_spdx2_parse_file():
27+
run_example("spdx2_parse_file.py")
28+
29+
30+
@pytest.mark.usefixtures('cleanup_output_files')
31+
def test_spdx2_convert_to_spdx3():
32+
run_example("spdx2_convert_to_spdx3.py")
33+
34+
output_file = os.path.join(os.path.dirname(__file__), "spdx2_to_3.jsonld")
35+
assert os.path.exists(output_file)
36+
37+
38+
@pytest.mark.usefixtures('cleanup_output_files')
39+
def test_spdx2_document_from_scratch():
40+
run_example("spdx2_document_from_scratch.py")
41+
42+
output_file = os.path.join(os.path.dirname(__file__), "my_spdx_document.spdx.json")
43+
assert os.path.exists(output_file)

0 commit comments

Comments
 (0)