Skip to content

Commit

Permalink
Restructure pySigma check
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaspatzke committed Jan 29, 2024
1 parent d8b71b2 commit 7e31389
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 2 additions & 3 deletions sigma/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import requests
from packaging.version import Version

from sigma.cli.pysigma import check_pysigma

try:
import sigma.parser.base

Expand Down Expand Up @@ -36,6 +34,7 @@
from .check import check
from .plugin import plugin_group
from .analyze import analyze_group
from .pysigma import check_pysigma_command


@click.group()
Expand Down Expand Up @@ -72,7 +71,7 @@ def main():
cli.add_command(list_group)
cli.add_command(convert)
cli.add_command(check)
cli.add_command(check_pysigma)
cli.add_command(check_pysigma_command)
cli.add_command(version)
cli()

Expand Down
3 changes: 3 additions & 0 deletions sigma/cli/pysigma.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def check_pysigma_version():
default=False,
help="Suppress output if check passes.",
)
def check_pysigma_command(quiet):
check_pysigma(quiet)

def check_pysigma(quiet=False):
"""Check the version of pySigma against the required version of sigma-cli and reinstall on user prompt if
necessary."""
Expand Down
6 changes: 3 additions & 3 deletions tests/test_pysigma.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sigma.cli.pysigma import check_pysigma, check_pysigma_version
from sigma.cli.pysigma import check_pysigma_command, check_pysigma_version
from click.testing import CliRunner
import pytest

Expand All @@ -20,12 +20,12 @@ def test_check_pysigma_version_incompatible(monkeypatch, pysigma_expected_versio

def test_check_pysigma():
cli = CliRunner()
result = cli.invoke(check_pysigma)
result = cli.invoke(check_pysigma_command)
assert "pySigma version is compatible with sigma-cli" in result.output

def test_check_pysigma_incompatible(monkeypatch):
monkeypatch.setattr('importlib.metadata.version', lambda x: "0.0.1")
cli = CliRunner()
result = cli.invoke(check_pysigma, input="y\n")
result = cli.invoke(check_pysigma_command, input="y\n")
assert "pySigma version is not compatible" in result.output
assert "pySigma successfully reinstalled" in result.output

0 comments on commit 7e31389

Please sign in to comment.