123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818 |
- import unittest
- import sys
- import os
- from utils import execute, kill, run_file, run_barebone
- def flatten(lst):
- new_lst = []
- for f in lst:
- if isinstance(f, (list, tuple)):
- new_lst.extend(flatten(f))
- else:
- new_lst.append(f)
- return new_lst
- bottom = ['"instantiate_bottom"',
- '"node"', '"Class"', 'true',
- '"node"', '"Type"', 'true',
- '"node"', '"__String"', 'true',
- '"value"', '"__name"', '"name"', 'true',
- '"edge"', '"Attribute"', '"Class"', '"Type"', 'true',
- '"edge"', '"__Name"', '"Attribute"', '"__String"', 'true',
- '"edge"', '"Association"', '"Class"', '"Class"', 'true',
- '"edge"', '"Inheritance"', '"Class"', '"Class"', 'true',
- '"edge"', '"__name_edge"', '"__Name"', '"__name"', 'true',
- '"edge"', '"__inh_1"', '"Association"', '"Class"', 'true',
- '"edge"', '"__inh_2"', '"Attribute"', '"Class"', 'true',
- '"value"', '"__attribute"', '"attribute"', 'true',
- '"edge"', '"__attribute_edge"', '"Attribute"', '"__attribute"', 'false',
- 1,
- ]
- retype = ['"retype_model"',
- 1,
- 1,
- 1, '"Inheritance"',
- 'true',
- '"Class"', '"Class"', 'true',
- '"Type"', '"Type"', 'true',
- '"__String"', '"Type"', 'true',
- '"Attribute"', '"Attribute"', 'true',
- '"__Name"', '"Attribute"', 'true',
- '"Association"', '"Association"', 'true',
- '"Inheritance"', '"Association"', 'true',
- '"__inh_1"', '"Inheritance"', 'true',
- '"__inh2"', '"Inheritance"', 'true',
- '"__name"', '"__String"', 'true',
- '"__name_edge"', '"__Name"', 'true',
- '"__attribute"', '"__String"', 'true',
- '"__attribute_edge"', '"__Name"', 'false',
- ]
- def function_call(func, paramA, paramB):
- return ['"output"', '"call"',
- '"access"',
- '"resolve"', '"%s"' % func,
- '3',
- '"const"', 3,
- '"call"',
- '"access"',
- '"resolve"', '"dict_read"',
- '2',
- '"call"',
- '"access"',
- '"resolve"', '"dict_read"',
- '2',
- '"const"', 3,
- '"const"', '"model"',
- 'false',
- '"const"', '"%s"' % paramA,
- 'false',
- '"call"',
- '"access"',
- '"resolve"', '"dict_read"',
- '2',
- '"call"',
- '"access"',
- '"resolve"', '"dict_read"',
- '2',
- '"const"', 2,
- '"const"', '"model"',
- 'false',
- '"const"', '"%s"' % paramB,
- 'false',
- 'false',
- 'true',
- ]
-
- class TestConstructorsModels(unittest.TestCase):
- def test_constructors_instantiate_bottom(self):
- commands = bottom + [
- '"output"', '"const"', '3',
- 'true',
- '"return"', 'true',
- '"const"', 'true',
- ]
- self.assertTrue(run_barebone(flatten(commands), ['3'], 1))
- def test_constructors_instantiate_model(self):
- commands = bottom + [
- '"instantiate_model"',
- 1,
- 1, '"Inheritance"',
- '"Type"', '"Integer"',
- 'false',
- 'false',
- 'true',
- '"Class"', '"Place"',
- 'true',
- '"tokens"', '"Integer"', 'false',
- 'false',
- 'true',
- '"Class"', '"Transition"',
- 'false',
- 'false',
- 'true',
- '"Association"', '"P2T"', '"Place"', '"Transition"',
- 'true',
- '"weight"', '"Integer"', 'false',
- 'false',
- 'true',
- '"Association"', '"T2P"', '"Transition"', '"Place"',
- 'true',
- '"weight"', '"Integer"', 'false',
- 'false',
- 'false',
- 2,
- '"instantiate_model"',
- 2,
- 1, '"Inheritance"',
- '"Place"', '"p1"',
- 'false',
- 'true',
- '"tokens"', '5', 'false',
- 'true',
- '"Transition"', '"t1"',
- 'false',
- 'false',
- 'true',
- '"P2T"', '""', '"p1"', '"t1"',
- 'false',
- 'true',
- '"weight"', '1', 'false',
- 'true',
- '"T2P"', '""', '"t1"', '"p1"',
- 'false',
- 'true',
- '"weight"', '2', 'false',
- 'false',
- 3,
- '"output"', '"const"', '3',
- 'true',
- '"return"', 'true',
- '"const"', 'true',
- ]
- self.assertTrue(run_barebone(flatten(commands), ['3'], 1))
- def test_constructors_retype_model(self):
- commands = bottom + retype + [
- '"output"', '"const"', '3',
- 'true',
- '"return"', 'true',
- '"const"', 'true',
- ]
- self.assertTrue(run_barebone(flatten(commands), ['3'], 1))
- def test_constructors_instantiate_model_inheritance(self):
- commands = bottom + [
- '"instantiate_model"',
- 1,
- 1, '"Inheritance"',
- '"Class"', '"A"',
- 'true',
- '"a"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Class"', '"B"',
- 'true',
- '"b"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Inheritance"', '"b_inherits_from_a"', '"B"', '"A"',
- 'false',
- 'false',
- 'false',
- 2,
- '"instantiate_model"',
- 2,
- 1, '"Inheritance"',
- '"A"', '"a1"',
- 'false',
- 'true',
- '"a"', '1', 'false',
- 'true',
- '"B"', '"b1"',
- 'false',
- 'true',
- '"a"', '2', 'true',
- '"b"', '3', 'false',
- 'false',
- 3,
- '"output"', '"const"', '3',
- 'true',
- '"return"', 'true',
- '"const"', 'true',
- ]
- self.assertTrue(run_barebone(flatten(commands), ['3'], 1))
- def test_constructors_conformance_metametamodel(self):
- commands = bottom + retype + [
- '"output"', '"call"',
- '"access"',
- '"resolve"', '"conformance_scd"',
- '1',
- '"const"', 1,
- 'false',
- 'true',
- '"return"', 'true',
- '"const"', 'true',
- ]
- self.assertTrue(run_barebone(flatten(commands), ['OK'], 1))
- def test_constructors_conformance_metamodel(self):
- commands = bottom + retype + [
- '"instantiate_model"',
- 1,
- 1, '"Inheritance"',
- '"Class"', '"Place"',
- 'true',
- '"tokens"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Class"', '"Transition"',
- 'false',
- 'false',
- 'true',
- '"Association"', '"P2T"', '"Place"', '"Transition"',
- 'true',
- '"weight"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Association"', '"T2P"', '"Transition"', '"Place"',
- 'true',
- '"weight"', '{"value": "Integer"}', 'false',
- 'false',
- 'false',
- 2,
- '"output"', '"call"',
- '"access"',
- '"resolve"', '"conformance_scd"',
- '1',
- '"const"', 2,
- 'false',
- 'true',
- '"return"', 'true',
- '"const"', 'true',
- ]
- self.assertTrue(run_barebone(flatten(commands), ['OK'], 1))
- def test_constructors_conformance_model(self):
- commands = bottom + retype + [
- '"instantiate_model"',
- 1,
- 1, '"Inheritance"',
- '"Class"', '"Place"',
- 'true',
- '"tokens"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Class"', '"Transition"',
- 'false',
- 'false',
- 'true',
- '"Association"', '"P2T"', '"Place"', '"Transition"',
- 'true',
- '"weight"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Association"', '"T2P"', '"Transition"', '"Place"',
- 'true',
- '"weight"', '{"value": "Integer"}', 'false',
- 'false',
- 'false',
- 2,
- '"instantiate_model"',
- 2,
- 1, '"Inheritance"',
- '"Place"', '"p1"',
- 'false',
- 'true',
- '"tokens"', '5', 'false',
- 'true',
- '"Transition"', '"t1"',
- 'false',
- 'false',
- 'true',
- '"P2T"', '""', '"p1"', '"t1"',
- 'false',
- 'true',
- '"weight"', '1', 'false',
- 'true',
- '"T2P"', '""', '"t1"', '"p1"',
- 'false',
- 'true',
- '"weight"', '2', 'false',
- 'false',
- 3,
- '"output"', '"call"',
- '"access"',
- '"resolve"', '"conformance_scd"',
- '1',
- '"const"', 3,
- 'false',
- 'true',
- '"return"', 'true',
- '"const"', 'true',
- ]
- self.assertTrue(run_barebone(flatten(commands), ['OK'], 1))
- def test_constructors_is_direct_instance(self):
- commands = bottom + retype + [
- '"instantiate_model"',
- 1,
- 1, '"Inheritance"',
- '"Class"', '"A"',
- 'true',
- '"a"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Class"', '"B"',
- 'true',
- '"b"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Class"', '"C"',
- 'true',
- '"b"', '{"value": "Integer"}', 'true',
- '"c"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Inheritance"', '"__inh_1"', '"A"', '"B"',
- 'false',
- 'false',
- 'false',
- 2,
- '"instantiate_model"',
- 2,
- 1, '"Inheritance"',
- '"A"', '"a"',
- 'false',
- 'true',
- '"a"', '1', 'true',
- '"b"', '1', 'false',
- 'true',
- '"B"', '"b"',
- 'false',
- 'true',
- '"b"', '1', 'false',
- 'true',
- '"C"', '"c"',
- 'false',
- 'true',
- '"b"', '1', 'true',
- '"c"', '1', 'false',
- 'false',
- 3,
- ] + \
- function_call("is_direct_instance", "a", "A") + \
- function_call("is_direct_instance", "a", "B") + \
- function_call("is_direct_instance", "a", "C") + \
- function_call("is_direct_instance", "b", "A") + \
- function_call("is_direct_instance", "b", "B") + \
- function_call("is_direct_instance", "b", "C") + \
- function_call("is_direct_instance", "c", "A") + \
- function_call("is_direct_instance", "c", "B") + \
- function_call("is_direct_instance", "c", "C") + \
- ['"return"', 'true',
- '"const"', 'true',
- ]
- # Test in order:
- # a : A --> Yes
- # a : B --> No
- # a : C --> No
- # b : A --> No
- # b : B --> Yes
- # b : C --> No
- # c : A --> No
- # c : B --> No
- # c : C --> Yes
- self.assertTrue(run_barebone(flatten(commands), ['True', 'False', 'False', 'False', 'True', 'False', 'False', 'False', 'True'], 1))
- def test_constructors_is_nominal_instance(self):
- commands = bottom + retype + [
- '"instantiate_model"',
- 1,
- 1, '"Inheritance"',
- '"Class"', '"A"',
- 'true',
- '"a"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Class"', '"B"',
- 'true',
- '"b"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Class"', '"C"',
- 'true',
- '"b"', '{"value": "Integer"}', 'true',
- '"c"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Inheritance"', '"__inh_1"', '"A"', '"B"',
- 'false',
- 'false',
- 'false',
- 2,
- '"instantiate_model"',
- 2,
- 1, '"Inheritance"',
- '"A"', '"a"',
- 'false',
- 'true',
- '"a"', '1', 'true',
- '"b"', '1', 'false',
- 'true',
- '"B"', '"b"',
- 'false',
- 'true',
- '"b"', '1', 'false',
- 'true',
- '"C"', '"c"',
- 'false',
- 'true',
- '"b"', '1', 'true',
- '"c"', '1', 'false',
- 'false',
- 3, ] + \
- function_call("is_nominal_instance", "a", "A") + \
- function_call("is_nominal_instance", "a", "B") + \
- function_call("is_nominal_instance", "a", "C") + \
- function_call("is_nominal_instance", "b", "A") + \
- function_call("is_nominal_instance", "b", "B") + \
- function_call("is_nominal_instance", "b", "C") + \
- function_call("is_nominal_instance", "c", "A") + \
- function_call("is_nominal_instance", "c", "B") + \
- function_call("is_nominal_instance", "c", "C") + \
- [ '"return"', 'true',
- '"const"', 'true',
- ]
- # Test in order:
- # a : A --> Yes
- # a : B --> Yes
- # a : C --> No
- # b : A --> No
- # b : B --> Yes
- # b : C --> No
- # c : A --> No
- # c : B --> No
- # c : C --> Yes
- self.assertTrue(run_barebone(flatten(commands), ['True', 'True', 'False', 'False', 'True', 'False', 'False', 'False', 'True'], 1))
- def test_constructors_is_structural_instance(self):
- commands = bottom + retype + [
- '"instantiate_model"',
- 1,
- 1, '"Inheritance"',
- '"Class"', '"A"',
- 'true',
- '"a"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Class"', '"B"',
- 'true',
- '"b"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Class"', '"C"',
- 'true',
- '"b"', '{"value": "Integer"}', 'true',
- '"c"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Inheritance"', '"__inh_1"', '"A"', '"B"',
- 'false',
- 'false',
- 'false',
- 2,
- '"instantiate_model"',
- 2,
- 1, '"Inheritance"',
- '"A"', '"a"',
- 'false',
- 'true',
- '"a"', '1', 'false',
- 'true',
- '"B"', '"b"',
- 'false',
- 'true',
- '"b"', '1', 'false',
- 'true',
- '"C"', '"c"',
- 'false',
- 'true',
- '"b"', '1', 'true',
- '"c"', '1', 'false',
- 'false',
- 3, ] + \
- function_call("is_structural_instance", "a", "A") + \
- function_call("is_structural_instance", "a", "B") + \
- function_call("is_structural_instance", "a", "C") + \
- function_call("is_structural_instance", "b", "A") + \
- function_call("is_structural_instance", "b", "B") + \
- function_call("is_structural_instance", "b", "C") + \
- function_call("is_structural_instance", "c", "A") + \
- function_call("is_structural_instance", "c", "B") + \
- function_call("is_structural_instance", "c", "C") + \
- [ '"return"', 'true',
- '"const"', 'true',
- ]
- # Test in order:
- # a : A --> Yes
- # a : B --> No
- # a : C --> No
- # b : A --> No
- # b : B --> Yes
- # b : C --> No
- # c : A --> No
- # c : B --> Yes
- # c : C --> Yes
- self.assertTrue(run_barebone(flatten(commands), ['True', 'False', 'False', 'False', 'True', 'False', 'False', 'True', 'True'], 1))
- def test_constructors_readAttribute(self):
- commands = bottom + retype + [
- '"instantiate_model"',
- 1,
- 1, '"Inheritance"',
- '"Class"', '"Place"',
- 'true',
- '"tokens"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Class"', '"Transition"',
- 'false',
- 'false',
- 'true',
- '"Association"', '"P2T"', '"Place"', '"Transition"',
- 'true',
- '"weight"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Association"', '"T2P"', '"Transition"', '"Place"',
- 'true',
- '"weight"', '{"value": "Integer"}', 'false',
- 'false',
- 'false',
- 2,
- '"instantiate_model"',
- 2,
- 1, '"Inheritance"',
- '"Place"', '"p1"',
- 'false',
- 'true',
- '"tokens"', '5', 'false',
- 'true',
- '"Transition"', '"t1"',
- 'false',
- 'false',
- 'true',
- '"P2T"', '"arc1"', '"p1"', '"t1"',
- 'false',
- 'true',
- '"weight"', '1', 'false',
- 'true',
- '"T2P"', '"arc2"', '"t1"', '"p1"',
- 'false',
- 'true',
- '"weight"', '2', 'false',
- 'false',
- 3,
- '"output"', '"call"',
- '"access"',
- '"resolve"', '"readAttribute"',
- '3',
- '"const"', 3,
- '"call"',
- '"access"',
- '"resolve"', '"readElementByName"',
- '2',
- '"const"', 3,
- '"const"', '"p1"',
- 'false',
- '"const"', '"tokens"',
- 'false',
- 'true',
- '"output"', '"call"',
- '"access"',
- '"resolve"', '"readAttribute"',
- '3',
- '"const"', 3,
- '"call"',
- '"access"',
- '"resolve"', '"readElementByName"',
- '2',
- '"const"', 3,
- '"const"', '"arc1"',
- 'false',
- '"const"', '"weight"',
- 'false',
- 'true',
- '"output"', '"call"',
- '"access"',
- '"resolve"', '"readAttribute"',
- '3',
- '"const"', 3,
- '"call"',
- '"access"',
- '"resolve"', '"readElementByName"',
- '2',
- '"const"', 3,
- '"const"', '"arc2"',
- 'false',
- '"const"', '"weight"',
- 'false',
- 'true',
- '"return"', 'true',
- '"const"', 'true',
- ]
- self.assertTrue(run_barebone(flatten(commands), ['5', '1', '2'], 1))
- def test_constructors_readAndSetAttribute(self):
- commands = bottom + retype + [
- '"instantiate_model"',
- 1,
- 1, '"Inheritance"',
- '"Class"', '"Place"',
- 'true',
- '"tokens"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Class"', '"Transition"',
- 'false',
- 'false',
- 'true',
- '"Association"', '"P2T"', '"Place"', '"Transition"',
- 'true',
- '"weight"', '{"value": "Integer"}', 'false',
- 'false',
- 'true',
- '"Association"', '"T2P"', '"Transition"', '"Place"',
- 'true',
- '"weight"', '{"value": "Integer"}', 'false',
- 'false',
- 'false',
- 2,
- '"instantiate_model"',
- 2,
- 1, '"Inheritance"',
- '"Place"', '"p1"',
- 'false',
- 'true',
- '"tokens"', '5', 'false',
- 'true',
- '"Transition"', '"t1"',
- 'false',
- 'false',
- 'true',
- '"P2T"', '"arc1"', '"p1"', '"t1"',
- 'false',
- 'true',
- '"weight"', '1', 'false',
- 'true',
- '"T2P"', '"arc2"', '"t1"', '"p1"',
- 'false',
- 'true',
- '"weight"', '2', 'false',
- 'false',
- 3,
- '"output"', '"call"',
- '"access"',
- '"resolve"', '"readAttribute"',
- '3',
- '"const"', 3,
- '"call"',
- '"access"',
- '"resolve"', '"readElementByName"',
- '2',
- '"const"', 3,
- '"const"', '"p1"',
- 'false',
- '"const"', '"tokens"',
- 'false',
- 'true',
- '"output"', '"call"',
- '"access"',
- '"resolve"', '"readAttribute"',
- '3',
- '"const"', 3,
- '"call"',
- '"access"',
- '"resolve"', '"readElementByName"',
- '2',
- '"const"', 3,
- '"const"', '"arc1"',
- 'false',
- '"const"', '"weight"',
- 'false',
- 'true',
- '"output"', '"call"',
- '"access"',
- '"resolve"', '"readAttribute"',
- '3',
- '"const"', 3,
- '"call"',
- '"access"',
- '"resolve"', '"readElementByName"',
- '2',
- '"const"', 3,
- '"const"', '"arc2"',
- 'false',
- '"const"', '"weight"',
- 'false',
- 'true',
- '"call"',
- '"access"',
- '"resolve"', '"setAttribute"',
- '4',
- '"const"', 3,
- '"call"',
- '"access"',
- '"resolve"', '"readElementByName"',
- '2',
- '"const"', 3,
- '"const"', '"p1"',
- 'false',
- '"const"', '"tokens"',
- '"const"', '10',
- 'true',
- '"call"',
- '"access"',
- '"resolve"', '"setAttribute"',
- '4',
- '"const"', 3,
- '"call"',
- '"access"',
- '"resolve"', '"readElementByName"',
- '2',
- '"const"', 3,
- '"const"', '"arc1"',
- 'false',
- '"const"', '"weight"',
- '"const"', '16',
- 'true',
- '"call"',
- '"access"',
- '"resolve"', '"setAttribute"',
- '4',
- '"const"', 3,
- '"call"',
- '"access"',
- '"resolve"', '"readElementByName"',
- '2',
- '"const"', 3,
- '"const"', '"arc2"',
- 'false',
- '"const"', '"weight"',
- '"const"', '30',
- 'true',
- '"output"', '"call"',
- '"access"',
- '"resolve"', '"readAttribute"',
- '3',
- '"const"', 3,
- '"call"',
- '"access"',
- '"resolve"', '"readElementByName"',
- '2',
- '"const"', 3,
- '"const"', '"p1"',
- 'false',
- '"const"', '"tokens"',
- 'false',
- 'true',
- '"output"', '"call"',
- '"access"',
- '"resolve"', '"readAttribute"',
- '3',
- '"const"', 3,
- '"call"',
- '"access"',
- '"resolve"', '"readElementByName"',
- '2',
- '"const"', 3,
- '"const"', '"arc1"',
- 'false',
- '"const"', '"weight"',
- 'false',
- 'true',
- '"output"', '"call"',
- '"access"',
- '"resolve"', '"readAttribute"',
- '3',
- '"const"', 3,
- '"call"',
- '"access"',
- '"resolve"', '"readElementByName"',
- '2',
- '"const"', 3,
- '"const"', '"arc2"',
- 'false',
- '"const"', '"weight"',
- 'false',
- 'true',
- '"return"', 'true',
- '"const"', 'true',
- ]
- self.assertTrue(run_barebone(flatten(commands), ['5', '1', '2', '10', '16', '30'], 1))
|