Exemplo n.º 1
0
def test_resource_extract_rootnum_and_frag():
    num, frag = Resource.extract_rootnum_and_frag('/1/a.b')
    assert num == 1
    assert frag == '/a.b'

    num, frag = Resource.extract_rootnum_and_frag('/123')
    assert num == 123
    assert frag == ''

    num, frag = Resource.extract_rootnum_and_frag('/234/a/b/c/d')
    assert num == 234
    assert frag == '/a/b/c/d'
Exemplo n.º 2
0
def test_notification_add_resource():
    root = EPackage(name='test')

    from pyecore.resources import Resource
    resource = Resource()

    o1 = ObserverCounter(resource)
    resource.append(root)
    assert o1.calls == 0  # does not trigger any notification

    A = EClass('A')
    root.eClassifiers.append(A)
    assert o1.calls == 2
    assert o1.kind == Kind.ADD
    assert o1.feature is EPackage.eClassifiers
Exemplo n.º 3
0
def test_resource_update_URI():
    resource = Resource(uri=URI('test_uri'))
    assert resource.uri.plain == 'test_uri'

    resource.uri = URI('http://new_URI')
    assert resource.uri.plain == 'http://new_URI'

    resource.uri = 'http://newnewURI'
    assert resource.uri.plain == 'http://newnewURI'

    rset = ResourceSet()
    resource = rset.create_resource('http://test_URI')
    assert resource.uri.plain == 'http://test_URI'

    resource.uri = 'http://newURI'
    assert 'http://newURI' in rset.resources
    assert 'http://test_URI' not in rset.resources
    assert resource.uri.plain == 'http://newURI'
Exemplo n.º 4
0
def test_resource_normalize_change_protocol():
    r = Resource(path.join('..', 'test'))
    r.uri = 'pathmap://test'

    assert r.uri.normalize() == r.uri.plain
    assert r.uri.plain == 'pathmap://test'
Exemplo n.º 5
0
#
#  TNO licenses this work to you under the Apache License, Version 2.0
#  You may obtain a copy of the license at http://www.apache.org/licenses/LICENSE-2.0
#
#  Contributors:
#         TNO             - Initial implementation
#
#  :license: Apache License, Version 2.0
#

import esdl
from pyecore.resources import Resource

esdl.Point.__repr__ = lambda x: 'Point(lat={})'.format(x.lat)

r = Resource()
line = esdl.Line()
r.append(line)
point1 = esdl.Point(lat=1.0, lon=1.0)
point2 = esdl.Point(lat=2.0, lon=2.0)
line.point.extend((point1, point2))

print('original -', line.point)
print('original - uri for point[0]', line.point[0].eURIFragment())
print('original - resolved object for', line.point[0].eURIFragment(),
      "(should be 1.0):", r.resolve(line.point[0].eURIFragment()))
print('fragment cache:', r._resolve_mem)
print()
print('reversing list')
rev = list(reversed(line.point))
line.point.clear()
Exemplo n.º 6
0
def resolve_fragment(resource: Resource, fragment: str):
    return resource.resolve(fragment)