Skip to content

Commit

Permalink
[issue_586] add tests for cli usage
Browse files Browse the repository at this point in the history
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
  • Loading branch information
meretp committed Apr 17, 2023
1 parent aeb7f23 commit 34e945f
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/spdx/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
from typing import Tuple

import pytest
from click.testing import CliRunner

from spdx.clitools.pyspdxtools import main


@pytest.mark.parametrize(
"options",
[
("--infile", os.path.join(os.path.dirname(__file__), "data/SPDXJSONExample-v2.3.spdx.json")),
("-i", os.path.join(os.path.dirname(__file__), "data/SPDXJSONExample-v2.3.spdx.json"), "--novalidation"),
(
"-i",
os.path.join(os.path.dirname(__file__), "data/SPDXJSONExample-v2.3.spdx.json"),
"--novalidation",
"--version",
"SPDX-2.3",
),
("-i", os.path.join(os.path.dirname(__file__), "data/SPDXJSONExample-v2.3.spdx.json"), "-o", "-"),
],
)
def test_cli(options: Tuple[str, str]):
runner = CliRunner()

result = runner.invoke(main, options)

assert result.exit_code == 0


@pytest.mark.parametrize(
"options",
[
(),
("-i", os.path.join(os.path.dirname(__file__), "data/SPDXJSONExample-v2.3.spdx.json"), "--version"),
("-i", os.path.join(os.path.dirname(__file__), "data/SPDXJSONExample-v2.3.spdx.json"), "-o"),
],
)
def test_cli_with_system_exit(options):
runner = CliRunner()

result = runner.invoke(main, options)

assert result.exit_code == 2

0 comments on commit 34e945f

Please sign in to comment.