# Path: baroque/datastructures/bags.py
# class EventTypesBag:
#     """A type-aware collection of event types
# 
#     Args:
#         eventtypes (collection, optional): collection of :obj:`baroque.entities.eventtypes.EventType` items.
# 
#     """
#     def __init__(self, eventtypes=None):
#         self.types = set()
#         if eventtypes is not None:
#             self.add(eventtypes)
# 
#     def add(self, eventtypes):
#         """Adds a collection of eventtypes to this bag.
# 
#         Args:
#             `list` of (:obj:`baroque.entities.eventtypes.EventType`): the event types to be added
# 
#         Raises:
#             `AssertionError`: when the supplied arg is not a collection or its items are not :obj:`baroque.entities.eventtypes.EventType` instances or :obj:`baroque.entities.eventtypes.EventType` subclasses 
# 
#         """
#         assert not isinstance(eventtypes, str)
#         assert isinstance(eventtypes, collections.Iterable)
#         assert all([isinstance(et, EventType) or type(et) == type
#                     for et in eventtypes])
#         self.types.update(set([type(et) for et in eventtypes]))
# 
#     def __len__(self):
#         return len(self.types)
# 
#     def __iter__(self):
#         return (et for et in self.types)
# 
#     def __contains__(self, item):
#         return type(item) in self.types
# 
# Path: baroque/defaults/eventtypes.py
# class GenericEventType(EventType):
#     """Describes generic events with a free-form content.
# 
#     Args:
#         owner (str, optional): ID of the owner of this event type.
# 
#     """
#     def __init__(self, owner=None):
#         EventType.__init__(self,
#                            '''{
#                              "$schema": "http://json-schema.org/draft-04/schema#"
#                            }''',
#                            description='Generic event',
#                            owner=owner)
# 
# class MetricEventType(EventType):
#     """Describes events carrying metric data.
#     Suitable i.e. to track values about measured physical quantities.
#     The metric name and value are conveyed in the event payload.
# 
#     Args:
#         owner (str, optional): ID of the owner of this event type.
# 
#     """
#     def __init__(self, owner=None):
#         EventType.__init__(
#             self,
#             '''
#             {
#               "$schema": "http://json-schema.org/draft-04/schema#",
#               "type": "object",
#               "properties": {
#                 "payload": {
#                   "type": "object",
#                   "properties": {
#                     "metric": {
#                       "type": ["string", "number"]
#                     },
#                     "value": {
#                       "type": ["string", "number"]
#                     },
#                     "timestamp": {
#                       "type": ["string", "number"]
#                     },
#                     "meta": {
#                       "type": "object",
#                       "properties": {}
#                     }
#                   },
#                   "required": [
#                     "metric",
#                     "value",
#                     "timestamp"
#                   ]
#                 }
#               },
#               "required": [
#                 "payload"
#               ]
#             }
#             ''',
#             description='Metric events',
#             owner=owner)
# 
# class DataOperationEventType(EventType):
#     """Describes events cast when some kind of operation is done on a
#     piece of data.
#     Suitable i.e. to track CRUD operations on DB tables or whole datastores.
#     Details about the impacted data entity and the operation are
#     conveyed in the event payload.
# 
#     Args:
#         owner (str, optional): ID of the owner of this event type.
# 
#     """
#     def __init__(self, owner=None):
#         EventType.__init__(
#             self,
#             '''
#             {
#               "$schema": "http://json-schema.org/draft-04/schema#",
#               "type": "object",
#               "properties": {
#                 "payload": {
#                   "type": "object",
#                   "properties": {
#                     "datum": {
#                       "type": "object",
#                       "properties": {}
#                     },
#                     "operation": {
#                       "type": "string"
#                     },
#                     "timestamp": {
#                       "type": ["number", "string"]
#                     },
#                     "meta": {
#                       "type": "object",
#                       "properties": {}
#                     }
#                   },
#                   "required": [
#                     "datum",
#                     "operation",
#                     "timestamp"
#                   ]
#                 }
#               },
#               "required": [
#                 "payload"
#               ]
#             }
#             ''',
#             description='Data operation events',
#             owner=owner)


import pytest
from baroque.datastructures.bags import EventTypesBag
from baroque.defaults.eventtypes import GenericEventType, MetricEventType,\
    DataOperationEventType


def test_add():
    bag = EventTypesBag()
    assert len(bag.types) == 0
    ets = [GenericEventType(), MetricEventType()]
    bag.add(ets)
    assert len(bag.types) == 2

# Path: baroque/datastructures/bags.py
# class EventTypesBag:
#     """A type-aware collection of event types
# 
#     Args:
#         eventtypes (collection, optional): collection of :obj:`baroque.entities.eventtypes.EventType` items.
# 
#     """
#     def __init__(self, eventtypes=None):
#         self.types = set()
#         if eventtypes is not None:
#             self.add(eventtypes)
# 
#     def add(self, eventtypes):
#         """Adds a collection of eventtypes to this bag.
# 
#         Args:
#             `list` of (:obj:`baroque.entities.eventtypes.EventType`): the event types to be added
# 
#         Raises:
#             `AssertionError`: when the supplied arg is not a collection or its items are not :obj:`baroque.entities.eventtypes.EventType` instances or :obj:`baroque.entities.eventtypes.EventType` subclasses 
# 
#         """
#         assert not isinstance(eventtypes, str)
#         assert isinstance(eventtypes, collections.Iterable)
#         assert all([isinstance(et, EventType) or type(et) == type
#                     for et in eventtypes])
#         self.types.update(set([type(et) for et in eventtypes]))
# 
#     def __len__(self):
#         return len(self.types)
# 
#     def __iter__(self):
#         return (et for et in self.types)
# 
#     def __contains__(self, item):
#         return type(item) in self.types
# 
# Path: baroque/defaults/eventtypes.py
# class GenericEventType(EventType):
#     """Describes generic events with a free-form content.
# 
#     Args:
#         owner (str, optional): ID of the owner of this event type.
# 
#     """
#     def __init__(self, owner=None):
#         EventType.__init__(self,
#                            '''{
#                              "$schema": "http://json-schema.org/draft-04/schema#"
#                            }''',
#                            description='Generic event',
#                            owner=owner)
# 
# class MetricEventType(EventType):
#     """Describes events carrying metric data.
#     Suitable i.e. to track values about measured physical quantities.
#     The metric name and value are conveyed in the event payload.
# 
#     Args:
#         owner (str, optional): ID of the owner of this event type.
# 
#     """
#     def __init__(self, owner=None):
#         EventType.__init__(
#             self,
#             '''
#             {
#               "$schema": "http://json-schema.org/draft-04/schema#",
#               "type": "object",
#               "properties": {
#                 "payload": {
#                   "type": "object",
#                   "properties": {
#                     "metric": {
#                       "type": ["string", "number"]
#                     },
#                     "value": {
#                       "type": ["string", "number"]
#                     },
#                     "timestamp": {
#                       "type": ["string", "number"]
#                     },
#                     "meta": {
#                       "type": "object",
#                       "properties": {}
#                     }
#                   },
#                   "required": [
#                     "metric",
#                     "value",
#                     "timestamp"
#                   ]
#                 }
#               },
#               "required": [
#                 "payload"
#               ]
#             }
#             ''',
#             description='Metric events',
#             owner=owner)
# 
# class DataOperationEventType(EventType):
#     """Describes events cast when some kind of operation is done on a
#     piece of data.
#     Suitable i.e. to track CRUD operations on DB tables or whole datastores.
#     Details about the impacted data entity and the operation are
#     conveyed in the event payload.
# 
#     Args:
#         owner (str, optional): ID of the owner of this event type.
# 
#     """
#     def __init__(self, owner=None):
#         EventType.__init__(
#             self,
#             '''
#             {
#               "$schema": "http://json-schema.org/draft-04/schema#",
#               "type": "object",
#               "properties": {
#                 "payload": {
#                   "type": "object",
#                   "properties": {
#                     "datum": {
#                       "type": "object",
#                       "properties": {}
#                     },
#                     "operation": {
#                       "type": "string"
#                     },
#                     "timestamp": {
#                       "type": ["number", "string"]
#                     },
#                     "meta": {
#                       "type": "object",
#                       "properties": {}
#                     }
#                   },
#                   "required": [
#                     "datum",
#                     "operation",
#                     "timestamp"
#                   ]
#                 }
#               },
#               "required": [
#                 "payload"
#               ]
#             }
#             ''',
#             description='Data operation events',
#             owner=owner)


# Path: tests/datastructures/test_eventtypesbag.py
import pytest
from baroque.datastructures.bags import EventTypesBag
from baroque.defaults.eventtypes import GenericEventType, MetricEventType,\
    DataOperationEventType



def test_add():
    bag = EventTypesBag()
    assert len(bag.types) == 0
    ets = [GenericEventType(), MetricEventType()]
    bag.add(ets)
    assert len(bag.types) == 2

    bag.add([GenericEventType()])