diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-06-09 16:38:21 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-06-09 16:38:21 +0200 |
commit | ea81f14dafbfb24d70373c74b5f8dabf3f2225d9 (patch) | |
tree | b020c7b72d33df91a35f27a40ef02dfd878bf5d2 /test/git/async/test_channel.py | |
parent | 07996a1a1e53ffdd2680d4bfbc2f4059687859a5 (diff) | |
download | gitpython-ea81f14dafbfb24d70373c74b5f8dabf3f2225d9.tar.gz |
Channel: Callbacks reviewed - they are now part of Subclasses of the default channel implementation, one of which is used as base by the Pool Read channel, releasing it of the duty to call these itself. The write channel with callback subclass allows the transformation of the item to be written
Diffstat (limited to 'test/git/async/test_channel.py')
-rw-r--r-- | test/git/async/test_channel.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/git/async/test_channel.py b/test/git/async/test_channel.py index 444a076a..215081cd 100644 --- a/test/git/async/test_channel.py +++ b/test/git/async/test_channel.py @@ -44,3 +44,30 @@ class TestChannels(TestBase): assert len(rc.read(5)) == 0 assert len(rc.read(1)) == 0 + + # test callback channels + wc, rc = mkchannel(wctype = CallbackWChannel, rctype = CallbackRChannel) + + cb = [0, 0] # set slots to one if called + def pre_write(item): + cb[0] = 1 + return item + 1 + def pre_read(count): + cb[1] = 1 + + # set, verify it returns previous one + assert wc.set_pre_cb(pre_write) is None + assert rc.set_pre_cb(pre_read) is None + assert wc.set_pre_cb(pre_write) is pre_write + assert rc.set_pre_cb(pre_read) is pre_read + + # writer transforms input + val = 5 + wc.write(val) + assert cb[0] == 1 and cb[1] == 0 + + rval = rc.read(1)[0] # read one item, must not block + assert cb[0] == 1 and cb[1] == 1 + assert rval == val + 1 + + |