Skip to content

Commit

Permalink
tests/generate: add support for custom epsilon as a string
Browse files Browse the repository at this point in the history
  • Loading branch information
vsergeev committed Dec 13, 2019
1 parent 5a83516 commit 854da52
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions tests/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def serialize(x):
"\n"
"jigs.TestBlock(radio.%s, {\n"
"%s"
"}, {epsilon = %.1e})\n",
"}, {epsilon = %s})\n",
"SourceSpec":
"-- Do not edit! This file was generated by %s\n"
"\n"
Expand All @@ -102,7 +102,7 @@ def serialize(x):
"\n"
"jigs.TestSourceBlock(radio.%s, {\n"
"%s"
"}, {epsilon = %.1e})\n",
"}, {epsilon = %s})\n",
"CompositeSpec":
"-- Do not edit! This file was generated by %s\n"
"\n"
Expand All @@ -111,7 +111,7 @@ def serialize(x):
"\n"
"jigs.TestCompositeBlock(radio.%s, {\n"
"%s"
"}, {epsilon = %.1e})\n",
"}, {epsilon = %s})\n",
"RawSpec":
"-- Do not edit! This file was generated by %s\n"
"\n"
Expand Down Expand Up @@ -140,7 +140,8 @@ def generate_spec(path, spec, dest):
serialized_inputs = ", ".join([serialize(e) for e in vector.inputs])
serialized_outputs = ", ".join([serialize(e) for e in vector.outputs])
serialized_vectors.append(spec_templates[vector.__class__.__name__] % (vector.desc, serialized_args, serialized_inputs, serialized_outputs))
s = spec_templates[spec.__class__.__name__] % (path, spec.name, "".join(serialized_vectors), spec.epsilon)
serialized_epsilon = spec.epsilon if isinstance(spec.epsilon, str) else "{:.1e}".format(spec.epsilon)
s = spec_templates[spec.__class__.__name__] % (path, spec.name, "".join(serialized_vectors), serialized_epsilon)

with open(dest, "w") as f:
f.write(s)
Expand Down

0 comments on commit 854da52

Please sign in to comment.