# Path: omelette/compiler/uml.py
# class UMLObject(object):
#     """Class representing UML diagram object."""
# 
#     def __init__(self, parent=None, name=None, is_prototype=False,
#             code_object=None):
#         """
#         Create UMLObject
# 
#         Keyword arguments:
#         parent -- name of UMLObject this object is based upon (default: None)
#         name -- name of this UMLObject (default: None)
#         is_prototype -- prototype objects aren't returned by Compiler.compile
#         method (default: False)
#         """
# 
#         self.__operations = []
#         self.__attributes = []
#         self.properties = {}
# 
#         self.required = {}
#         self.allowed = {}
# 
#         self.type = None
#         self.parent = parent
#         self.name = name
#         self.is_prototype = is_prototype
#         self.code_object = code_object
# 
#     def __setitem__(self, key, value):
#         property = self.properties.get(key)
#         type = property[1] if property else None
# 
#         self.properties[key] = (value, type)
# 
#     def __getitem__(self, key):
#         return self.properties[key][0]
# 
#     def add_operation(self, operation):
#         """Adds an instance of Operation class to objects operations"""
#         self.__operations.append(operation)
# 
#     def add_attribute(self, attribute):
#         """Adds an instance of Attribute class to objects attributes"""
#         self.__attributes.append(attribute)
# 
#     def operations(self):
#         """Returns list of object's operations"""
#         return self.__operations
# 
#     def attributes(self):
#         """Returns list of object's attributes"""
#         return self.__attributes
# 
#     def __eq__(self, other):
#         return self.__dict__ == other.__dict__
# 
#     def __contains__(self, key):
#         return key in self.properties
# 
# Path: omelette/compiler/validator.py
# class Validator(object):
# 
#     def __init__(self, uml_objects):
#         self.__uml_objects = uml_objects
# 
#     def __log_error(self, message):
#         logger = logging.getLogger("compiler")
#         logger.error(message, object=self.__uml_object)
# 
#     def __validate_reference(self, reference):
#         if reference not in self.__uml_objects.keys():
#             self.__log_error("non-existing object referenced: " + reference)
# 
#     def __validate_type(self, name, types):
#         value, type = self.__uml_object.properties[name]
#         message = "invalid type of property: %s (expected %s)"
# 
#         if not isinstance(types[name], list):
#             if type != types[name]:
#                 self.__log_error(message % (name, types[name]))
#             elif type == "OBJECT":
#                 self.__validate_reference(value)
#         else:
#             if value not in types[name]:
#                 expected = "[" + ", ".join(types[name]) + "]"
#                 self.__log_error(message % (name, expected))
# 
#     def __validate_property(self, name):
#         required = self.__uml_object.required
#         allowed = self.__uml_object.allowed
# 
#         if name in required:
#             self.__required_left.remove(name)
#             self.__validate_type(name, required)
#         elif name in allowed:
#             self.__validate_type(name, allowed)
#         else:
#             self.__log_error("not allowed property: " + name)
# 
#     def validate(self):
#         for uml_object in self.__uml_objects.values():
#             self.__uml_object = uml_object
#             self.__required_left = uml_object.required.keys()
# 
#             for name in self.__uml_object.properties:
#                 self.__validate_property(name)
# 
#             for name in self.__required_left:
#                 self.__log_error("not defined property: " + name)
# 
# Path: omelette/compiler/logging.py
# def getLogger(name):
#     def __init__(self):
#     def info(self, msg, object=None):
#     def warning(self, msg, object=None):
#     def error(self, msg, object=None):
#     def critical(self, msg, object=None):
#     def flush(self):
#     def is_empty(self):
#     def get_events(self, levels="INFO WARNING ERROR CRITICAL"):
#     def has(self, level):
#     def __init__(self, msg, level, object):
#     def __str__(self):
# class Logger:
# class Event:


import unittest
from omelette.compiler.uml import UMLObject
from omelette.compiler.validator import Validator
from omelette.compiler import logging

class ValidatorTest(unittest.TestCase):

    def setUp(self):
        self.uml_object = UMLObject(name="association")
        self.uml_object.required = {"source-object": "OBJECT"}
        self.uml_object.allowed = {
            "arrow": "STRING",
            "direction": ["none", "source", "target", "both"],
            "source-role": "STRING",
            "source-count": "MULTIPLICITY"}

        self.uml_objects = {
            "association": self.uml_object,

# Path: omelette/compiler/uml.py
# class UMLObject(object):
#     """Class representing UML diagram object."""
# 
#     def __init__(self, parent=None, name=None, is_prototype=False,
#             code_object=None):
#         """
#         Create UMLObject
# 
#         Keyword arguments:
#         parent -- name of UMLObject this object is based upon (default: None)
#         name -- name of this UMLObject (default: None)
#         is_prototype -- prototype objects aren't returned by Compiler.compile
#         method (default: False)
#         """
# 
#         self.__operations = []
#         self.__attributes = []
#         self.properties = {}
# 
#         self.required = {}
#         self.allowed = {}
# 
#         self.type = None
#         self.parent = parent
#         self.name = name
#         self.is_prototype = is_prototype
#         self.code_object = code_object
# 
#     def __setitem__(self, key, value):
#         property = self.properties.get(key)
#         type = property[1] if property else None
# 
#         self.properties[key] = (value, type)
# 
#     def __getitem__(self, key):
#         return self.properties[key][0]
# 
#     def add_operation(self, operation):
#         """Adds an instance of Operation class to objects operations"""
#         self.__operations.append(operation)
# 
#     def add_attribute(self, attribute):
#         """Adds an instance of Attribute class to objects attributes"""
#         self.__attributes.append(attribute)
# 
#     def operations(self):
#         """Returns list of object's operations"""
#         return self.__operations
# 
#     def attributes(self):
#         """Returns list of object's attributes"""
#         return self.__attributes
# 
#     def __eq__(self, other):
#         return self.__dict__ == other.__dict__
# 
#     def __contains__(self, key):
#         return key in self.properties
# 
# Path: omelette/compiler/validator.py
# class Validator(object):
# 
#     def __init__(self, uml_objects):
#         self.__uml_objects = uml_objects
# 
#     def __log_error(self, message):
#         logger = logging.getLogger("compiler")
#         logger.error(message, object=self.__uml_object)
# 
#     def __validate_reference(self, reference):
#         if reference not in self.__uml_objects.keys():
#             self.__log_error("non-existing object referenced: " + reference)
# 
#     def __validate_type(self, name, types):
#         value, type = self.__uml_object.properties[name]
#         message = "invalid type of property: %s (expected %s)"
# 
#         if not isinstance(types[name], list):
#             if type != types[name]:
#                 self.__log_error(message % (name, types[name]))
#             elif type == "OBJECT":
#                 self.__validate_reference(value)
#         else:
#             if value not in types[name]:
#                 expected = "[" + ", ".join(types[name]) + "]"
#                 self.__log_error(message % (name, expected))
# 
#     def __validate_property(self, name):
#         required = self.__uml_object.required
#         allowed = self.__uml_object.allowed
# 
#         if name in required:
#             self.__required_left.remove(name)
#             self.__validate_type(name, required)
#         elif name in allowed:
#             self.__validate_type(name, allowed)
#         else:
#             self.__log_error("not allowed property: " + name)
# 
#     def validate(self):
#         for uml_object in self.__uml_objects.values():
#             self.__uml_object = uml_object
#             self.__required_left = uml_object.required.keys()
# 
#             for name in self.__uml_object.properties:
#                 self.__validate_property(name)
# 
#             for name in self.__required_left:
#                 self.__log_error("not defined property: " + name)
# 
# Path: omelette/compiler/logging.py
# def getLogger(name):
#     def __init__(self):
#     def info(self, msg, object=None):
#     def warning(self, msg, object=None):
#     def error(self, msg, object=None):
#     def critical(self, msg, object=None):
#     def flush(self):
#     def is_empty(self):
#     def get_events(self, levels="INFO WARNING ERROR CRITICAL"):
#     def has(self, level):
#     def __init__(self, msg, level, object):
#     def __str__(self):
# class Logger:
# class Event:


# Path: omelette/compiler/test/test_validator.py
import unittest
from omelette.compiler.uml import UMLObject
from omelette.compiler.validator import Validator
from omelette.compiler import logging


class ValidatorTest(unittest.TestCase):

    def setUp(self):
        self.uml_object = UMLObject(name="association")
        self.uml_object.required = {"source-object": "OBJECT"}
        self.uml_object.allowed = {
            "arrow": "STRING",
            "direction": ["none", "source", "target", "both"],
            "source-role": "STRING",
            "source-count": "MULTIPLICITY"}

        self.uml_objects = {
            "association": self.uml_object,

            "Student": UMLObject(name="Student")}