test_constructors_models_compiled.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 = ['"initialize_SCD"', '"models/SimpleClassDiagrams"'] + \
  34. model_compile("integration/code/petrinets.mvc") + \
  35. ['"exit"', '1'] + conformance_check("models/PetriNets") + ['"return"', 'false']
  36. self.assertTrue(run_barebone(commands, ["OK"], 4))
  37. def test_constructors_petrinet_instance(self):
  38. commands = ['"initialize_SCD"', '"models/SimpleClassDiagrams"'] + \
  39. model_compile("integration/code/petrinets.mvc") + \
  40. model_compile("integration/code/my_petrinet.mvc") + \
  41. ['"exit"', '1'] + conformance_check("models/my_petrinet") + ['"return"', 'false']
  42. self.assertTrue(run_barebone(commands, ["OK"], 4))
  43. def test_constructors_petrinet_full(self):
  44. commands = ['"initialize_SCD"', '"models/SimpleClassDiagrams"'] + \
  45. model_compile("integration/code/my_petrinet_with_MM.mvc") + \
  46. ['"exit"', '1'] + conformance_check("models/my_petrinet") + ['"return"', 'false']
  47. self.assertTrue(run_barebone(commands, ["OK"], 4))
  48. def test_constructors_petrinets_constraints(self):
  49. commands = ['"initialize_SCD"', '"models/SimpleClassDiagrams"'] + \
  50. model_compile("integration/code/petrinets_constraints.mvc") + \
  51. ['"exit"', '1'] + conformance_check("models/PetriNets") + ['"return"', 'false']
  52. self.assertTrue(run_barebone(commands, ["OK"], 4))
  53. def test_constructors_petrinet_instance_constraints(self):
  54. commands = ['"initialize_SCD"', '"models/SimpleClassDiagrams"'] + \
  55. model_compile("integration/code/petrinets_constraints.mvc") + \
  56. model_compile("integration/code/my_petrinet.mvc") + \
  57. ['"exit"', '1'] + conformance_check("models/my_petrinet") + ['"return"', 'false']
  58. self.assertTrue(run_barebone(commands, ["OK"], 4))
  59. def test_constructors_petrinet_full_constraints(self):
  60. commands = ['"initialize_SCD"', '"models/SimpleClassDiagrams"'] + \
  61. model_compile("integration/code/my_petrinet_with_MM_and_constraints.mvc") + \
  62. ['"exit"', '1'] + conformance_check("models/my_petrinet") + ['"return"', 'false']
  63. self.assertTrue(run_barebone(commands, ["OK"], 4))
  64. def test_constructors_petrinet_invalids(self):
  65. commands = ['"initialize_SCD"', '"models/SimpleClassDiagrams"'] + \
  66. model_compile("integration/code/several_petrinets.mvc") + \
  67. ['"exit"', '1'] + \
  68. conformance_check("models/valid_petrinet") + \
  69. conformance_check("models/invalid_petrinet_1") + \
  70. conformance_check("models/invalid_petrinet_2") + \
  71. conformance_check("models/invalid_petrinet_3") + \
  72. conformance_check("models/invalid_petrinet_4") + \
  73. conformance_check("models/invalid_petrinet_5") + \
  74. conformance_check("models/invalid_petrinet_6") + \
  75. conformance_check("models/invalid_petrinet_7") + \
  76. ['"return"', 'false']
  77. self.assertTrue(run_barebone(commands, ["OK",
  78. "Natural does not have a positive or zero value at p1.tokens",
  79. "Natural does not have a positive or zero value at p2t.weight",
  80. "Destination of model edge not typed by source of type: wrong_p2t",
  81. "Source of model edge not typed by source of type: wrong_t2p",
  82. "Lower cardinality violation for outgoing edge of type Place_tokens at p1",
  83. "Lower cardinality violation for outgoing edge of type P2T_weight at p2t",
  84. "Natural has no integer value at p1.tokens"], 4))