generate_scala_testcode.py 1.04 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/usr/bin/env python
from __future__ import print_function
import os
from glob import glob

scala_imports = """package eu.nomad_lab.parsers

import eu.nomad_lab.{ parsers, DefaultPythonInterpreter }
import org.scalacheck.Properties
import org.specs2.mutable.Specification
import org.{ json4s => jn }

"""

test_template = """\
    "test %(name)s " >> {
      "test with json-events" >> {
18
        ParserRun.parse(MolcasParser, "parsers/molcas/test/examples/%(name)s", "json-events") must_== ParseResult.ParseSuccess
19 20
      }
      "test with json" >> {
21
        ParserRun.parse(MolcasParser, "parsers/molcas/test/examples/%(name)s", "json") must_== ParseResult.ParseSuccess
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
      }
    }"""

fd = open('out.scala', 'w')

fd.write(scala_imports)

print('object MolcasParserSpec extends Specification {', file=fd)
print('  "MolcasParserTest" >> {', file=fd)

fnames = glob('test/test???.input.out')
fnames.sort()
for fname in fnames:
    fname = os.path.basename(fname)
    print(test_template % dict(name=fname), file=fd)

print('  }', file=fd)
print('}', file=fd)