aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Harder <radhermit@gmail.com>2021-03-04 00:00:25 -0700
committerTim Harder <radhermit@gmail.com>2021-03-04 00:29:33 -0700
commit1d3dda7932900725c3174974e78b3bc10c5088b5 (patch)
treeed0c564b6e558c044f56bdf95a59178e76e71537 /tests/scripts/test_pkgcheck_ci.py
parentvarious tox and github workflow updates from pkgdev (diff)
downloadpkgcheck-1d3dda7932900725c3174974e78b3bc10c5088b5.tar.gz
pkgcheck-1d3dda7932900725c3174974e78b3bc10c5088b5.tar.bz2
pkgcheck-1d3dda7932900725c3174974e78b3bc10c5088b5.zip
move test data to a separate repo root dir
To make pytest happier when running on it's own since it prefers tests in a root-level dir.
Diffstat (limited to 'tests/scripts/test_pkgcheck_ci.py')
-rw-r--r--tests/scripts/test_pkgcheck_ci.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/scripts/test_pkgcheck_ci.py b/tests/scripts/test_pkgcheck_ci.py
new file mode 100644
index 00000000..2ac21d7c
--- /dev/null
+++ b/tests/scripts/test_pkgcheck_ci.py
@@ -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)]