Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Testing of object, map, and array literals #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .gitignore
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/
7 changes: 7 additions & 0 deletions pytest-wdl-tests/tests/literals/data/array_literals_out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
INTS
0
1
2
STRINGS
array
literal
6 changes: 6 additions & 0 deletions pytest-wdl-tests/tests/literals/data/map_literals_out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
INTS
1 10
2 11
MIXED
a 1
b 2
Copy link
Contributor

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?

Copy link
Author

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()

2 changes: 2 additions & 0 deletions pytest-wdl-tests/tests/literals/data/object_literals_out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a b
10 11
6 changes: 6 additions & 0 deletions pytest-wdl-tests/tests/literals/data/object_map_coercion_out
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
1 change: 1 addition & 0 deletions pytest-wdl-tests/tests/literals/data/pair_literals_out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
23 twenty-three
157 changes: 157 additions & 0 deletions pytest-wdl-tests/tests/literals/literals.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# 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()
}
}

task map_literals {
input {
File map_literal_ints
File map_literal_mixed
}
command {
set -e

echo INTS
cat ~{map_literal_ints}
printf "\nMIXED\n"
cat ~{map_literal_mixed}
}
output {
File map_literals_out = stdout()
}
}

task object_literals {
input {
File object_literal
}
command {
set -e

cat ~{object_literal}
}
output {
File object_literals_out = stdout()
}
}

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()
}
}

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()
}
}
3 changes: 3 additions & 0 deletions pytest-wdl-tests/tests/literals/test_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this if the file is empty?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileNotFoundError: Could not find any of test_data.json,tests/test_data.json starting from /Users/jggatter/Desktop/Projects/Testathon-2020/pytest-wdl-tests/tests/whitespace

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?

}

4 changes: 4 additions & 0 deletions pytest-wdl-tests/tests/literals/test_literals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def test_literals(workflow_data, workflow_runner):
inputs = {}
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", inputs, expected, workflow_name="literals")
2 changes: 2 additions & 0 deletions pytest-wdl-tests/tests/whitespace/data/spaces_out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
I am a document. I am all spaces. Let me pass!
Look now I'm in this python heredoc! I am a document. I am all spaces. Let me pass!
2 changes: 2 additions & 0 deletions pytest-wdl-tests/tests/whitespace/data/tabs_out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
I am a document. I am all tabs. Let me pass!
Look now I'm in this python heredoc! I am a document. I am all tabs. Let me pass!
31 changes: 31 additions & 0 deletions pytest-wdl-tests/tests/whitespace/indented_heredoc.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow has tab indents and one extra indent at the heredoc! It is intended to fail miserably.

version 1.0

workflow indented_heredoc {
input {
String message = "I am a document. I am indented incorrectly at the heredoc. Let me fail!"
}
call t {
input: message=message
}
output {
File indented_heredoc_out = t.out
}
}

task t {
input {
String message
}
command {
echo ~{message}
python <<CODE
for i in range(0,1):
print("Look now I'm in this python heredoc! ~{message}")
CODE
}
output {
File out = stdout()
}
}
31 changes: 31 additions & 0 deletions pytest-wdl-tests/tests/whitespace/mixed.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow has 2-space indents and one tab at the heredoc! It is intended to fail miserably.

version 1.0

workflow mixed {
input {
String message = "I am a document. I am mixed. Let me fail!"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? This looks fine to me?

If I'm reading this right: The engine will strip the common spacing from the start of the command section, and then the python heredoc will have a single tab indentation in it?

Copy link
Author

@jggatter jggatter Feb 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to read task definition at line 17 column 6 (reason 1 of 1): Cannot mix leading whitespace characters in command: [" ", "\t"]

I get this error message, I believe it fails because of the tab in the heredoc
I did also try a version where I put a tab on line 6 or 7 and that failed similarly

}
call t {
input: message=message
}
output {
File mixed_out = t.out
}
}

task t {
input {
String message
}
command {
echo ~{message}
python <<CODE
for i in range(0,1):
print("Look now I'm in this python heredoc! ~{message}")
CODE
}
output {
File out = stdout()
}
}
16 changes: 16 additions & 0 deletions pytest-wdl-tests/tests/whitespace/proper_whitespace.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This main workflow is all tab-indented, but it calls both a tab-indented and a 2-space indented subworkflow.
# It is intended to run successfully.

version 1.0

import "tabs.wdl" as t
import "spaces.wdl" as s

workflow proper_whitespace {
call t.tabs as tabs
call s.spaces as spaces
output {
File tabs_out = tabs.tabs_out
File spaces_out = spaces.spaces_out
}
}
31 changes: 31 additions & 0 deletions pytest-wdl-tests/tests/whitespace/spaces.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow is all 2-space-indented, it is intended to run successfully.

version 1.0

workflow spaces {
input {
String message = "I am a document. I am all spaces. Let me pass!"
}
call t {
input: message=message
}
output {
File spaces_out = t.out
}
}

task t {
input {
String message
}
command {
echo ~{message}
python <<CODE
for i in range(0,1):
print("Look now I'm in this python heredoc! ~{message}")
CODE
}
output {
File out = stdout()
}
}
31 changes: 31 additions & 0 deletions pytest-wdl-tests/tests/whitespace/tabs.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow is all tab-indented, it is intended to run successfully.

version 1.0

workflow tabs {
input {
String message = "I am a document. I am all tabs. Let me pass!"
}
call t {
input: message=message
}
output {
File tabs_out = t.out
}
}

task t {
input {
String message
}
command {
echo ~{message}
python <<CODE
for i in range(0,1):
print("Look now I'm in this python heredoc! ~{message}")
CODE
}
output {
File out = stdout()
}
}
2 changes: 2 additions & 0 deletions pytest-wdl-tests/tests/whitespace/test_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
Loading