import unittest
import sys
import os

from utils import execute, kill, run_file, run_barebone
sys.path.append("interface/HUTN")
from hutn_compiler.compiler import main as do_compile

def model_compile(filename):
    return do_compile(filename, "interface/HUTN/grammars/modelling.g", "M")

def conformance_call(operation, model, metamodel):
    return [
            '"output"',
                '"call"',
                    '"access"', '"resolve"', '"%s"' % operation,
                    '3',
                    '"call"', '"access"', '"resolve"', '"import_node"', '1', '"const"', '"models/example_M"', 'false',
                    '"const"', '"%s"' % model,
                    '"const"', '"%s"' % metamodel,
                'false',
            'true',
            ]

def conformance_check(node):
    return [
            '"output"',
                '"call"',
                    '"access"', '"resolve"', '"conformance_scd"',
                    '1',
                    '"call"', '"access"', '"resolve"', '"import_node"', '1', '"const"', '"%s"' % (node), 'false',
                    'false',
                'true',
            ]

class TestConstructorsModelsCompiled(unittest.TestCase):
    def test_constructors_petrinets(self):
        commands = ['"model"' ,'"initialize_SCD"', '"models/SimpleClassDiagrams"', '"exit"'] + \
                   model_compile("integration/code/petrinets.mvc") + \
                   conformance_check("models/PetriNets") + \
                   ['"return"', 'false']
        self.assertTrue(run_barebone(commands, ["OK"], 1))

    def test_constructors_petrinet_instance(self):
        commands = ['"model"' ,'"initialize_SCD"', '"models/SimpleClassDiagrams"', '"exit"'] + \
                   model_compile("integration/code/petrinets.mvc") + \
                   model_compile("integration/code/my_petrinet.mvc") + \
                   conformance_check("models/my_petrinet") + \
                   ['"return"', 'false']
        self.assertTrue(run_barebone(commands, ["OK"], 1))

    def test_constructors_petrinet_full(self):
        commands = ['"model"' ,'"initialize_SCD"', '"models/SimpleClassDiagrams"', '"exit"'] + \
                   model_compile("integration/code/my_petrinet_with_MM.mvc") + \
                   conformance_check("models/my_petrinet") + \
                   ['"return"', 'false']
        self.assertTrue(run_barebone(commands, ["OK"], 1))
