diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-06-05 15:56:14 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-06-05 15:56:14 +0200 |
commit | c69b6b979e3d6bd01ec40e75b92b21f7a391f0ca (patch) | |
tree | 0ed9539c4d8260b3549546b9e395797469de41f3 /test/git/odb/test_channel.py | |
parent | 7c1169f6ea406fec1e26e99821e18e66437e65eb (diff) | |
download | gitpython-c69b6b979e3d6bd01ec40e75b92b21f7a391f0ca.tar.gz |
Added basic channel implementation including test
restructured odb tests, they are now in an own module to keep the modules small
Diffstat (limited to 'test/git/odb/test_channel.py')
-rw-r--r-- | test/git/odb/test_channel.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/git/odb/test_channel.py b/test/git/odb/test_channel.py new file mode 100644 index 00000000..89b26582 --- /dev/null +++ b/test/git/odb/test_channel.py @@ -0,0 +1,61 @@ +"""Channel testing""" +from test.testlib import * +from git.odb.channel import * + +import time + +class TestDB(TestBase): + + def test_base(self): + # creating channel yields a write and a read channal + wc, rc = Channel() + assert isinstance(wc, WChannel) + assert isinstance(rc, RChannel) + + # everything else fails + self.failUnlessRaises(ValueError, Channel, 1, "too many args") + + # TEST UNLIMITED SIZE CHANNEL - writing+reading is FIFO + item = 1 + item2 = 2 + wc.write(item) + wc.write(item2) + assert rc.read() == item + assert rc.read() == item2 + + # next read blocks, then raises - it waits a second + st = time.time() + self.failUnlessRaises(IOError, rc.read, True, 1) + assert time.time() - st >= 1.0 + + # writing to a closed channel raises + assert not wc.closed + wc.close() + assert wc.closed + wc.close() # fine + assert wc.closed + + self.failUnlessRaises(IOError, wc.write, 1) + + # reading from a closed channel never blocks + self.failUnlessRaises(IOError, rc.read) + + + + # TEST LIMITED SIZE CHANNEL + # channel with max-items set + wc, rc = Channel(1) + wc.write(item) # fine + + # blocks for a second, its full + st = time.time() + self.failUnlessRaises(IOError, wc.write, item, True, 1) + assert time.time() - st >= 1.0 + + # get one + assert rc.read() == item + + # its empty,can put one again + wc.write(item2) + assert rc.read() == item2 + wc.close() |