Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mlin committed Nov 16, 2021
1 parent fb401bd commit c1d23ce
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
25 changes: 17 additions & 8 deletions WDL/Value.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import hashlib
from abc import ABC
from typing import Any, List, Optional, Tuple, Dict, Iterable, Union, Callable
from contextlib import suppress
from . import Error, Type, Env


Expand Down Expand Up @@ -185,9 +186,8 @@ def coerce(self, desired_type: Optional[Type.Base] = None) -> Base:
if isinstance(desired_type, Type.Float):
return Float(float(self.value), self.expr)
except ValueError as exn:
if self.expr:
raise Error.EvalError(self.expr, "coercing String to number: " + str(exn)) from exn
raise
msg = f"coercing String to {desired_type}: {exn}"
raise Error.EvalError(self.expr, msg) if self.expr else Error.RuntimeError(msg)
return super().coerce(desired_type)


Expand Down Expand Up @@ -454,7 +454,7 @@ def __init__(
except Error.RuntimeError:
msg = (
f"runtime type mismatch initializing struct member"
f"{str(type_members[k])} {k}"
f" {str(type_members[k])} {k}"
)
raise Error.EvalError(
expr,
Expand Down Expand Up @@ -489,17 +489,26 @@ def fail(msg):
assert isinstance(self.type, Type.Object)
key_type = desired_type.item_type[0]
if not Type.String().coerces(key_type):
fail(f"cannot coerce struct member names to {key_type}")
fail(f"cannot coerce member names to {key_type} map keys")
value_type = desired_type.item_type[1]
entries = []
for k, v in self.value.items():
if not (isinstance(v, Null) and value_type.optional):
if not self.type.members[k].coerces(value_type):
map_key = None
try:
map_key = String(k).coerce(key_type)
except Error.RuntimeError:
fail(f"cannot coerce member name {k} to {key_type} map key")
map_value = None
if self.type.members[k].coerces(value_type):
with suppress(Error.RuntimeError):
map_value = v.coerce(value_type)
if map_value is None:
fail(
"cannot coerce struct member"
f" {self.type.members[k]} {k} to {value_type}"
f" {self.type.members[k]} {k} to {value_type} map value"
)
entries.append((String(k).coerce(key_type), v.coerce(value_type)))
entries.append((map_key, map_value))
return Map(desired_type.item_type, entries)
if isinstance(desired_type, Type.Any):
return self
Expand Down
10 changes: 6 additions & 4 deletions tests/test_4taskrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,10 +811,11 @@ def test_runtime_memory_limit(self):
String memory
}
command <<<
cat /sys/fs/cgroup/memory/memory.limit_in_bytes
cat /sys/fs/cgroup/memory/memory.limit_in_bytes \
|| cat /sys/fs/cgroup/memory.max
>>>
output {
Int memory_limit_in_bytes = read_int(stdout())
String memory_limit_in_bytes = read_string(stdout())
}
runtime {
cpu: 1
Expand All @@ -824,10 +825,11 @@ def test_runtime_memory_limit(self):
"""
cfg = WDL.runtime.config.Loader(logging.getLogger(self.id()), [])
outputs = self._test_task(txt, {"memory": "256MB"}, cfg=cfg)
self.assertGreater(outputs["memory_limit_in_bytes"], 300*1024*1024)
if outputs["memory_limit_in_bytes"] != "max":
self.assertGreater(int(outputs["memory_limit_in_bytes"]), 300*1024*1024)
cfg.override({"task_runtime": {"memory_limit_multiplier": 0.9}})
outputs = self._test_task(txt, {"memory": "256MB"}, cfg=cfg)
self.assertLess(outputs["memory_limit_in_bytes"], 300*1024*1024)
self.assertLess(int(outputs["memory_limit_in_bytes"]), 300*1024*1024)

def test_runtime_returnCodes(self):
txt = R"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_5stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ def test_issue524(self):
>>>
output {
Map[Array[Float],String] data = read_json("data.json")
Map[Float,String] data = read_json("data.json")
}
}
""", expected_exception=WDL.Error.EvalError)
Expand Down

0 comments on commit c1d23ce

Please sign in to comment.