-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add initial
pkgcheck ci
tests
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from functools import partial | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from pkgcheck.checks.metadata import InvalidSlot | ||
from pkgcheck.reporters import JsonStream | ||
from pkgcheck.scripts import run | ||
from pkgcore.ebuild.cpv import VersionedCPV | ||
|
||
|
||
class TestPkgcheckCi: | ||
|
||
script = partial(run, 'pkgcheck') | ||
|
||
@pytest.fixture(autouse=True) | ||
def _setup(self, testconfig, tmp_path): | ||
self.cache_dir = str(tmp_path) | ||
base_args = ['--config', testconfig] | ||
self.scan_args = ['--config', 'no', '--cache-dir', self.cache_dir] | ||
# args for running pkgcheck like a script | ||
self.args = ['pkgcheck'] + base_args + ['ci'] + self.scan_args | ||
|
||
def test_empty_repo(self, capsys, repo): | ||
with patch('sys.argv', self.args + [repo.location]): | ||
with pytest.raises(SystemExit) as excinfo: | ||
self.script() | ||
assert excinfo.value.code == 0 | ||
out, err = capsys.readouterr() | ||
assert out == err == '' | ||
|
||
def test_exit_status(self, repo): | ||
# create good ebuild and another with an invalid EAPI | ||
repo.create_ebuild('cat/pkg-0') | ||
repo.create_ebuild('cat/pkg-1', eapi='-1') | ||
# exit status isn't enabled by default | ||
args = ['-r', repo.location] | ||
with patch('sys.argv', self.args + args): | ||
with pytest.raises(SystemExit) as excinfo: | ||
self.script() | ||
assert excinfo.value.code == 0 | ||
|
||
# all error level results are flagged by default when enabled | ||
with patch('sys.argv', self.args + args + ['--exit']): | ||
with pytest.raises(SystemExit) as excinfo: | ||
self.script() | ||
assert excinfo.value.code == 1 | ||
|
||
# selective error results will only flag those specified | ||
with patch('sys.argv', self.args + args + ['--exit', 'InvalidSlot']): | ||
with pytest.raises(SystemExit) as excinfo: | ||
self.script() | ||
assert excinfo.value.code == 0 | ||
with patch('sys.argv', self.args + args + ['--exit', 'InvalidEapi']): | ||
with pytest.raises(SystemExit) as excinfo: | ||
self.script() | ||
assert excinfo.value.code == 1 | ||
|
||
def test_failures(self, tmp_path, repo): | ||
repo.create_ebuild('cat/pkg-1', slot='') | ||
failures = str(tmp_path / 'failures.json') | ||
args = ['--failures', failures, '--exit', '-r', repo.location] | ||
with patch('sys.argv', self.args + args): | ||
with pytest.raises(SystemExit) as excinfo: | ||
self.script() | ||
assert excinfo.value.code == 1 | ||
|
||
with open(str(failures)) as f: | ||
results = list(JsonStream.from_iter(f)) | ||
pkg = VersionedCPV('cat/pkg-1') | ||
assert results == [InvalidSlot('slot', 'SLOT cannot be unset or empty', pkg=pkg)] |