Commit b5792409 authored by Denis Bilenko's avatar Denis Bilenko

fix some tests to clean up objects

so that they pass on python-dbg
parent b0cf96a8
...@@ -98,12 +98,7 @@ class TestLink(greentest.TestCase): ...@@ -98,12 +98,7 @@ class TestLink(greentest.TestCase):
class TestUnlink(greentest.TestCase): class TestUnlink(greentest.TestCase):
switch_expected = False switch_expected = False
def setUp(self): def _test_func(self, p, link):
greentest.TestCase.setUp(self)
self.p = gevent.spawn(dummy_test_func)
def _test_func(self, link):
p = self.p
link(dummy_test_func) link(dummy_test_func)
assert len(p._links) == 1, p._links assert len(p._links) == 1, p._links
p.unlink(dummy_test_func) p.unlink(dummy_test_func)
...@@ -113,15 +108,19 @@ class TestUnlink(greentest.TestCase): ...@@ -113,15 +108,19 @@ class TestUnlink(greentest.TestCase):
assert len(p._links) == 1, p._links assert len(p._links) == 1, p._links
p.unlink(self.setUp) p.unlink(self.setUp)
assert not p._links, p._links assert not p._links, p._links
p.kill()
def test_func_link(self): def test_func_link(self):
self._test_func(self.p.link) p = gevent.spawn(dummy_test_func)
self._test_func(p, p.link)
def test_func_link_value(self): def test_func_link_value(self):
self._test_func(self.p.link_value) p = gevent.spawn(dummy_test_func)
self._test_func(p, p.link_value)
def test_func_link_exception(self): def test_func_link_exception(self):
self._test_func(self.p.link_exception) p = gevent.spawn(dummy_test_func)
self._test_func(p, p.link_exception)
class LinksTestCase(greentest.TestCase): class LinksTestCase(greentest.TestCase):
......
...@@ -2,31 +2,30 @@ import gevent ...@@ -2,31 +2,30 @@ import gevent
import greentest import greentest
class Test(greentest.TestCase): class appender(object):
count = 2 def __init__(self, lst, item):
self.lst = lst
self.item = item
def setUp(self): def __call__(self, *args):
self.lst = [] self.lst.append(self.item)
def tearDown(self):
self.assertEqual(self.lst, range(self.count))
def test_greenlet_link(self): class Test(greentest.TestCase):
# test that links are executed in the same order as they were added
g = gevent.spawn(self.lst.append, 0)
class appender(object): count = 2
def __init__(myself, item): def test_greenlet_link(self):
myself.item = item lst = []
def __call__(myself, *args): # test that links are executed in the same order as they were added
self.lst.append(myself.item) g = gevent.spawn(lst.append, 0)
for i in xrange(1, self.count): for i in xrange(1, self.count):
g.link(appender(i)) g.link(appender(lst, i))
g.join() g.join()
self.assertEqual(lst, range(self.count))
class Test3(Test): class Test3(Test):
......
...@@ -11,4 +11,7 @@ else: ...@@ -11,4 +11,7 @@ else:
import subprocess import subprocess
for _ in xrange(5): for _ in xrange(5):
out, err = subprocess.Popen([sys.executable, __file__, 'runtestcase'], stderr=subprocess.PIPE).communicate() out, err = subprocess.Popen([sys.executable, __file__, 'runtestcase'], stderr=subprocess.PIPE).communicate()
assert err.strip() == 'bye', err if 'refs' in err:
assert err.startswith('bye'), repr(err)
else:
assert err.strip() == 'bye', repr(err)
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