diff options
author | hut <hut@lavabit.com> | 2010-03-30 19:13:58 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-03-30 19:13:58 +0200 |
commit | d1fc886688016e97af8f1dbe74e5b2c04649e08b (patch) | |
tree | 563ed41f3d0f94988a40589da4c697c9f9ce9ad6 /test | |
parent | 51d9c72ed3c7b65db192d25933a5f0ee07502cda (diff) | |
download | ranger-d1fc886688016e97af8f1dbe74e5b2c04649e08b.tar.gz |
tc_signal: added more tests (some still fail!)
Diffstat (limited to 'test')
-rw-r--r-- | test/tc_signal.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/tc_signal.py b/test/tc_signal.py index a585a86b..639cf7c3 100644 --- a/test/tc_signal.py +++ b/test/tc_signal.py @@ -15,6 +15,7 @@ if __name__ == '__main__': from __init__ import init; init() import unittest +import gc from ranger.ext.signal_dispatcher import * class TestSignal(unittest.TestCase): @@ -75,6 +76,59 @@ class TestSignal(unittest.TestCase): sd.signal_emit('setnumber', number=100) self.assertEqual(None, lst[-1]) + def test_weak_refs(self): + sd = self.sd + is_deleted = [False] + + class Foo(object): + def __init__(self): + self.alphabet = ['a'] + def calc(self, signal): + self.alphabet.append(chr(ord(self.alphabet[-1]) + 1)) + def __del__(self): + is_deleted[0] = True + + foo = Foo() + alphabet = foo.alphabet + calc = foo.calc + + del foo + self.assertEqual('a', ''.join(alphabet)) + sd.signal_bind('mysignal', calc, weak=True) + sd.signal_emit('mysignal') + self.assertEqual('ab', ''.join(alphabet)) + self.assertFalse(is_deleted[0]) + + del calc + self.assertTrue(is_deleted[0]) + + def test_weak_refs_dead_on_arrival(self): + sd = self.sd + is_deleted = [False] + + class Foo(object): + def __init__(self): + self.alphabet = ['a'] + def calc(self, signal): + self.alphabet.append(chr(ord(self.alphabet[-1]) + 1)) + def __del__(self): + is_deleted[0] = True + + foo = Foo() + alphabet = foo.alphabet + + self.assertEqual('a', ''.join(alphabet)) + sd.signal_bind('mysignal', foo.calc, weak=True) + del foo + + sd.signal_emit('mysignal') + self.assertEqual('ab', ''.join(alphabet)) + self.assertFalse(is_deleted[0]) + + del calc + self.assertTrue(is_deleted[0]) + + def test_regexp_signals(self): sd = RegexpSignalDispatcher() lst = [] |