Commit 87228e62 authored by Kirill Smelkov's avatar Kirill Smelkov

xnet/lonet.py: Use defer

Pygolang, starting from 0.0.0.dev5 provides working defer.
parent 2789db4e
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
# See COPYING file for full licensing terms. # See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
from golang import gimport from golang import gimport, defer, func
xerr = gimport('lab.nexedi.com/kirr/go123/xerr') xerr = gimport('lab.nexedi.com/kirr/go123/xerr')
lonet = gimport('lab.nexedi.com/kirr/go123/xnet/lonet') lonet = gimport('lab.nexedi.com/kirr/go123/xnet/lonet')
...@@ -41,22 +41,20 @@ def xwrite(sk, data): ...@@ -41,22 +41,20 @@ def xwrite(sk, data):
# _test_virtnet_basic runs basic tests on a virtnet network implementation. # _test_virtnet_basic runs basic tests on a virtnet network implementation.
# (this follows virtnettest.TestBasic) # (this follows virtnettest.TestBasic)
@func
def _test_virtnet_basic(subnet): def _test_virtnet_basic(subnet):
# (verifying that error log stays empty) # (verifying that error log stays empty)
errorlog = StringIO() errorlog = StringIO()
errorlogh = log.StreamHandler(errorlog) errorlogh = log.StreamHandler(errorlog)
l = log.getLogger() l = log.getLogger()
l.addHandler(errorlogh) l.addHandler(errorlogh)
def _():
try:
__test_virtnet_basic(subnet)
finally:
subnet.close()
l.removeHandler(errorlogh) l.removeHandler(errorlogh)
assert errorlog.getvalue() == "" assert errorlog.getvalue() == ""
defer(_)
defer(subnet.close)
def __test_virtnet_basic(subnet):
def xaddr(addr): def xaddr(addr):
return lonet.Addr.parse(subnet.network(), addr) return lonet.Addr.parse(subnet.network(), addr)
...@@ -143,14 +141,11 @@ def test_lonet_py_basic(): ...@@ -143,14 +141,11 @@ def test_lonet_py_basic():
# test interaction with lonet.go # test interaction with lonet.go
@func
def test_lonet_py_go(network): def test_lonet_py_go(network):
subnet = lonet.join(network) subnet = lonet.join(network)
try: defer(subnet.close)
_test_lonet_py_go(subnet)
finally:
subnet.close()
def _test_lonet_py_go(subnet):
def xaddr(addr): def xaddr(addr):
return lonet.Addr.parse(subnet.network(), addr) return lonet.Addr.parse(subnet.network(), addr)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment