test_constructors_models_compiled.py 4.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import unittest
  2. import sys
  3. import os
  4. from utils import execute, kill, run_file, run_barebone
  5. sys.path.append("interface/HUTN")
  6. from hutn_compiler.compiler import main as do_compile
  7. def model_compile(filename):
  8. return do_compile(filename, "interface/HUTN/grammars/modelling.g", "M")
  9. def conformance_call(operation, model, metamodel):
  10. return [
  11. '"output"',
  12. '"call"',
  13. '"access"', '"resolve"', '"%s"' % operation,
  14. '3',
  15. '"call"', '"access"', '"resolve"', '"import_node"', '1', '"const"', '"models/example_M"', 'false',
  16. '"const"', '"%s"' % model,
  17. '"const"', '"%s"' % metamodel,
  18. 'false',
  19. 'true',
  20. ]
  21. def conformance_check(node):
  22. return [
  23. '"output"',
  24. '"call"',
  25. '"access"', '"resolve"', '"conformance_scd"',
  26. '1',
  27. '"call"', '"access"', '"resolve"', '"import_node"', '1', '"const"', '"%s"' % (node), 'false',
  28. 'false',
  29. 'true',
  30. ]
  31. class TestConstructorsModelsCompiled(unittest.TestCase):
  32. def test_constructors_petrinets(self):
  33. commands = ['"model"' ,'"initialize_SCD"', '"models/SimpleClassDiagrams"', '"exit"'] + \
  34. model_compile("integration/code/petrinets.mvc") + \
  35. conformance_check("models/PetriNets") + \
  36. ['"return"', 'false']
  37. self.assertTrue(run_barebone(commands, ["OK"], 1))
  38. def test_constructors_petrinet_instance(self):
  39. commands = ['"model"' ,'"initialize_SCD"', '"models/SimpleClassDiagrams"', '"exit"'] + \
  40. model_compile("integration/code/petrinets.mvc") + \
  41. model_compile("integration/code/my_petrinet.mvc") + \
  42. conformance_check("models/my_petrinet") + \
  43. ['"return"', 'false']
  44. self.assertTrue(run_barebone(commands, ["OK"], 1))
  45. def test_constructors_petrinet_full(self):
  46. commands = ['"model"' ,'"initialize_SCD"', '"models/SimpleClassDiagrams"', '"exit"'] + \
  47. model_compile("integration/code/my_petrinet_with_MM.mvc") + \
  48. conformance_check("models/my_petrinet") + \
  49. ['"return"', 'false']
  50. self.assertTrue(run_barebone(commands, ["OK"], 1))
  51. def test_constructors_petrinets_constraints(self):
  52. commands = ['"model"' ,'"initialize_SCD"', '"models/SimpleClassDiagrams"', '"exit"'] + \
  53. model_compile("integration/code/petrinets_constraints.mvc") + \
  54. conformance_check("models/PetriNets") + \
  55. ['"return"', 'false']
  56. self.assertTrue(run_barebone(commands, ["OK"], 1))
  57. def test_constructors_petrinet_instance_constraints(self):
  58. commands = ['"model"' ,'"initialize_SCD"', '"models/SimpleClassDiagrams"', '"exit"'] + \
  59. model_compile("integration/code/petrinets_constraints.mvc") + \
  60. model_compile("integration/code/my_petrinet.mvc") + \
  61. conformance_check("models/my_petrinet") + \
  62. ['"return"', 'false']
  63. self.assertTrue(run_barebone(commands, ["OK"], 1))
  64. def test_constructors_petrinet_full_constraints(self):
  65. commands = ['"model"' ,'"initialize_SCD"', '"models/SimpleClassDiagrams"', '"exit"'] + \
  66. model_compile("integration/code/my_petrinet_with_MM_and_constraints.mvc") + \
  67. conformance_check("models/my_petrinet") + \
  68. ['"return"', 'false']
  69. self.assertTrue(run_barebone(commands, ["OK"], 1))
  70. def test_constructors_petrinet_invalids(self):
  71. commands = ['"model"' ,'"initialize_SCD"', '"models/SimpleClassDiagrams"', '"exit"'] + \
  72. model_compile("integration/code/several_petrinets.mvc") + \
  73. conformance_check("models/valid_petrinet") + \
  74. conformance_check("models/invalid_petrinet_1") + \
  75. conformance_check("models/invalid_petrinet_2") + \
  76. conformance_check("models/invalid_petrinet_3") + \
  77. conformance_check("models/invalid_petrinet_4") + \
  78. conformance_check("models/invalid_petrinet_5") + \
  79. conformance_check("models/invalid_petrinet_6") + \
  80. conformance_check("models/invalid_petrinet_7") + \
  81. ['"return"', 'false']
  82. self.assertTrue(run_barebone(commands, ["OK", "Natural does not have a positive or zero value at p1.tokens", "Natural does not have a positive or zero value at p2t.weight", "Destination of model edge not typed by source of type: wrong_p2t", "Source of model edge not typed by source of type: wrong_t2p", "Lower cardinality violation for outgoing edge of type Place_tokens at p1", "Lower cardinality violation for outgoing edge of type P2T_weight at p2t", "Natural has no integer value at p1.tokens"], 1))