Example #1
0
    # Simple calls
    assert unify('foo()') == 'foo()'
    assert unify('bar.fo_o()') == 'bar.fo_o()'
    
    # Anything that already has braces or []
    assert unify('(foo)') == '(foo)'
    assert unify('(3 + 3)') == '(3 + 3)'
    assert unify('[2, 3]') == '[2, 3]'
    
    # Func calls with args (but no extra braces)
    assert unify('xxxxx(some args bla)') == 'xxxxx(some args bla)'
    assert unify('foo(3)') == 'foo(3)'
    
    # Indexing
    assert unify('foo[1]') == 'foo[1]'
    assert unify('bar.foo[1:2,3]') == 'bar.foo[1:2,3]'
    
    # Dict
    assert unify('{a:3, b:"5"}') == '{a:3, b:"5"}'
    
    # Otherwise ... braces!
    assert unify('3+3') == '(3+3)'
    assert unify('(3)+(3)') == '((3)+(3))'
    assert unify('[3]+[3]') == '([3]+[3])'
    assert unify('foo((3))') == '(foo((3)))'
    assert unify('bar+foo(3)') == '(bar+foo(3))'
    assert unify('b + {a:3}') == '(b + {a:3})'


run_tests_if_main()
Example #2
0
    handler_ref = weakref.ref(handler)
    del handler
    gc.collect()
    assert handler_ref() is not None  # h is holding on

    handler_ref().dispose()
    gc.collect()
    assert handler_ref() is None


def test_dispose2():

    h = event.HasEvents()

    @h.connect('x1', 'x2')
    def handler(*events):
        pass

    handler_ref = weakref.ref(handler)
    del handler
    gc.collect()
    assert handler_ref() is not None  # h is holding on

    h.dispose()  # <=== only this line is different from test_dispose1()
    gc.collect()
    assert handler_ref() is None


run_tests_if_main()