From e746f96bcc29238b79118123028ca170adc4ff0f Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 4 Jun 2010 17:22:08 +0200 Subject: Fixed implementation after design change to deal with it - all tests run, but next there will have to be more through testing --- test/git/test_odb.py | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) (limited to 'test/git/test_odb.py') diff --git a/test/git/test_odb.py b/test/git/test_odb.py index 80597df6..c3a03714 100644 --- a/test/git/test_odb.py +++ b/test/git/test_odb.py @@ -1,7 +1,8 @@ """Test for object db""" from test.testlib import * -from git.odb.db import * +from git.odb import * +from git.odb.stream import Sha1Writer from git import Blob from git.errors import BadObject @@ -20,26 +21,39 @@ class TestDB(TestBase): def _assert_object_writing(self, db): """General tests to verify object writing, compatible to ObjectDBW :note: requires write access to the database""" - # start in dry-run mode - for dry_run in range(1, -1, -1): + # start in 'dry-run' mode, using a simple sha1 writer + ostreams = (Sha1Writer, None) + for ostreamcls in ostreams: for data in self.all_data: - for hex_sha in range(2): - sha = db.store(Blob.type, len(data), StringIO(data), dry_run, hex_sha) - assert db.has_object(sha) != dry_run - assert len(sha) == 20 + hex_sha * 20 + dry_run = ostreamcls is not None + ostream = None + if ostreamcls is not None: + ostream = ostreamcls() + # END create ostream + + prev_ostream = db.set_ostream(ostream) + assert type(prev_ostream) in ostreams or prev_ostream in ostreams + + istream = IStream(Blob.type, len(data), StringIO(data)) + my_istream = db.store(istream) + sha = istream.sha + assert my_istream is istream + assert db.has_object(sha) != dry_run + assert len(sha) == 40 # for now we require 40 byte shas as default + + # verify data - the slow way, we want to run code + if not dry_run: + info = db.info(sha) + assert Blob.type == info.type + assert info.size == len(data) - # verify data - the slow way, we want to run code - if not dry_run: - type, size = db.info(sha) - assert Blob.type == type - assert size == len(data) - - type, size, stream = dbstreamsha) - assert stream.read() == data - else: - self.failUnlessRaises(BadObject, db.info, sha) - self.failUnlessRaises(BadObject, db.object, sha) - # END for each sha type + ostream = db.stream(sha) + assert ostream.read() == data + assert ostream.type == Blob.type + assert ostream.size == len(data) + else: + self.failUnlessRaises(BadObject, db.info, sha) + self.failUnlessRaises(BadObject, db.stream, sha) # END for each data set # END for each dry_run mode -- cgit v1.2.1