Commit 6cb4e6c6 authored by Jérome Perrin's avatar Jérome Perrin

run tests for JSONInputs/*.json

parent 33c67d28
......@@ -20,9 +20,13 @@
from dream.simulation import LineGenerationJSON
import json
import os
import glob
import tempfile
from unittest import TestCase
project_path = os.path.split(os.path.split(os.path.split(__file__)[0])[0])[0]
class SimulationTopology(TestCase):
"""
Test topology files. The simulation is launched with files Topology01.json,
......@@ -33,19 +37,18 @@ class SimulationTopology(TestCase):
dump=1 python setup.py test
This will regenerate all dump files in dream/test/dump/.
This will regenerate all dump files in dream/tests/dump/.
Then you can check carefully if all outputs are correct. You could use git
diff to check what is different. Once you are sure that your new dumps are
correct, you could commit, your new dumps will be used as new reference.
"""
def setUp(self):
self.project_path = os.path.split(os.path.split(os.path.split(__file__)[0])[0])[0]
self.dump_folder_path = os.path.join(self.project_path, "dream", "test", "dump")
self.dump_folder_path = os.path.join(project_path, "dream", "tests", "dump")
def checkTopology(self, filename=None):
file_path = os.path.join(self.project_path, "dream", "simulation",
"JSONInputs", "%s.json" % filename)
file_path = os.path.join(project_path, "dream", "simulation",
"JSONInputs", filename)
input_file = open(file_path, "r")
input_data = input_file.read()
input_file.close()
......@@ -66,10 +69,11 @@ class SimulationTopology(TestCase):
self.assertEquals(stable_result, dump_result, "outputs are different")
# Automatically create a test method for every topology
for x in range(1, 24):
for filepath in glob.glob(os.path.join(project_path, "dream", "simulation",
"JSONInputs", "*.json")):
filename = os.path.basename(filepath)
def getTestTopology():
filename = "Topology%02i" % x
def test_topology(self):
self.checkTopology(filename=filename)
return test_topology
setattr(SimulationTopology, "test_topology_%02i" % x, getTestTopology())
setattr(SimulationTopology, "test_%s" % filename, getTestTopology())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment