-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing of object, map, and array literals #8
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
__pycache__ | ||
.DS_Store | ||
|
||
# cromwell jar files | ||
# cromwell jar files, etc. | ||
cromwell-executions | ||
cromwell-workflow-logs | ||
*.jar | ||
pytest-wdl-tests/tests/literals/run.sh | ||
pytest-wdl-tests/tests/literals/validate.sh | ||
pytest-wdl-tests/tests/literals/json.sh | ||
|
||
# python virtual environment | ||
env/ | ||
env/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
INTS | ||
0 | ||
1 | ||
2 | ||
STRINGS | ||
array | ||
literal |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
INTS | ||
1 10 | ||
2 11 | ||
MIXED | ||
a 1 | ||
b 2 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
a b | ||
10 11 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
OBJECT_SYNTAX | ||
key1 key2 key3 | ||
7 8 9 | ||
MAP_COERCION | ||
key1name key2name key3name | ||
10 11 12 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
23 twenty-three |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
# This workflow tests the the literals sections of the WDL 1.0 Spec | ||
# It also requires the use of some functions such as write_lines(), write_object(), write_map(), and stdout() | ||
# write_map() is slightly broken as it does not print a \n after writing like the related functions do. | ||
|
||
version 1.0 | ||
|
||
workflow literals { | ||
input { | ||
### Array Literals | ||
Array[String] array_literal_strings = ["array", "literal"] | ||
Array[Int] array_literal_ints = [0, 1, 2] | ||
|
||
### Map Literals | ||
Map[Int, Int] map_literal_ints = {1: 10, 2: 11} | ||
Map[String, Int] map_literal_mixed = {"a": 1, "b": 2} | ||
|
||
### Object Literals | ||
Object object_literal = object { | ||
a: 10, | ||
b: 11 | ||
} | ||
|
||
### Object Coercion from Map | ||
# "object" keyword before {} indicates Object, absence of indicates Map. | ||
String key1 = "key1name" | ||
String key2 = "key2name" | ||
String key3 = "key3name" | ||
|
||
Object object_syntax = object { | ||
key1: 7, | ||
key2: 8, | ||
key3: 9 | ||
} | ||
|
||
Object map_coercion = { | ||
key1: 10, | ||
key2: 11, | ||
key3: 12 | ||
} | ||
|
||
### Pair Literals | ||
Pair[Int, String] pair_literal_mixed = (23, "twenty-three") | ||
} | ||
call array_literals { | ||
input: | ||
array_literal_strings=write_lines(array_literal_strings), | ||
array_literal_ints=write_lines(array_literal_ints) | ||
} | ||
call map_literals { | ||
input: | ||
map_literal_ints=write_map(map_literal_ints), | ||
map_literal_mixed=write_map(map_literal_mixed) | ||
} | ||
call object_literals { | ||
input: | ||
object_literal = write_object(object_literal) | ||
} | ||
call object_map_coercion { | ||
input: | ||
object_syntax=write_object(object_syntax), | ||
map_coercion=write_object(map_coercion) | ||
} | ||
call pair_literals { | ||
input: | ||
pair_literal_mixed_left=pair_literal_mixed.left, | ||
pair_literal_mixed_right=pair_literal_mixed.right | ||
} | ||
output { | ||
File array_literals_out = array_literals.array_literals_out | ||
File map_literals_out = map_literals.map_literals_out | ||
File object_literals_out = object_literals.object_literals_out | ||
File object_map_coercion_out = object_map_coercion.object_map_coercion_out | ||
File pair_literals_out = pair_literals.pair_literals_out | ||
} | ||
} | ||
|
||
task array_literals { | ||
input { | ||
File array_literal_ints | ||
File array_literal_strings | ||
} | ||
command { | ||
set -e | ||
echo INTS | ||
cat ~{array_literal_ints} | ||
printf "STRINGS\n" | ||
cat ~{array_literal_strings} | ||
} | ||
output { | ||
File array_literals_out = stdout() | ||
} | ||
runtime { | ||
docker: "ubuntu:latest" | ||
} | ||
} | ||
|
||
task map_literals { | ||
input { | ||
File map_literal_ints | ||
File map_literal_mixed | ||
} | ||
command { | ||
set -e | ||
|
||
echo INTS | ||
cat ~{map_literal_ints} | ||
printf "\nMIXED\n" # Need a newline following the first written map | ||
cat ~{map_literal_mixed} | ||
} | ||
output { | ||
File map_literals_out = stdout() | ||
} | ||
runtime { | ||
docker: "ubuntu:latest" | ||
} | ||
} | ||
|
||
task object_literals { | ||
input { | ||
File object_literal | ||
} | ||
command { | ||
set -e | ||
|
||
cat ~{object_literal} | ||
} | ||
output { | ||
File object_literals_out = stdout() | ||
} | ||
runtime { | ||
docker: "ubuntu:latest" | ||
} | ||
} | ||
|
||
task object_map_coercion { | ||
input { | ||
File object_syntax | ||
File map_coercion | ||
} | ||
command { | ||
set -e | ||
|
||
echo OBJECT_SYNTAX | ||
cat ~{object_syntax} | ||
printf "MAP_COERCION\n" | ||
cat ~{map_coercion} | ||
} | ||
output { | ||
File object_map_coercion_out = stdout() | ||
} | ||
runtime { | ||
docker: "ubuntu:latest" | ||
} | ||
} | ||
|
||
task pair_literals { | ||
input { | ||
Int pair_literal_mixed_left | ||
String pair_literal_mixed_right | ||
} | ||
command { | ||
set -e | ||
|
||
echo ~{pair_literal_mixed_left} ~{pair_literal_mixed_right} | ||
} | ||
output { | ||
File pair_literals_out = stdout() | ||
} | ||
runtime { | ||
docker: "ubuntu:latest" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need this if the file is empty? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I deleted the jsons and the input dictionaries from every line in the python script and it gave me that error message. Any way around supplying inputs to py-test wdl? |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
def test_literals(workflow_data, workflow_runner): | ||
expected = workflow_data.get_dict("array_literals_out", "map_literals_out", "object_literals_out", "object_map_coercion_out", "pair_literals_out") | ||
workflow_runner("literals.wdl", {}, expected, workflow_name="literals") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
version 1.0 | ||
|
||
workflow basic_array_functions { | ||
input { | ||
File tsv | ||
Int num = 3 # range(num) --> [0, 1, 2] | ||
Array[Int] array_1 = [0, 1, 2] | ||
Array[Int] array_2 = [3, 4, 5] | ||
Array[String] array_3 = ['a', 'b', 'c'] | ||
Array[String] array_4 = ['d', 'e'] | ||
} | ||
# tsv is read into a 2D array before it is fed to transpose and flatten | ||
Array[Array[String]] array_2d = read_tsv(tsv) | ||
|
||
call range { | ||
input: array_range=range(num) | ||
} | ||
call transpose { | ||
input: array_transpose=transpose(array_2d) | ||
} | ||
scatter (pair in zip(array_1, array_3)) { | ||
call zip { | ||
input: | ||
pair_left=pair.left, | ||
pair_right=pair.right | ||
} | ||
} | ||
scatter (pair in cross(array_1, array_4)) { | ||
call cross { | ||
input: | ||
pair_left=pair.left, | ||
pair_right=pair.right | ||
} | ||
} | ||
call length { | ||
input: | ||
array_1_length=length(array_1), | ||
array_4_length=length(array_4) | ||
} | ||
call flatten { | ||
input: array_flatten=flatten(array_2d) | ||
} | ||
call prefix { | ||
input: array_prefix=prefix("prefix_", array_3) | ||
} | ||
output { | ||
File range_out = range.out | ||
File transpose_out = transpose.out | ||
Array[File] zip_out = zip.out | ||
Array[File] cross_out = cross.out | ||
File length_out = length.out | ||
File flatten_out = flatten.out | ||
File prefix_out = prefix.out | ||
} | ||
} | ||
|
||
task range { | ||
input { | ||
Array[Int] array_range | ||
} | ||
command { | ||
cat ~{write_lines(array_range)} | ||
} | ||
output { | ||
File out = stdout() | ||
} | ||
runtime { | ||
docker: "ubuntu:latest" | ||
} | ||
} | ||
|
||
task transpose { | ||
input { | ||
Array[Array[String]] array_transpose | ||
} | ||
command { | ||
cat ~{write_tsv(array_transpose)} | ||
} | ||
output { | ||
File out = stdout() | ||
} | ||
runtime { | ||
docker: "ubuntu:latest" | ||
} | ||
} | ||
|
||
task zip { | ||
input { | ||
Int pair_left | ||
String pair_right | ||
} | ||
command { | ||
echo ~{pair_left} ~{pair_right} | ||
} | ||
output { | ||
File out = stdout() | ||
} | ||
runtime { | ||
docker: "ubuntu:latest" | ||
} | ||
} | ||
|
||
task cross { | ||
input { | ||
Int pair_left | ||
String pair_right | ||
} | ||
command { | ||
echo ~{pair_left} ~{pair_right} | ||
} | ||
output { | ||
File out = stdout() | ||
} | ||
runtime { | ||
docker: "ubuntu:latest" | ||
} | ||
} | ||
|
||
task length { | ||
input { | ||
Int array_1_length | ||
Int array_4_length | ||
} | ||
command { | ||
echo ~{array_1_length} # 3 | ||
echo ~{array_4_length} # 2 | ||
} | ||
output { | ||
File out = stdout() | ||
} | ||
runtime { | ||
docker: "ubuntu:latest" | ||
} | ||
} | ||
|
||
task flatten { | ||
input { | ||
Array[String] array_flatten | ||
} | ||
command { | ||
cat ~{write_lines(array_flatten)} | ||
} | ||
output { | ||
File out = stdout() | ||
} | ||
runtime { | ||
docker: "ubuntu:latest" | ||
} | ||
} | ||
|
||
task prefix { | ||
input { | ||
Array[String] array_prefix | ||
} | ||
command { | ||
cat ~{write_lines(array_prefix)} | ||
} | ||
output { | ||
File out = stdout() | ||
} | ||
runtime { | ||
docker: "ubuntu:latest" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
red blue yellow | ||
purple green orange |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought you decided that you wanted to assert that there would be a newline added here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put the newline in that WDL command so that Cromwell output would match this output file. If you're referring to lack of new line at the end of file, I don't know what's right, I just wanted write_map() to give a similar format to array's write_lines()