示例#1
0
def test_writable():
    schema = Dict.of(Integer.named(u'main'),
                     Ref.named(u'aux').to(u'../main').using(writable=True))

    el = schema()
    el[u'aux'] = 6
    assert el[u'main'].value == 6
    assert el[u'aux'].value == 6
示例#2
0
def test_not_writable():
    schema = Dict.of(Integer.named(u'main'),
                     Ref.named(u'aux').to(u'main').using(writable=False))

    el = schema()

    with pytest.raises(TypeError):
        el[u'aux'].set(6)
示例#3
0
def test_writable():
    schema = Dict.of(Integer.named(u'main'),
                     Ref.named(u'aux').to(u'main').using(writable=True))

    el = schema()
    el[u'aux'] = 6
    assert el[u'main'].value == 6
    assert el[u'aux'].value == 6
示例#4
0
def test_dereference_twice():
    schema = Dict.of(Integer.named(u'main'),
                     Ref.named(u'aux').to(u'../main').using(writable=True))

    # Previous revisions would fail after two dereferences
    element = schema()

    element[u'aux'] = 1
    assert element[u'aux'].value == 1

    element[u'aux'].set(1)
    assert element[u'aux'].value == 1

    assert element.find_one(element[u'aux'].target_path) is element[u'main']
    assert element.find_one(element[u'aux'].target_path) is element[u'main']
示例#5
0
def test_dereference_twice():
    schema = Dict.of(Integer.named(u'main'),
                     Ref.named(u'aux').to(u'main').using(writable=True))

    # Previous revisions would fail after two dereferences
    element = schema()

    element[u'aux'] = 1
    assert element[u'aux'].value == 1

    element[u'aux'].set(1)
    assert element[u'aux'].value == 1

    assert element.el(element[u'aux'].target_path) is element[u'main']
    assert element.el(element[u'aux'].target_path) is element[u'main']
示例#6
0
def test_binops():
    schema = Dict.of(Integer.named(u'main'),
                     Ref.named(u'aux').to(u'../main'), Integer.named(u'other'))
    el = schema({u'main': 5})

    assert el[u'aux'] == Integer(5)
    assert el[u'aux'].value == 5
    assert el[u'aux'].u == u'5'
    assert Integer(5) == el[u'aux']
    assert 5 == el[u'aux'].value
    assert u'5' == el[u'aux'].u

    assert el[u'aux'] != Integer(6)
    assert el[u'aux'].value != 6
    assert el[u'aux'].u != u'6'
    assert Integer(6) != el[u'aux']
    assert 6 != el[u'aux']
    assert u'6' != el[u'aux']

    assert el[u'aux'] == el[u'main']
    assert el[u'main'] == el[u'aux']
    assert el[u'aux'] != el[u'other']
    assert el[u'other'] != el[u'aux']
示例#7
0
def test_binops():
    schema = Dict.of(Integer.named(u'main'),
                     Ref.named(u'aux').to(u'main'),
                     Integer.named(u'other'))
    el = schema({u'main': 5})

    assert el[u'aux'] == Integer(5)
    assert el[u'aux'].value == 5
    assert el[u'aux'].u == u'5'
    assert Integer(5) == el[u'aux']
    assert 5 == el[u'aux'].value
    assert u'5' == el[u'aux'].u

    assert el[u'aux'] != Integer(6)
    assert el[u'aux'].value != 6
    assert el[u'aux'].u != u'6'
    assert Integer(6) != el[u'aux']
    assert 6 != el[u'aux']
    assert u'6' != el[u'aux']

    assert el[u'aux'] == el[u'main']
    assert el[u'main'] == el[u'aux']
    assert el[u'aux'] != el[u'other']
    assert el[u'other'] != el[u'aux']
示例#8
0
def test_not_writable():
    schema = Dict.of(Integer.named(u'main'),
                     Ref.named(u'aux').to(u'../main').using(writable=False))

    el = schema()
    assert_raises(TypeError, el[u'aux'].set, 6)
示例#9
0
 def element(writable):
     ref = Ref.named(u'aux').to(u'/main')
     if writable:
         ref = ref.using(writable=writable)
     return Dict.of(Integer.named(u'main'), ref)()
示例#10
0
 def element(writable):
     ref = Ref.named(u'aux').to(u'main')
     if writable:
         ref = ref.using(writable=writable)
     return Dict.of(Integer.named(u'main'), ref)()
示例#11
0
文件: test_refs.py 项目: dag/flatland
def test_not_writable():
    schema = Dict.of(Integer.named(u'main'),
                     Ref.named(u'aux').to(u'main').using(writable=False))

    el = schema()
    assert_raises(TypeError, el[u'aux'].set, 6)