... |
... |
@@ -44,109 +44,118 @@ DATA_DIR = os.path.join( |
44
|
44
|
)
|
45
|
45
|
|
46
|
46
|
|
47
|
|
-def create_workspace_element(tmpdir, datafiles, kind, track, suffix='', workspace_dir=None,
|
48
|
|
- project_path=None, element_attrs=None):
|
49
|
|
-
|
50
|
|
- element_name = 'workspace-test-{}{}.bst'.format(kind, suffix)
|
51
|
|
- element_path = os.path.join(project_path, 'elements')
|
52
|
|
- workspace_cmd = os.path.join(project_path, 'workspace_cmd')
|
53
|
|
- if not workspace_dir:
|
54
|
|
- workspace_dir = os.path.join(workspace_cmd, element_name.rstrip('.bst'))
|
55
|
|
- bin_files_path = os.path.join(project_path, 'files', 'bin-files')
|
56
|
|
-
|
57
|
|
- # Create our repo object of the given source type with
|
58
|
|
- # the bin files, and then collect the initial ref.
|
59
|
|
- repo = create_repo(kind, str(tmpdir))
|
60
|
|
- ref = repo.create(bin_files_path)
|
61
|
|
- if track:
|
62
|
|
- ref = None
|
63
|
|
-
|
64
|
|
- # Write out our test target
|
65
|
|
- element = {
|
66
|
|
- 'kind': 'import',
|
67
|
|
- 'sources': [
|
68
|
|
- repo.source_config(ref=ref)
|
69
|
|
- ]
|
70
|
|
- }
|
71
|
|
- if element_attrs:
|
72
|
|
- element = {**element, **element_attrs}
|
73
|
|
- _yaml.dump(element,
|
74
|
|
- os.path.join(element_path,
|
75
|
|
- element_name))
|
76
|
|
- return element_name, element_path, workspace_dir
|
77
|
|
-
|
78
|
|
-
|
79
|
|
-def create_workspace_elements(cli, tmpdir, datafiles, kinds, track, suffixs=None, workspace_dir=None,
|
80
|
|
- project_path=None, element_attrs=None):
|
|
47
|
+class WorkspaceCreater():
|
|
48
|
+ def __init__(self, cli, tmpdir, datafiles, project_path=None):
|
|
49
|
+ self.cli = cli
|
|
50
|
+ self.tmpdir = tmpdir
|
|
51
|
+ self.datafiles = datafiles
|
|
52
|
+
|
|
53
|
+ if not project_path:
|
|
54
|
+ project_path = os.path.join(datafiles.dirname, datafiles.basename)
|
|
55
|
+ else:
|
|
56
|
+ shutil.copytree(os.path.join(datafiles.dirname, datafiles.basename), project_path)
|
81
|
57
|
|
82
|
|
- if not project_path:
|
83
|
|
- project_path = os.path.join(datafiles.dirname, datafiles.basename)
|
84
|
|
- else:
|
85
|
|
- shutil.copytree(os.path.join(datafiles.dirname, datafiles.basename), project_path)
|
|
58
|
+ self.project_path = project_path
|
|
59
|
+ self.bin_files_path = os.path.join(project_path, 'files', 'bin-files')
|
86
|
60
|
|
87
|
|
- results = []
|
|
61
|
+ self.workspace_cmd = os.path.join(self.project_path, 'workspace_cmd')
|
88
|
62
|
|
89
|
|
- if suffixs is None:
|
90
|
|
- suffixs = ['', ] * len(kinds)
|
91
|
|
- else:
|
92
|
|
- if len(suffixs) != len(kinds):
|
93
|
|
- raise "terable error"
|
|
63
|
+ def create_workspace_element(self, kind, track, suffix='', workspace_dir=None,
|
|
64
|
+ element_attrs=None):
|
|
65
|
+ element_name = 'workspace-test-{}{}.bst'.format(kind, suffix)
|
|
66
|
+ element_path = os.path.join(self.project_path, 'elements')
|
|
67
|
+ if not workspace_dir:
|
|
68
|
+ workspace_dir = os.path.join(self.workspace_cmd, element_name.rstrip('.bst'))
|
94
|
69
|
|
95
|
|
- for suffix, kind in zip(suffixs, kinds):
|
96
|
|
- element_name, element_path, workspace_dir_suffix \
|
97
|
|
- = create_workspace_element(tmpdir, datafiles, kind, track, suffix, workspace_dir,
|
98
|
|
- project_path, element_attrs)
|
99
|
|
-
|
100
|
|
- # Assert that there is no reference, a track & fetch is needed
|
101
|
|
- state = cli.get_element_state(project_path, element_name)
|
|
70
|
+ # Create our repo object of the given source type with
|
|
71
|
+ # the bin files, and then collect the initial ref.
|
|
72
|
+ repo = create_repo(kind, str(self.tmpdir))
|
|
73
|
+ ref = repo.create(self.bin_files_path)
|
102
|
74
|
if track:
|
103
|
|
- assert state == 'no reference'
|
104
|
|
- else:
|
105
|
|
- assert state == 'fetch needed'
|
106
|
|
- results.append((element_name, project_path, workspace_dir_suffix))
|
107
|
|
- return results
|
|
75
|
+ ref = None
|
108
|
76
|
|
|
77
|
+ # Write out our test target
|
|
78
|
+ element = {
|
|
79
|
+ 'kind': 'import',
|
|
80
|
+ 'sources': [
|
|
81
|
+ repo.source_config(ref=ref)
|
|
82
|
+ ]
|
|
83
|
+ }
|
|
84
|
+ if element_attrs:
|
|
85
|
+ element = {**element, **element_attrs}
|
|
86
|
+ _yaml.dump(element,
|
|
87
|
+ os.path.join(element_path,
|
|
88
|
+ element_name))
|
|
89
|
+ return element_name, element_path, workspace_dir
|
109
|
90
|
|
110
|
|
-def open_workspaces(cli, tmpdir, datafiles, kinds, track, suffixs=None, workspace_dir=None,
|
111
|
|
- project_path=None, element_attrs=None):
|
|
91
|
+ def create_workspace_elements(self, kinds, track, suffixs=None, workspace_dir_usr=None,
|
|
92
|
+ element_attrs=None):
|
112
|
93
|
|
113
|
|
- results = create_workspace_elements(cli, tmpdir, datafiles, kinds, track, suffixs, workspace_dir,
|
114
|
|
- project_path, element_attrs)
|
115
|
|
- _, project_path, workspace_dir_suffix = results[0]
|
116
|
|
- workspace_cmd = os.path.join(project_path, 'workspace_cmd')
|
117
|
|
- os.makedirs(workspace_cmd, exist_ok=True)
|
|
94
|
+ results = []
|
118
|
95
|
|
119
|
|
- # Now open the workspace, this should have the effect of automatically
|
120
|
|
- # tracking & fetching the source from the repo.
|
121
|
|
- args = ['workspace', 'open']
|
122
|
|
- if track:
|
123
|
|
- args.append('--track')
|
124
|
|
- if workspace_dir is not None:
|
125
|
|
- assert (len(results) != 1, "test logic error")
|
126
|
|
- args.extend(['--directory', workspace_dir_suffix])
|
|
96
|
+ if suffixs is None:
|
|
97
|
+ suffixs = ['', ] * len(kinds)
|
|
98
|
+ else:
|
|
99
|
+ if len(suffixs) != len(kinds):
|
|
100
|
+ raise "terable error"
|
|
101
|
+
|
|
102
|
+ for suffix, kind in zip(suffixs, kinds):
|
|
103
|
+ element_name, element_path, workspace_dir = \
|
|
104
|
+ self.create_workspace_element(kind, track, suffix, workspace_dir_usr,
|
|
105
|
+ element_attrs)
|
|
106
|
+
|
|
107
|
+ # Assert that there is no reference, a track & fetch is needed
|
|
108
|
+ state = self.cli.get_element_state(self.project_path, element_name)
|
|
109
|
+ if track:
|
|
110
|
+ assert state == 'no reference'
|
|
111
|
+ else:
|
|
112
|
+ assert state == 'fetch needed'
|
|
113
|
+ results.append((element_name, workspace_dir))
|
|
114
|
+
|
|
115
|
+ return results
|
|
116
|
+
|
|
117
|
+ def open_workspaces(self, kinds, track, suffixs=None, workspace_dir=None,
|
|
118
|
+ element_attrs=None):
|
|
119
|
+
|
|
120
|
+ results = self.create_workspace_elements(kinds, track, suffixs, workspace_dir,
|
|
121
|
+ element_attrs)
|
|
122
|
+ os.makedirs(self.workspace_cmd, exist_ok=True)
|
|
123
|
+
|
|
124
|
+ # Now open the workspace, this should have the effect of automatically
|
|
125
|
+ # tracking & fetching the source from the repo.
|
|
126
|
+ args = ['workspace', 'open']
|
|
127
|
+ if track:
|
|
128
|
+ args.append('--track')
|
|
129
|
+ if workspace_dir is not None:
|
|
130
|
+ assert len(results) == 1, "test logic error"
|
|
131
|
+ _, workspace_dir = results[0]
|
|
132
|
+ args.extend(['--directory', workspace_dir])
|
127
|
133
|
|
128
|
|
- args.extend([element_name for element_name, project_path, workspace_dir_suffix in results])
|
129
|
|
- print ('args', args)
|
130
|
|
- result = cli.run(cwd=workspace_cmd, project=project_path, args=args)
|
|
134
|
+ args.extend([element_name for element_name, workspace_dir_suffix in results])
|
|
135
|
+ result = self.cli.run(cwd=self.workspace_cmd, project=self.project_path, args=args)
|
131
|
136
|
|
132
|
|
- result.assert_success()
|
|
137
|
+ result.assert_success()
|
133
|
138
|
|
134
|
|
- for element_name, project_path, workspace_dir_suffix in results:
|
135
|
|
- # Assert that we are now buildable because the source is
|
136
|
|
- # now cached.
|
137
|
|
- assert cli.get_element_state(project_path, element_name) == 'buildable'
|
|
139
|
+ for element_name, workspace_dir in results:
|
|
140
|
+ # Assert that we are now buildable because the source is
|
|
141
|
+ # now cached.
|
|
142
|
+ assert self.cli.get_element_state(self.project_path, element_name) == 'buildable'
|
138
|
143
|
|
139
|
|
- # Check that the executable hello file is found in the workspace
|
140
|
|
- filename = os.path.join(workspace_dir_suffix, 'usr', 'bin', 'hello')
|
141
|
|
- assert os.path.exists(filename)
|
|
144
|
+ # Check that the executable hello file is found in the workspace
|
|
145
|
+ filename = os.path.join(workspace_dir, 'usr', 'bin', 'hello')
|
|
146
|
+ assert os.path.exists(filename)
|
142
|
147
|
|
143
|
|
- return results
|
|
148
|
+ return results
|
144
|
149
|
|
145
|
150
|
|
146
|
151
|
def open_workspace(cli, tmpdir, datafiles, kind, track, suffix='', workspace_dir=None,
|
147
|
152
|
project_path=None, element_attrs=None):
|
148
|
|
- return open_workspaces(cli, tmpdir, datafiles, (kind,), track, suffixs=(suffix,), workspace_dir=workspace_dir,
|
149
|
|
- project_path=project_path, element_attrs=element_attrs)[0]
|
|
153
|
+ workspace_object = WorkspaceCreater(cli, tmpdir, datafiles, project_path)
|
|
154
|
+ workspaces = workspace_object.open_workspaces((kind, ), track, (suffix, ), workspace_dir,
|
|
155
|
+ element_attrs)
|
|
156
|
+ assert len(workspaces) == 1
|
|
157
|
+ element_name, workspace = workspaces[0]
|
|
158
|
+ return element_name, workspace_object.project_path, workspace
|
150
|
159
|
|
151
|
160
|
|
152
|
161
|
@pytest.mark.datafiles(DATA_DIR)
|
... |
... |
@@ -158,9 +167,11 @@ def test_open(cli, tmpdir, datafiles, kind): |
158
|
167
|
@pytest.mark.datafiles(DATA_DIR)
|
159
|
168
|
def test_open_multi(cli, tmpdir, datafiles):
|
160
|
169
|
|
161
|
|
- workspaces = open_workspaces(cli, tmpdir, datafiles, repo_kinds, False)
|
162
|
|
-
|
163
|
|
- for (element_name, project, workspace), kind in zip(workspaces, repo_kinds):
|
|
170
|
+ workspace_object = WorkspaceCreater(cli, tmpdir, datafiles)
|
|
171
|
+ workspaces = workspace_object.open_workspaces(repo_kinds, False)
|
|
172
|
+
|
|
173
|
+ for (elname, workspace), kind in zip(workspaces, repo_kinds):
|
|
174
|
+ assert kind in elname
|
164
|
175
|
workspace_lsdir = os.listdir(workspace)
|
165
|
176
|
if kind == 'git':
|
166
|
177
|
assert('.git' in workspace_lsdir)
|
... |
... |
@@ -173,19 +184,19 @@ def test_open_multi(cli, tmpdir, datafiles): |
173
|
184
|
|
174
|
185
|
@pytest.mark.datafiles(DATA_DIR)
|
175
|
186
|
def test_open_multi_with_directory(cli, tmpdir, datafiles):
|
|
187
|
+ workspace_object = WorkspaceCreater(cli, tmpdir, datafiles)
|
176
|
188
|
|
177
|
|
- results = create_workspace_elements(cli, tmpdir, datafiles, repo_kinds, False, repo_kinds)
|
178
|
|
- _, project_path, workspace_dir_suffix = results[0]
|
179
|
|
-
|
180
|
|
- workspace_cmd = os.path.join(project_path, 'workspace_cmd')
|
181
|
|
- os.makedirs(workspace_cmd, exist_ok=True)
|
|
189
|
+ results = workspace_object.create_workspace_elements(repo_kinds, False, repo_kinds)
|
|
190
|
+ os.makedirs(workspace_object.workspace_cmd, exist_ok=True)
|
182
|
191
|
|
183
|
192
|
# Now open the workspace, this should have the effect of automatically
|
184
|
193
|
# tracking & fetching the source from the repo.
|
185
|
|
- args = ['workspace', 'open', '--directory', 'anythingi/you/like']
|
|
194
|
+ args = ['workspace', 'open']
|
|
195
|
+ args.extend(['--directory', 'any/dir/should/fail'])
|
186
|
196
|
|
187
|
|
- args.extend([element_name for element_name, project_path, workspace_dir_suffix in results])
|
188
|
|
- result = cli.run(cwd=workspace_cmd, project=project_path, args=args)
|
|
197
|
+ args.extend([element_name for element_name, workspace_dir_suffix in results])
|
|
198
|
+ result = workspace_object.cli.run(cwd=workspace_object.workspace_cmd, project=workspace_object.project_path,
|
|
199
|
+ args=args)
|
189
|
200
|
|
190
|
201
|
result.assert_main_error(ErrorDomain.ARTIFACT, None)
|
191
|
202
|
assert ("Directory option can only be used if a single element is given" in result.stderr)
|