You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by ro...@apache.org on 2020/12/29 13:30:34 UTC
[buildstream] 02/11: plugintestutils: Add copy of
testutils.junction.py
This is an automated email from the ASF dual-hosted git repository.
root pushed a commit to branch phil/remove-ostree-plugin
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 94d31066d2801a75520a06f3c40ba2fe06bec5be
Author: Phil Dawson <ph...@codethink.co.uk>
AuthorDate: Tue Mar 26 09:32:14 2019 +0000
plugintestutils: Add copy of testutils.junction.py
Copy tests.testutils.junction into plugintestutils._utils. This is
needed for use by the templated source tests.
---
buildstream/plugintestutils/_utils/__init__.py | 1 +
buildstream/plugintestutils/_utils/junction.py | 83 ++++++++++++++++++++++++++
tests/sources/generic/fetch.py | 2 +-
tests/sources/generic/mirror.py | 2 +-
tests/sources/generic/track.py | 2 +-
tests/sources/generic/track_cross_junction.py | 2 +-
6 files changed, 88 insertions(+), 4 deletions(-)
diff --git a/buildstream/plugintestutils/_utils/__init__.py b/buildstream/plugintestutils/_utils/__init__.py
new file mode 100644
index 0000000..5938e6a
--- /dev/null
+++ b/buildstream/plugintestutils/_utils/__init__.py
@@ -0,0 +1 @@
+from .junction import generate_junction
diff --git a/buildstream/plugintestutils/_utils/junction.py b/buildstream/plugintestutils/_utils/junction.py
new file mode 100644
index 0000000..530a191
--- /dev/null
+++ b/buildstream/plugintestutils/_utils/junction.py
@@ -0,0 +1,83 @@
+import subprocess
+import pytest
+
+from .._utils.site import HAVE_GIT, GIT, GIT_ENV
+from buildstream.plugintestutils import Repo
+from buildstream import _yaml
+
+
+# generate_junction()
+#
+# Generates a junction element with a git repository
+#
+# Args:
+# tmpdir: The tmpdir fixture, for storing the generated git repo
+# subproject_path: The path for the subproject, to add to the git repo
+# junction_path: The location to store the generated junction element
+# store_ref: Whether to store the ref in the junction.bst file
+#
+# Returns:
+# (str): The ref
+#
+def generate_junction(tmpdir, subproject_path, junction_path, *, store_ref=True):
+ # Create a repo to hold the subproject and generate
+ # a junction element for it
+ #
+ repo = _SimpleGit(str(tmpdir))
+ source_ref = ref = repo.create(subproject_path)
+ if not store_ref:
+ source_ref = None
+
+ element = {
+ 'kind': 'junction',
+ 'sources': [
+ repo.source_config(ref=source_ref)
+ ]
+ }
+ _yaml.dump(element, junction_path)
+
+ return ref
+
+
+# A barebones Git Repo class to use for generating junctions
+class _SimpleGit(Repo):
+ def __init__(self, directory, subdir='repo'):
+ if not HAVE_GIT:
+ pytest.skip('git is not available')
+ super().__init__(directory, subdir)
+
+ def create(self, directory):
+ self.copy_directory(directory, self.repo)
+ self._run_git('init', '.')
+ self._run_git('add', '.')
+ self._run_git('commit', '-m', 'Initial commit')
+ return self.latest_commit()
+
+ def latest_commit(self):
+ return self._run_git(
+ 'rev-parse', 'HEAD',
+ stdout=subprocess.PIPE,
+ universal_newlines=True,
+ ).stdout.strip()
+
+ def source_config(self, ref=None, checkout_submodules=None):
+ config = {
+ 'kind': 'git',
+ 'url': 'file://' + self.repo,
+ 'track': 'master'
+ }
+ if ref is not None:
+ config['ref'] = ref
+ if checkout_submodules is not None:
+ config['checkout-submodules'] = checkout_submodules
+
+ return config
+
+ def _run_git(self, *args, **kwargs):
+ argv = [GIT]
+ argv.extend(args)
+ if 'env' not in kwargs:
+ kwargs['env'] = dict(GIT_ENV, PWD=self.repo)
+ kwargs.setdefault('cwd', self.repo)
+ kwargs.setdefault('check', True)
+ return subprocess.run(argv, **kwargs)
diff --git a/tests/sources/generic/fetch.py b/tests/sources/generic/fetch.py
index f8c6b55..52c8533 100644
--- a/tests/sources/generic/fetch.py
+++ b/tests/sources/generic/fetch.py
@@ -22,7 +22,7 @@
import os
import pytest
-from tests.testutils import generate_junction
+from .._utils import generate_junction
from buildstream.plugintestutils import create_repo, ALL_REPO_KINDS
from tests.frontend import configure_project
diff --git a/tests/sources/generic/mirror.py b/tests/sources/generic/mirror.py
index f52efcd..f17e388 100644
--- a/tests/sources/generic/mirror.py
+++ b/tests/sources/generic/mirror.py
@@ -22,7 +22,7 @@
import os
import pytest
-from tests.testutils import generate_junction
+from .._utils import generate_junction
from buildstream.plugintestutils import create_repo, ALL_REPO_KINDS
from buildstream.plugintestutils import cli # pylint: disable=unused-import
diff --git a/tests/sources/generic/track.py b/tests/sources/generic/track.py
index 881046a..9e53bc6 100644
--- a/tests/sources/generic/track.py
+++ b/tests/sources/generic/track.py
@@ -22,8 +22,8 @@
import os
import pytest
-from tests.testutils import generate_junction
from tests.frontend import configure_project
+from .._utils import generate_junction
from buildstream.plugintestutils import create_repo, ALL_REPO_KINDS
from buildstream.plugintestutils import cli # pylint: disable=unused-import
diff --git a/tests/sources/generic/track_cross_junction.py b/tests/sources/generic/track_cross_junction.py
index 7cf0496..68db917 100644
--- a/tests/sources/generic/track_cross_junction.py
+++ b/tests/sources/generic/track_cross_junction.py
@@ -22,7 +22,7 @@
import os
import pytest
-from tests.testutils import generate_junction
+from .._utils import generate_junction
from buildstream.plugintestutils import create_repo, ALL_REPO_KINDS
from buildstream.plugintestutils import cli # pylint: disable=unused-import