summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-11-05 16:31:27 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-11-05 16:31:27 +0900
commit8584c2df94c13be42bcdef0b6687208e11ab0e70 (patch)
tree188901fde6c511c5c0c37c68b7bc90f67e17ff59
parent139b7d98178100954c64cb788dbd4a01549f75ec (diff)
downloadbuildstream-8584c2df94c13be42bcdef0b6687208e11ab0e70.tar.gz
testutils: Added optional subdir parameter to repo creation
In case a test wants to create more than one repo.
-rw-r--r--tests/testutils/repo/__init__.py4
-rw-r--r--tests/testutils/repo/bzr.py4
-rw-r--r--tests/testutils/repo/git.py18
-rw-r--r--tests/testutils/repo/ostree.py4
-rw-r--r--tests/testutils/repo/repo.py5
5 files changed, 25 insertions, 10 deletions
diff --git a/tests/testutils/repo/__init__.py b/tests/testutils/repo/__init__.py
index 1123d6f5e..ff6844cf1 100644
--- a/tests/testutils/repo/__init__.py
+++ b/tests/testutils/repo/__init__.py
@@ -24,10 +24,10 @@ ALL_REPO_KINDS['zip'] = Zip
# kind (str): The kind of repo to create (a source plugin basename)
# directory (str): The path where the repo will keep a cache
#
-def create_repo(kind, directory):
+def create_repo(kind, directory, subdir='repo'):
try:
constructor = ALL_REPO_KINDS[kind]
except KeyError as e:
raise AssertionError("Unsupported repo kind {}".format(kind)) from e
- return constructor(directory)
+ return constructor(directory, subdir=subdir)
diff --git a/tests/testutils/repo/bzr.py b/tests/testutils/repo/bzr.py
index 0bb427e23..b6e68411d 100644
--- a/tests/testutils/repo/bzr.py
+++ b/tests/testutils/repo/bzr.py
@@ -13,10 +13,10 @@ BZR_ENV = {
class Bzr(Repo):
- def __init__(self, directory):
+ def __init__(self, directory, subdir):
if not HAVE_BZR:
pytest.skip("bzr is not available")
- super(Bzr, self).__init__(directory)
+ super(Bzr, self).__init__(directory, subdir)
def create(self, directory):
branch_dir = os.path.join(self.repo, 'trunk')
diff --git a/tests/testutils/repo/git.py b/tests/testutils/repo/git.py
index a1309bc7b..46338f445 100644
--- a/tests/testutils/repo/git.py
+++ b/tests/testutils/repo/git.py
@@ -17,10 +17,13 @@ GIT_ENV = {
class Git(Repo):
- def __init__(self, directory):
+ def __init__(self, directory, subdir):
if not HAVE_GIT:
pytest.skip("git is not available")
- super(Git, self).__init__(directory)
+
+ self.submodules = {}
+
+ super(Git, self).__init__(directory, subdir)
def create(self, directory):
self.copy_directory(directory, self.repo)
@@ -29,6 +32,12 @@ class Git(Repo):
subprocess.call(['git', 'commit', '-m', 'Initial commit'], env=GIT_ENV, cwd=self.repo)
return self.latest_commit()
+ def add_submodule(self, subdir, url):
+ self.submodules[subdir] = url
+ subprocess.call(['git', 'submodule', 'add', url, subdir], env=GIT_ENV, cwd=self.repo)
+ subprocess.call(['git', 'commit', '-m', 'Added the submodule'], env=GIT_ENV, cwd=self.repo)
+ return self.latest_commit()
+
def source_config(self, ref=None):
config = {
'kind': 'git',
@@ -38,6 +47,11 @@ class Git(Repo):
if ref is not None:
config['ref'] = ref
+ if self.submodules:
+ config['submodules'] = {}
+ for subdir, url in self.submodules.items():
+ config['submodules'][subdir] = {'url': url}
+
return config
def latest_commit(self):
diff --git a/tests/testutils/repo/ostree.py b/tests/testutils/repo/ostree.py
index f49659ca2..e240de113 100644
--- a/tests/testutils/repo/ostree.py
+++ b/tests/testutils/repo/ostree.py
@@ -7,11 +7,11 @@ from ..site import HAVE_OSTREE_CLI, HAVE_OSTREE
class OSTree(Repo):
- def __init__(self, directory):
+ def __init__(self, directory, subdir):
if not HAVE_OSTREE_CLI or not HAVE_OSTREE:
pytest.skip("ostree cli is not available")
- super(OSTree, self).__init__(directory)
+ super(OSTree, self).__init__(directory, subdir)
def create(self, directory):
subprocess.call(['ostree', 'init',
diff --git a/tests/testutils/repo/repo.py b/tests/testutils/repo/repo.py
index 03d616a90..4c9ee59a9 100644
--- a/tests/testutils/repo/repo.py
+++ b/tests/testutils/repo/repo.py
@@ -9,17 +9,18 @@ import shutil
#
# Args:
# directory (str): The base temp directory for the test
+# subdir (str): The subdir for the repo, in case there is more than one
#
class Repo():
- def __init__(self, directory):
+ def __init__(self, directory, subdir='repo'):
# The working directory for the repo object
#
self.directory = os.path.abspath(directory)
# The directory the actual repo will be stored in
- self.repo = os.path.join(self.directory, 'repo')
+ self.repo = os.path.join(self.directory, subdir)
os.makedirs(self.repo)