Browse Source

Fixed powerwindow test

Yentl Van Tendeloo 8 years ago
parent
commit
9f39335de9
2 changed files with 34 additions and 12 deletions
  1. 33 11
      integration/test_powerwindow.py
  2. 1 1
      wrappers/modelverse_SCCD.py

+ 33 - 11
integration/test_powerwindow.py

@@ -2,6 +2,8 @@ import unittest
 
 
 from utils import *
 from utils import *
 import sys
 import sys
+import os
+import shutil
 
 
 sys.path.append("wrappers")
 sys.path.append("wrappers")
 from modelverse import *
 from modelverse import *
@@ -62,17 +64,25 @@ class TestPowerWindow(unittest.TestCase):
         transformation_add_AL({"ReachabilityGraph": "formalisms/ReachabilityGraph"}, {}, "models/bfs", open("models/bfs.alc", 'r').read())
         transformation_add_AL({"ReachabilityGraph": "formalisms/ReachabilityGraph"}, {}, "models/bfs", open("models/bfs.alc", 'r').read())
         transformation_add_AL({"EPN_Plant": "formalisms/Encapsulated_PetriNet", "EPN_Control": "formalisms/Encapsulated_PetriNet", "EPN_Environment": "formalisms/Encapsulated_PetriNet"}, {"Encapsulated_PetriNet": "formalisms/Encapsulated_PetriNet"}, "models/merge_EPN", open("models/merge_EPN.alc", 'r').read())
         transformation_add_AL({"EPN_Plant": "formalisms/Encapsulated_PetriNet", "EPN_Control": "formalisms/Encapsulated_PetriNet", "EPN_Environment": "formalisms/Encapsulated_PetriNet"}, {"Encapsulated_PetriNet": "formalisms/Encapsulated_PetriNet"}, "models/merge_EPN", open("models/merge_EPN.alc", 'r').read())
 
 
-        global called
-        called = 0
         nr_of_operations = 6
         nr_of_operations = 6
 
 
+        try:
+            shutil.rmtree(".TEST_POWER_WINDOW")
+        except:
+            pass
+        os.makedirs(".TEST_POWER_WINDOW")
+
         def get_function(filename):
         def get_function(filename):
             def func(model):
             def func(model):
-                global called
+                import uuid
+                import os
+                called = len(os.listdir(".TEST_POWER_WINDOW/"))
                 if called > nr_of_operations:
                 if called > nr_of_operations:
                     raise Exception("Seemingly called some operation twice!")
                     raise Exception("Seemingly called some operation twice!")
                 else:
                 else:
-                    called += 1
+                    f = open(".TEST_POWER_WINDOW/%s" % str(uuid.uuid4()), 'w')
+                    f.write(filename)
+                    f.close()
                 model_overwrite(model, open(filename, "r").read())
                 model_overwrite(model, open(filename, "r").read())
             return func
             return func
 
 
@@ -98,6 +108,8 @@ class TestPowerWindow(unittest.TestCase):
             import traceback
             import traceback
             print(traceback.format_exc())
             print(traceback.format_exc())
 
 
+        called = len(os.listdir(".TEST_POWER_WINDOW/"))
+        shutil.rmtree(".TEST_POWER_WINDOW")
         if called != 6:
         if called != 6:
             print(called)
             print(called)
             raise Exception("Not executed sufficiently:" + str(called))
             raise Exception("Not executed sufficiently:" + str(called))
@@ -153,21 +165,28 @@ class TestPowerWindow(unittest.TestCase):
         #transformation_add_AL({"Encapsulated_PetriNet": "Encapsulated_PetriNet"}, {}, "epn_print", open("models/epn_print.alc").read())
         #transformation_add_AL({"Encapsulated_PetriNet": "Encapsulated_PetriNet"}, {}, "epn_print", open("models/epn_print.alc").read())
         #transformation_add_AL({"PetriNet": "PetriNet"}, {}, "pn_print", open("models/pn_print.alc").read())
         #transformation_add_AL({"PetriNet": "PetriNet"}, {}, "pn_print", open("models/pn_print.alc").read())
 
 
-        global called
-        called = 0
+        try:
+            shutil.rmtree(".TEST_POWER_WINDOW")
+        except:
+            pass
+        os.makedirs(".TEST_POWER_WINDOW")
+
         executed = set([])
         executed = set([])
 
 
         def get_function(filename, fixed=None):
         def get_function(filename, fixed=None):
             def func(model):
             def func(model):
-                global called
-                if called > len(callbacks) * 2:
+                import uuid
+                import os
+                nr_operations = 11
+                called = len(os.listdir(".TEST_POWER_WINDOW/"))
+                if (len(os.listdir(".TEST_POWER_WINDOW")) > nr_operations):
                     raise Exception("Seemingly called some operation twice!")
                     raise Exception("Seemingly called some operation twice!")
-                called += 1
-                if filename not in executed or fixed is None:
-                    executed.add(filename)
+                elif (len(glob.glob(".TEST_POWER_WINDOW/%s_*" % str(filename))) == 0) or fixed is None:
                     model_overwrite(model, open(filename, "r").read())
                     model_overwrite(model, open(filename, "r").read())
                 else:
                 else:
                     model_overwrite(model, open(fixed, "r").read())
                     model_overwrite(model, open(fixed, "r").read())
+
+                open(".TEST_POWER_WINDOW/%s_%s" % str(filename, uuid.uuid4()), 'w').close()
             return func
             return func
 
 
         cb_req = get_function("models/requirements_model.mvc")
         cb_req = get_function("models/requirements_model.mvc")
@@ -198,6 +217,9 @@ class TestPowerWindow(unittest.TestCase):
 
 
         thrd.join()
         thrd.join()
 
 
+        called = len(os.listdir(".TEST_POWER_WINDOW"))
+        shutil.rmtree(".TEST_POWER_WINDOW")
+
         if called != 11:
         if called != 11:
             print(called)
             print(called)
             raise Exception("Not executed sufficiently:" + str(called))
             raise Exception("Not executed sufficiently:" + str(called))

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
-Date:   Wed Nov 22 16:27:05 2017
+Date:   Thu Nov 23 08:18:26 2017
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server