summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Salmon <will.salmon@codethink.co.uk>2018-11-02 14:00:40 +0000
committerWilliam Salmon <will.salmon@codethink.co.uk>2018-11-02 14:15:48 +0000
commitdc02ac17c986368880ce69ef14422acf07b8eabd (patch)
tree507a67c9960c5a04d6fe6819a958904e30571f4d
parent7f79b9ce511f1421851821bf2928352ba569b8f0 (diff)
downloadbuildstream-willsalmon/triggerCI.tar.gz
refactor testswillsalmon/triggerCI
-rw-r--r--tests/frontend/workspace.py157
1 files changed, 106 insertions, 51 deletions
diff --git a/tests/frontend/workspace.py b/tests/frontend/workspace.py
index 51b7d6088..cdf12387c 100644
--- a/tests/frontend/workspace.py
+++ b/tests/frontend/workspace.py
@@ -21,9 +21,11 @@
# Phillip Smyth <phillip.smyth@codethink.co.uk>
# Jonathan Maw <jonathan.maw@codethink.co.uk>
# Richard Maw <richard.maw@codethink.co.uk>
+# William Salmon <will.salmon@codethink.co.uk>
#
import os
+import stat
import pytest
import shutil
import subprocess
@@ -43,65 +45,118 @@ DATA_DIR = os.path.join(
)
-def open_workspace(cli, tmpdir, datafiles, kind, track, suffix='', workspace_dir=None,
- project_path=None, element_attrs=None):
- if not workspace_dir:
- workspace_dir = os.path.join(str(tmpdir), 'workspace{}'.format(suffix))
- if not project_path:
- project_path = os.path.join(datafiles.dirname, datafiles.basename)
- else:
- shutil.copytree(os.path.join(datafiles.dirname, datafiles.basename), project_path)
- bin_files_path = os.path.join(project_path, 'files', 'bin-files')
- element_path = os.path.join(project_path, 'elements')
- element_name = 'workspace-test-{}{}.bst'.format(kind, suffix)
+class WorkspaceCreater():
+ def __init__(self, cli, tmpdir, datafiles, project_path=None):
+ self.cli = cli
+ self.tmpdir = tmpdir
+ self.datafiles = datafiles
+
+ if not project_path:
+ project_path = os.path.join(datafiles.dirname, datafiles.basename)
+ else:
+ shutil.copytree(os.path.join(datafiles.dirname, datafiles.basename), project_path)
+
+ self.project_path = project_path
+ self.bin_files_path = os.path.join(project_path, 'files', 'bin-files')
+
+ self.workspace_cmd = os.path.join(self.project_path, 'workspace_cmd')
+
+ def create_workspace_element(self, kind, track, suffix='', workspace_dir=None,
+ element_attrs=None):
+ element_name = 'workspace-test-{}{}.bst'.format(kind, suffix)
+ element_path = os.path.join(self.project_path, 'elements')
+ if not workspace_dir:
+ workspace_dir = os.path.join(self.workspace_cmd, element_name.rstrip('.bst'))
+
+ # Create our repo object of the given source type with
+ # the bin files, and then collect the initial ref.
+ repo = create_repo(kind, str(self.tmpdir))
+ ref = repo.create(self.bin_files_path)
+ if track:
+ ref = None
+
+ # Write out our test target
+ element = {
+ 'kind': 'import',
+ 'sources': [
+ repo.source_config(ref=ref)
+ ]
+ }
+ if element_attrs:
+ element = {**element, **element_attrs}
+ _yaml.dump(element,
+ os.path.join(element_path,
+ element_name))
+ return element_name, element_path, workspace_dir
- # Create our repo object of the given source type with
- # the bin files, and then collect the initial ref.
- #
- repo = create_repo(kind, str(tmpdir))
- ref = repo.create(bin_files_path)
- if track:
- ref = None
+ def create_workspace_elements(self, kinds, track, suffixs=None, workspace_dir_usr=None,
+ element_attrs=None):
- # Write out our test target
- element = {
- 'kind': 'import',
- 'sources': [
- repo.source_config(ref=ref)
- ]
- }
- if element_attrs:
- element = {**element, **element_attrs}
- _yaml.dump(element,
- os.path.join(element_path,
- element_name))
+ element_tuples = []
- # Assert that there is no reference, a track & fetch is needed
- state = cli.get_element_state(project_path, element_name)
- if track:
- assert state == 'no reference'
- else:
- assert state == 'fetch needed'
+ if suffixs is None:
+ suffixs = ['', ] * len(kinds)
+ else:
+ if len(suffixs) != len(kinds):
+ raise "terable error"
- # Now open the workspace, this should have the effect of automatically
- # tracking & fetching the source from the repo.
- args = ['workspace', 'open']
- if track:
- args.append('--track')
- args.extend([element_name, workspace_dir])
- result = cli.run(project=project_path, args=args)
+ for suffix, kind in zip(suffixs, kinds):
+ element_name, element_path, workspace_dir = \
+ self.create_workspace_element(kind, track, suffix, workspace_dir_usr,
+ element_attrs)
- result.assert_success()
+ # Assert that there is no reference, a track & fetch is needed
+ state = self.cli.get_element_state(self.project_path, element_name)
+ if track:
+ assert state == 'no reference'
+ else:
+ assert state == 'fetch needed'
+ element_tuples.append((element_name, workspace_dir))
- # Assert that we are now buildable because the source is
- # now cached.
- assert cli.get_element_state(project_path, element_name) == 'buildable'
+ return element_tuples
- # Check that the executable hello file is found in the workspace
- filename = os.path.join(workspace_dir, 'usr', 'bin', 'hello')
- assert os.path.exists(filename)
+ def open_workspaces(self, kinds, track, suffixs=None, workspace_dir=None,
+ element_attrs=None):
+
+ if workspace_dir is None:
+ workspace_dir = os.path.join(str(self.tmpdir), 'workspace{}'.format(suffixs[0]))
+
+ element_tuples = self.create_workspace_elements(kinds, track, suffixs, workspace_dir,
+ element_attrs)
+ os.makedirs(self.workspace_cmd, exist_ok=True)
+
+ # Now open the workspace, this should have the effect of automatically
+ # tracking & fetching the source from the repo.
+ args = ['workspace', 'open']
+ if track:
+ args.append('--track')
+
+ args.extend([element_name for element_name, workspace_dir_suffix in element_tuples])
+ args.append(workspace_dir)
+ result = self.cli.run(cwd=self.workspace_cmd, project=self.project_path, args=args)
- return (element_name, project_path, workspace_dir)
+ result.assert_success()
+
+ for element_name, workspace_dir in element_tuples:
+ # Assert that we are now buildable because the source is
+ # now cached.
+ assert self.cli.get_element_state(self.project_path, element_name) == 'buildable'
+
+ # Check that the executable hello file is found in the workspace
+ filename = os.path.join(workspace_dir, 'usr', 'bin', 'hello')
+ assert os.path.exists(filename)
+
+ return element_tuples
+
+
+def open_workspace(cli, tmpdir, datafiles, kind, track, suffix='', workspace_dir=None,
+ project_path=None, element_attrs=None):
+ workspace_object = WorkspaceCreater(cli, tmpdir, datafiles, project_path)
+ workspaces = workspace_object.open_workspaces((kind, ), track, (suffix, ), workspace_dir,
+ element_attrs)
+ assert len(workspaces) == 1
+ element_name, workspace = workspaces[0]
+ return element_name, workspace_object.project_path, workspace
@pytest.mark.datafiles(DATA_DIR)