# Path: pyecore/resources/resource.py
# class ResourceSet(object):
# class URI(object):
# class HttpURI(URI):
# class MetamodelDecoder(object):
# class Global_URI_decoder(object):
# class URIMapper(object):
# class URIConverter(object):
# class AbstractURIConverter(object):
# class HttpURIConverter(AbstractURIConverter):
# class LocalMetamodelDecoder(object):
# class Resource(object):
#     def __init__(self):
#     def create_resource(self, uri):
#     def remove_resource(self, resource):
#     def get_resource(self, uri, options=None):
#     def can_resolve(self, uri_path, from_resource=None):
#     def resolve(self, uri, from_resource=None):
#     def __init__(self, uri):
#     def _split(self):
#     def protocol(self):
#     def extension(self):
#     def segments(self):
#     def last_segment(self):
#     def create_instream(self):
#     def close_stream(self):
#     def create_outstream(self):
#     def normalize(self):
#     def relative_from_me(self, other_uri):
#     def apply_relative_from_me(self, relative_path):
#     def __init__(self, uri):
#     def create_instream(self):
#     def create_outstream(self):
#     def apply_relative_from_me(self, relative_path):
#     def split_path(path):
#     def can_resolve(path, registry):
#     def resolve(path, registry):
#     def can_resolve(path, from_resource=None):
#     def resolve(path, from_resource=None):
#     def translate(path, from_resource=None):
#     def convert(cls, uri, resource_set=None):
#     def can_handle(uri):
#     def convert(uri):
#     def can_handle(uri):
#     def convert(uri):
#     def can_resolve(path, from_resource=None):
#     def resolve(path, from_resource=None):
#     def __init__(self, uri=None, use_uuid=False):
#     def uri(self):
#     def uri(self, value):
#     def resolve(self, fragment, resource=None):
#     def resolve_object(self, path):
#     def extract_rootnum_and_frag(fragment):
#     def prefix2epackage(self, prefix):
#     def get_metamodel(self, nsuri):
#     def normalize(fragment):
#     def _is_external(self, path):
#     def _get_href_decoder(self, path, original_path):
#     def _try_resource_autoload(self, uri, original_uri):
#     def is_fragment_uuid(fragment):
#     def _navigate_from(cls, path, start_obj):
#     def get_id_attribute(eclass):
#     def _build_path_from(self, obj):
#     def _assign_uuid(obj):
#     def append(self, root):
#     def remove(self, root):
#     def open_out_stream(self, other=None):
#     def extend(self, values):
#     def _find_feature(self, eclass, name):


import pytest
import pyecore.ecore as Ecore
from pyecore.ecore import *
from pyecore.resources import global_registry, ResourceSet
from os import path

def test_delete_unresolved_proxy_2_models_loaded(lib):
    rset = ResourceSet()
    xmi_file = path.join('tests', 'xmi', 'xmi-tests', 'a1.xmi')
    root = rset.get_resource(xmi_file).contents[0]

    xmi_file = path.join('tests', 'xmi', 'xmi-tests', 'b1.xmi')
    root2 = rset.get_resource(xmi_file).contents[0]
    b = root.a[0].tob[0]
    b.delete()
    assert len(root.a[0].tob) == 0
    assert len(root2.b) == 1  # the element is still here


def test_delete_resolved_proxy_2_models_loaded(lib):
    rset = ResourceSet()
    xmi_file = path.join('tests', 'xmi', 'xmi-tests', 'a1.xmi')
    root = rset.get_resource(xmi_file).contents[0]

    xmi_file = path.join('tests', 'xmi', 'xmi-tests', 'b1.xmi')
    root2 = rset.get_resource(xmi_file).contents[0]
    b = root.a[0].tob[0]
    b.force_resolve()
    b.delete()
    assert len(root.a[0].tob) == 0
    assert len(root2.b) == 0  # the element had been removed
    assert b.eContainer() is None


def test_delete_unresolved_proxy_loaded_models_from_pointed(lib):

# Path: pyecore/resources/resource.py
# class ResourceSet(object):
# class URI(object):
# class HttpURI(URI):
# class MetamodelDecoder(object):
# class Global_URI_decoder(object):
# class URIMapper(object):
# class URIConverter(object):
# class AbstractURIConverter(object):
# class HttpURIConverter(AbstractURIConverter):
# class LocalMetamodelDecoder(object):
# class Resource(object):
#     def __init__(self):
#     def create_resource(self, uri):
#     def remove_resource(self, resource):
#     def get_resource(self, uri, options=None):
#     def can_resolve(self, uri_path, from_resource=None):
#     def resolve(self, uri, from_resource=None):
#     def __init__(self, uri):
#     def _split(self):
#     def protocol(self):
#     def extension(self):
#     def segments(self):
#     def last_segment(self):
#     def create_instream(self):
#     def close_stream(self):
#     def create_outstream(self):
#     def normalize(self):
#     def relative_from_me(self, other_uri):
#     def apply_relative_from_me(self, relative_path):
#     def __init__(self, uri):
#     def create_instream(self):
#     def create_outstream(self):
#     def apply_relative_from_me(self, relative_path):
#     def split_path(path):
#     def can_resolve(path, registry):
#     def resolve(path, registry):
#     def can_resolve(path, from_resource=None):
#     def resolve(path, from_resource=None):
#     def translate(path, from_resource=None):
#     def convert(cls, uri, resource_set=None):
#     def can_handle(uri):
#     def convert(uri):
#     def can_handle(uri):
#     def convert(uri):
#     def can_resolve(path, from_resource=None):
#     def resolve(path, from_resource=None):
#     def __init__(self, uri=None, use_uuid=False):
#     def uri(self):
#     def uri(self, value):
#     def resolve(self, fragment, resource=None):
#     def resolve_object(self, path):
#     def extract_rootnum_and_frag(fragment):
#     def prefix2epackage(self, prefix):
#     def get_metamodel(self, nsuri):
#     def normalize(fragment):
#     def _is_external(self, path):
#     def _get_href_decoder(self, path, original_path):
#     def _try_resource_autoload(self, uri, original_uri):
#     def is_fragment_uuid(fragment):
#     def _navigate_from(cls, path, start_obj):
#     def get_id_attribute(eclass):
#     def _build_path_from(self, obj):
#     def _assign_uuid(obj):
#     def append(self, root):
#     def remove(self, root):
#     def open_out_stream(self, other=None):
#     def extend(self, values):
#     def _find_feature(self, eclass, name):


# Path: tests/xmi/test_delete.py
import pytest
import pyecore.ecore as Ecore
from pyecore.ecore import *
from pyecore.resources import global_registry, ResourceSet
from os import path


def test_delete_unresolved_proxy_2_models_loaded(lib):
    rset = ResourceSet()
    xmi_file = path.join('tests', 'xmi', 'xmi-tests', 'a1.xmi')
    root = rset.get_resource(xmi_file).contents[0]

    xmi_file = path.join('tests', 'xmi', 'xmi-tests', 'b1.xmi')
    root2 = rset.get_resource(xmi_file).contents[0]
    b = root.a[0].tob[0]
    b.delete()
    assert len(root.a[0].tob) == 0
    assert len(root2.b) == 1  # the element is still here


def test_delete_resolved_proxy_2_models_loaded(lib):
    rset = ResourceSet()
    xmi_file = path.join('tests', 'xmi', 'xmi-tests', 'a1.xmi')
    root = rset.get_resource(xmi_file).contents[0]

    xmi_file = path.join('tests', 'xmi', 'xmi-tests', 'b1.xmi')
    root2 = rset.get_resource(xmi_file).contents[0]
    b = root.a[0].tob[0]
    b.force_resolve()
    b.delete()
    assert len(root.a[0].tob) == 0
    assert len(root2.b) == 0  # the element had been removed
    assert b.eContainer() is None


def test_delete_unresolved_proxy_loaded_models_from_pointed(lib):

    rset = ResourceSet()