Skip to content

Commit

Permalink
more NameCollision cases and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mlin committed Nov 27, 2018
1 parent 58fb80a commit 2a032f7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 14 deletions.
46 changes: 43 additions & 3 deletions WDL/Lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,12 @@ class NameCollision(Linter):
# Name collisions between
# - call and import
# - call and decl
# - call and its containing workflow
# - decl and import
# - decl and workflow
# - decl and task
# - workflow and import
# - task and import
# These are allowed, but potentially confusing.
# TODO: cover scatter variables
def call(self, obj: WDL.Call) -> Any:
Expand All @@ -317,12 +322,15 @@ def call(self, obj: WDL.Call) -> Any:
doc = getattr(doc, "parent")
for _, namespace, _ in doc.imports:
if namespace == obj.name:
msg = "call name {} collides with imported document namespace".format(obj.name)
msg = "call name '{}' collides with imported document namespace".format(obj.name)
self.add(obj, msg)
if doc.workflow and doc.workflow.name == obj.name:
msg = "call name '{}' collides with workflow name".format(obj.name)
self.add(obj, msg)
type_env = getattr(obj, "parent")._type_env
try:
WDL.Env.resolve(type_env, [], obj.name)
msg = "call name {} collides with declared value".format(obj.name)
msg = "call name '{}' collides with declared value".format(obj.name)
self.add(obj, msg)
except KeyError:
pass
Expand All @@ -334,8 +342,39 @@ def decl(self, obj: WDL.Decl) -> Any:
doc = getattr(doc, "parent")
for _, namespace, _ in doc.imports:
if namespace == obj.name:
msg = "declaration of {} collides with imported document namespace".format(obj.name)
msg = "declaration of '{}' collides with imported document namespace".format(
obj.name
)
self.add(obj, msg)
if doc.workflow and doc.workflow.name == obj.name:
msg = "declaration of '{}' collides with workflow name".format(obj.name)
self.add(obj, msg)
for task in doc.tasks:
if obj.name == task.name:
msg = "declaration of '{}' collides with a task name".format(obj.name)
self.add(obj, msg)

def workflow(self, obj: WDL.Workflow) -> Any:
doc = obj
while not isinstance(doc, WDL.Document):
doc = getattr(doc, "parent")
for _, namespace, _ in doc.imports:
if namespace == obj.name:
msg = "workflow name '{}' collides with imported document namespace".format(
obj.name
)
self.add(obj, msg)
super().workflow(obj)

def task(self, obj: WDL.Task) -> Any:
doc = obj
while not isinstance(doc, WDL.Document):
doc = getattr(doc, "parent")
for _, namespace, _ in doc.imports:
if namespace == obj.name:
msg = "task name '{}' collides with imported document namespace".format(obj.name)
self.add(obj, msg)
super().task(obj)


@a_linter
Expand Down Expand Up @@ -433,3 +472,4 @@ def call(self, obj: WDL.Tree.Call) -> Any:
+ obj.name
+ " nor are are they output from the workflow",
)
super().call(obj)
15 changes: 9 additions & 6 deletions test_corpi/contrived/contrived.wdl
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
# examples contrived to cover obscured Linter code paths otherwise missed
# examples contrived to cover obscure Linter code paths otherwise missed
version 1.0

import "empty.wdl" as popular
import "empty.wdl" as contrived

workflow contrived {
String popular = "fox"
call echo as popular { input:
Int contrived = 42
call popular { input:
popular = popular,
i = 42
i = contrived,
y = contrived
}
}

task echo {
task popular {
String popular
String? opt
Float? i
String x = popular + opt
String y = popular + i
Array[String]+ y = select_all([popular + i])

command {
echo "~{popular}"
echo "${x} ${y}"
echo "${x} ${sep=';' y}"
}
}
10 changes: 5 additions & 5 deletions tests/test_3corpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class broad_prod_wgs(unittest.TestCase):
["test_corpi/broadinstitute/gtex-pipeline/**"],
# need URI import
blacklist=["rnaseq_pipeline_bam","rnaseq_pipeline_fastq"],
expected_lint={'IncompleteCall': 30, 'UnusedDeclaration': 3}
expected_lint={'IncompleteCall': 30, 'UnusedDeclaration': 3, 'NameCollision': 4},
)
class GTEx(unittest.TestCase):
pass
Expand All @@ -117,14 +117,14 @@ class TOPMed(unittest.TestCase):
@test_corpus(
["test_corpi/broadinstitute/viral-ngs/pipes/WDL/workflows"],
path=[["test_corpi/broadinstitute/viral-ngs/pipes/WDL/workflows/tasks"]],
expected_lint={'UnusedDeclaration': 23, 'IncompleteCall': 44, 'UnusedImport': 1}
expected_lint={'UnusedDeclaration': 23, 'NameCollision': 9, 'IncompleteCall': 44, 'UnusedImport': 1},
)
class ViralNGS(unittest.TestCase):
pass

@test_corpus(
["test_corpi/ENCODE-DCC/chip-seq-pipeline2/**"],
expected_lint={'StringCoercion': 192, 'ArrayCoercion': 64, 'OptionalCoercion': 64}
expected_lint={'StringCoercion': 192, 'NameCollision': 16, 'ArrayCoercion': 64, 'OptionalCoercion': 64},
)
class ENCODE_ChIPseq(unittest.TestCase):
pass
Expand Down Expand Up @@ -162,14 +162,14 @@ class ENCODE_WGBS(unittest.TestCase):
# double quantifier
"conditionals_base"
],
expected_lint={'UnusedDeclaration': 20, 'UnusedCall': 15}
expected_lint={'UnusedDeclaration': 20, 'UnusedCall': 15, 'NameCollision': 2}
)
class dxWDL(unittest.TestCase):
pass

@test_corpus(
["test_corpi/contrived/**"],
expected_lint= {'UnusedImport': 1, 'NameCollision': 4, 'OptionalCoercion': 2, 'StringCoercion': 1},
expected_lint={'UnusedImport': 2, 'NameCollision': 10, 'OptionalCoercion': 2, 'StringCoercion': 1, 'NonemptyArrayCoercion': 1, 'ArrayCoercion': 1},
)
class Contrived(unittest.TestCase):
pass

0 comments on commit 2a032f7

Please sign in to comment.