# Path: pyecore/utils.py
# class DynamicEPackage(EObserver):
#     """A DynamicEPackage gives the ability to directly handle metaclasses
#     from a metamodel as if it were a statically generated EPackage.
# 
#     Usage from an existing dynamic EPackage named 'myroot' that defines two
#     EClass: 'A' and 'B'
#     >>> from pyecore.utils import DynamicEPackage
#     >>> MyAPI = DynamicEPackage(myroot)
#     >>> MyAPI.A
#     <EClass name="A">
#     >>> a = MyAPI.A()
#     >>> a
#     <pyecore.ecore.A object at 0x7f118de363c8>
#     """
# 
#     def __init__(self, package):
#         if not isinstance(package, EPackage):
#             raise BadValueError(got=package, expected=EPackage)
#         if ismodule(package):
#             package = package.eClass
#         super().__init__(notifier=package)
# 
#         for eclass in package.eClassifiers:
#             setattr(self, eclass.name, eclass)
#         for subpackage in package.eSubpackages:
#             setattr(self, subpackage.name, DynamicEPackage(subpackage))
# 
#     def notifyChanged(self, notification):
#         kind = notification.kind
#         if notification.feature is EPackage.eClassifiers:
#             if kind == Kind.ADD:
#                 new = notification.new
#                 setattr(self, new.name, new)
#             elif kind == Kind.ADD_MANY:
#                 for new in notification.new:
#                     setattr(self, new.name, new)
#             elif kind == Kind.REMOVE and notification.old.eResource is None:
#                 delattr(self, notification.old.name)
#             # elif kind == Kind.REMOVE_MANY:
#             #     for element in notification.old:
#             #         if element.eResource is None:
#             #             delattr(self, element.name)


import pytest
from pyecore.ecore import *
from pyecore.utils import DynamicEPackage
from pyecore.notification import *
    assert b5 in a.inners


def test_slicing_int_list_bad_obj(simplemm):
    a = simplemm.A()
    a.ints.extend([1, 2, 3, 4])
    with pytest.raises(BadValueError):
        a.ints[1:] = ['r']


def test_slicing_obj_list_bad_obj(simplemm):
    a = simplemm.A()
    with pytest.raises(BadValueError):
        a.cols[:] = [simplemm.A()]


def test_slicing_insert_ints(simplemm):
    a = simplemm.A()
    a.ints.insert(0, 1)
    assert a.ints == [1]


def test_slicing_pop_b(simplemm):
    a = simplemm.A()
    b1 = simplemm.B()
    b2 = simplemm.B()
    a.cols.extend([b1, b2])
    o = ObserverCounter(a)
    e = a.cols.pop(1)
    assert e is b2

# Path: pyecore/utils.py
# class DynamicEPackage(EObserver):
#     """A DynamicEPackage gives the ability to directly handle metaclasses
#     from a metamodel as if it were a statically generated EPackage.
# 
#     Usage from an existing dynamic EPackage named 'myroot' that defines two
#     EClass: 'A' and 'B'
#     >>> from pyecore.utils import DynamicEPackage
#     >>> MyAPI = DynamicEPackage(myroot)
#     >>> MyAPI.A
#     <EClass name="A">
#     >>> a = MyAPI.A()
#     >>> a
#     <pyecore.ecore.A object at 0x7f118de363c8>
#     """
# 
#     def __init__(self, package):
#         if not isinstance(package, EPackage):
#             raise BadValueError(got=package, expected=EPackage)
#         if ismodule(package):
#             package = package.eClass
#         super().__init__(notifier=package)
# 
#         for eclass in package.eClassifiers:
#             setattr(self, eclass.name, eclass)
#         for subpackage in package.eSubpackages:
#             setattr(self, subpackage.name, DynamicEPackage(subpackage))
# 
#     def notifyChanged(self, notification):
#         kind = notification.kind
#         if notification.feature is EPackage.eClassifiers:
#             if kind == Kind.ADD:
#                 new = notification.new
#                 setattr(self, new.name, new)
#             elif kind == Kind.ADD_MANY:
#                 for new in notification.new:
#                     setattr(self, new.name, new)
#             elif kind == Kind.REMOVE and notification.old.eResource is None:
#                 delattr(self, notification.old.name)
#             # elif kind == Kind.REMOVE_MANY:
#             #     for element in notification.old:
#             #         if element.eResource is None:
#             #             delattr(self, element.name)


# Path: tests/test_slicing_del.py
import pytest
from pyecore.ecore import *
from pyecore.utils import DynamicEPackage
from pyecore.notification import *

    assert b5 in a.inners


def test_slicing_int_list_bad_obj(simplemm):
    a = simplemm.A()
    a.ints.extend([1, 2, 3, 4])
    with pytest.raises(BadValueError):
        a.ints[1:] = ['r']


def test_slicing_obj_list_bad_obj(simplemm):
    a = simplemm.A()
    with pytest.raises(BadValueError):
        a.cols[:] = [simplemm.A()]


def test_slicing_insert_ints(simplemm):
    a = simplemm.A()
    a.ints.insert(0, 1)
    assert a.ints == [1]


def test_slicing_pop_b(simplemm):
    a = simplemm.A()
    b1 = simplemm.B()
    b2 = simplemm.B()
    a.cols.extend([b1, b2])
    o = ObserverCounter(a)
    e = a.cols.pop(1)
    assert e is b2

    assert o.calls == 1