-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function to initialize a test workspace (#215)
* Add function to initialize a test workspace * Update changelog * Add unit test for testing.init_jobs
- Loading branch information
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright (c) 2019 The Regents of the University of Michigan | ||
# All rights reserved. | ||
# This software is licensed under the BSD 3-Clause License. | ||
"""Functions for initializing workspaces for testing purposes.""" | ||
from itertools import cycle | ||
|
||
|
||
def init_jobs(project, nested=False, listed=False, heterogeneous=False): | ||
"""Initialize a dataspace for testing purposes | ||
:param project: | ||
The project to add the jobs to | ||
:type project: | ||
:py:class:`~.project.Project` | ||
:param nested: | ||
If True, included nested state points | ||
:type nested: | ||
bool | ||
:param listed: | ||
If True, include lists as values of state point parameters | ||
:type listed: | ||
bool | ||
:param heterogeneous: | ||
If True, include heterogeneous state point parameters | ||
:type heterogeneous: | ||
bool | ||
:returns: | ||
A list containing the initialized jobs | ||
:rtype: | ||
list of :py:class:`~.Job` | ||
""" | ||
jobs_init = [] | ||
vals = [1, 1.0, '1', False, True, None] | ||
if nested: | ||
vals += [{'b': v, 'c': 0} if heterogeneous else {'b': v} for v in vals] | ||
if listed: | ||
vals += [[v, 0] if heterogeneous else [v] for v in vals] | ||
if heterogeneous: | ||
for k, v in zip(cycle('ab'), vals): | ||
jobs_init.append(project.open_job({k: v}).init()) | ||
else: | ||
for v in vals: | ||
jobs_init.append(project.open_job(dict(a=v)).init()) | ||
return jobs_init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters