Tests: clone modules with the packaging utility

This is how packagers do. Git URL configuration can also be removed.

Also: redirect command outputs, so that pytest can capture them.

Signed-off-by: Hunor Csomortáni <csomh@redhat.com>
This commit is contained in:
Hunor Csomortáni
2019-12-06 12:18:11 +01:00
parent 30215a1ac5
commit cfb3549e79
3 changed files with 26 additions and 14 deletions

View File

@@ -2,14 +2,18 @@
# SPDX-License-Identifier: MIT
import os
import sys
import tempfile
import pytest
from sh import git, pushd
import sh
import yaml
import utils
our_sh = sh(_out=sys.stdout, _err=sys.stderr, _tee=True)
from our_sh import pushd, Command # noqa
@pytest.fixture(scope="session")
def test_env():
@@ -26,14 +30,13 @@ def test_env():
@pytest.fixture(scope="function")
def repo(request, test_env):
"""Clone the git repo to be used by the test
"""Clone the module repo to be used by the test
Find out the name of the test (anything that follow "test_"),
and get the corresponding git repo configuration from the test
environment configuration.
Find out the name of the test (anything that follow "test_"), and get
the corresponding module repo from the test environment configuration.
Do a shallow clone of the git repo in a temporary location and
switch the current working directory into it.
Clone the repo in a temporary location and switch the current working
directory into it.
:param pytest.FixtureRequest request: request object giving access
to the requesting test context
@@ -44,14 +47,16 @@ def repo(request, test_env):
with tempfile.TemporaryDirectory() as tempdir:
testname = request.function.__name__.split("test_", 1)[1]
repo_conf = test_env["testdata"][testname]
url = test_env["git_url"] + repo_conf["module"]
packaging_util = Command(test_env["packaging_utility"]).bake(
_out=sys.stdout, _err=sys.stderr, _tee=True
)
args = [
"--branch",
repo_conf["branch"],
url,
f"modules/{repo_conf['module']}",
tempdir,
]
git("clone", *args)
packaging_util("clone", *args)
with pushd(tempdir):
yield utils.Repo(repo_conf["module"])

View File

@@ -1,9 +1,10 @@
---
# Utility to be used to clone and build the modules.
# It's configuration points to the dist-git where
# test modules are to be found.
packaging_utility: fedpkg
# API endpoint of the MBS instance under test.
mbs_api: https://mbs.fedoraproject.org/module-build-service/2/module-builds/
# Git instance used by the build system.
git_url: https://src.fedoraproject.org/
# Koji instance the MBS instance under test communicates with.
koji:
server: https://koji.fedoraproject.org/kojihub

View File

@@ -2,13 +2,17 @@
# SPDX-License-Identifier: MIT
import re
import sys
import time
from kobo import rpmlib
import koji
import yaml
import requests
from sh import Command, git
import sh
our_sh = sh(_out=sys.stdout, _err=sys.stderr, _tee=True)
from our_sh import Command, git # noqa
class Koji:
@@ -123,7 +127,9 @@ class Build:
"""
def __init__(self, packaging_utility, mbs_api):
self._packaging_utility = Command(packaging_utility)
self._packaging_utility = Command(packaging_utility).bake(
_out=sys.stdout, _err=sys.stderr, _tee=True
)
self._mbs_api = mbs_api
self._data = None
self._component_data = None