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

run tests for JSONInputs/*.json

parent 33c67d28
...@@ -20,9 +20,13 @@ ...@@ -20,9 +20,13 @@
from dream.simulation import LineGenerationJSON from dream.simulation import LineGenerationJSON
import json import json
import os import os
import glob
import tempfile import tempfile
from unittest import TestCase from unittest import TestCase
project_path = os.path.split(os.path.split(os.path.split(__file__)[0])[0])[0]
class SimulationTopology(TestCase): class SimulationTopology(TestCase):
""" """
Test topology files. The simulation is launched with files Topology01.json, Test topology files. The simulation is launched with files Topology01.json,
...@@ -33,19 +37,18 @@ class SimulationTopology(TestCase): ...@@ -33,19 +37,18 @@ class SimulationTopology(TestCase):
dump=1 python setup.py test 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 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 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. correct, you could commit, your new dumps will be used as new reference.
""" """
def setUp(self): 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(project_path, "dream", "tests", "dump")
self.dump_folder_path = os.path.join(self.project_path, "dream", "test", "dump")
def checkTopology(self, filename=None): def checkTopology(self, filename=None):
file_path = os.path.join(self.project_path, "dream", "simulation", file_path = os.path.join(project_path, "dream", "simulation",
"JSONInputs", "%s.json" % filename) "JSONInputs", filename)
input_file = open(file_path, "r") input_file = open(file_path, "r")
input_data = input_file.read() input_data = input_file.read()
input_file.close() input_file.close()
...@@ -66,10 +69,11 @@ class SimulationTopology(TestCase): ...@@ -66,10 +69,11 @@ class SimulationTopology(TestCase):
self.assertEquals(stable_result, dump_result, "outputs are different") self.assertEquals(stable_result, dump_result, "outputs are different")
# Automatically create a test method for every topology # 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(): def getTestTopology():
filename = "Topology%02i" % x def test_topology(self):
def test_topology(self):
self.checkTopology(filename=filename) self.checkTopology(filename=filename)
return test_topology 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