test: convert to pytest test_noop.py

Split the tests and add verification for access to mount when necessary.
This commit is contained in:
Thomas Lavocat 2021-08-10 15:18:20 +02:00 committed by Thomas Lavocat
parent 78bc042bae
commit 1b145701f4

View file

@ -1,62 +1,65 @@
#
# Runtime Tests for No-op Pipelines
#
import json
import unittest
import tempfile
import pytest
from .. import test
NOOP_V2 = {
"version": "2",
"pipelines": [
{
"name": "noop",
"stages": [
{
"type": "org.osbuild.noop",
"options": {"zero": 0},
"inputs": {
"tree": {
"type": "org.osbuild.noop",
"origin": "org.osbuild.pipeline",
"references": {
"foo": {}
@pytest.fixture(name="jsondata", scope="module")
def jsondata_fixture():
return json.dumps({
"version": "2",
"pipelines": [
{
"name": "noop",
"stages": [
{
"type": "org.osbuild.noop",
"options": {"zero": 0},
"inputs": {
"tree": {
"type": "org.osbuild.noop",
"origin": "org.osbuild.pipeline",
"references": {
"foo": {}
}
}
}
}
}
]
}
]
}
]
}
]
})
@pytest.fixture(name="tmpdir", scope="module")
def tmpdir_fixture():
with tempfile.TemporaryDirectory() as tmp:
yield tmp
class TestNoop(unittest.TestCase):
def setUp(self):
self.osbuild = test.OSBuild()
@pytest.fixture(name="osb", scope="module")
def osbuild_fixture():
with test.OSBuild() as osb:
yield osb
def test_noop(self):
#
# Run a noop Pipeline. Run twice to verify the cache does not affect
# the operation (we do not have checkpoints, nor any stages that could
# be checkpointed).
#
# Then run the entire thing again, to verify our own `osbuild` executor
# tears things down properly and allows to be executed multiple times.
#
#
# Run a noop Pipeline. Run twice to verify the cache does not affect
# the operation (we do not have checkpoints, nor any stages that could
# be checkpointed).
#
# Then run the entire thing again, to verify our own `osbuild` executor
# tears things down properly and allows to be executed multiple times.
#
def test_noop(osb):
osb.compile("{}")
osb.compile("{}")
with self.osbuild as osb:
osb.compile("{}")
osb.compile("{}")
def test_noop2(osb):
osb.compile("{}")
osb.compile("{}")
with self.osbuild as osb:
osb.compile("{}")
osb.compile("{}")
def test_noop_v2(self):
with tempfile.TemporaryDirectory() as tmp:
with self.osbuild as osb:
osb.compile(json.dumps(NOOP_V2), output_dir=tmp)
@pytest.mark.skipif(not test.TestBase.can_bind_mount(), reason="root-only")
def test_noop_v2(osb, tmpdir, jsondata):
osb.compile(jsondata, output_dir=tmpdir)