<s> import unittest <EOL> import tempfile <EOL> import shutil <EOL> import dulwich <EOL> from support import setup_logger <EOL> from spaghettifs . easygit import EasyGit , EasyTree , EasyBlob <EOL> from spaghettifs . treetree import TreeTree <EOL> class BasicTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . repo_path = tempfile . mkdtemp ( ) <EOL> self . eg = EasyGit . new_repo ( self . repo_path , bare = True ) <EOL> self . tt = TreeTree ( self . eg . root . new_tree ( '<STR_LIT>' ) ) <EOL> def tearDown ( self ) : <EOL> shutil . rmtree ( self . repo_path ) <EOL> def commit ( self ) : <EOL> self . eg . commit ( author = "<STR_LIT>" , <EOL> message = "<STR_LIT>" ) <EOL> def test_valid_ids ( self ) : <EOL> self . assertRaises ( ValueError , self . tt . new_blob , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , self . tt . new_blob , <NUM_LIT> ) <EOL> try : <EOL> self . tt . new_blob ( '<STR_LIT>' ) <EOL> self . tt . new_blob ( '<STR_LIT>' ) <EOL> except ValueError : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_create_retrieve_blobs ( self ) : <EOL> for name in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:0>' ] : <EOL> self . assertTrue ( name not in self . tt ) <EOL> self . tt . new_blob ( name ) . data = '<STR_LIT>' <EOL> self . commit ( ) <EOL> self . assertTrue ( name in self . tt ) <EOL> self . assertEqual ( self . tt [ name ] . data , '<STR_LIT>' ) <EOL> self . assertTrue ( name not in self . eg . root [ '<STR_LIT>' ] ) <EOL> def test_create_retrieve_trees ( self ) : <EOL> for name in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> self . assertTrue ( name not in self . tt ) <EOL> self . tt . new_tree ( name ) . new_blob ( '<STR_LIT:c>' ) . data = '<STR_LIT>' <EOL> self . commit ( ) <EOL> self . assertTrue ( name in self . tt ) <EOL> self . assertEqual ( self . tt [ name ] [ '<STR_LIT:c>' ] . data , '<STR_LIT>' ) <EOL> self . assertTrue ( name not in self . eg . root [ '<STR_LIT>' ] ) <EOL> def test_structure ( self ) : <EOL> raw_tt = self . eg . root [ '<STR_LIT>' ] <EOL> self . tt . new_tree ( '<STR_LIT>' ) <EOL> self . assertTrue ( isinstance ( raw_tt [ '<STR_LIT>' ] [ '<STR_LIT:1>' ] [ '<STR_LIT:2>' ] [ '<STR_LIT:3>' ] , EasyTree ) ) <EOL> self . tt . new_blob ( '<STR_LIT>' ) <EOL> self . assertTrue ( isinstance ( raw_tt [ '<STR_LIT>' ] [ '<STR_LIT:2>' ] [ '<STR_LIT:2>' ] , EasyBlob ) ) <EOL> self . assertRaises ( KeyError , lambda : self . tt [ '<STR_LIT>' ] ) <EOL> def test_overwrite ( self ) : <EOL> self . tt . new_tree ( '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , self . tt . new_blob , '<STR_LIT>' ) <EOL> def test_clone ( self ) : <EOL> blobby = self . eg . root . new_blob ( '<STR_LIT>' ) <EOL> blobby . data = '<STR_LIT>' <EOL> self . tt . clone ( blobby , '<STR_LIT>' ) <EOL> blobby . data = '<STR_LIT>' <EOL> self . assertEqual ( self . tt [ '<STR_LIT>' ] . data , '<STR_LIT>' ) <EOL> self . assertEqual ( self . eg . root [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:1>' ] [ '<STR_LIT:2>' ] [ '<STR_LIT:3>' ] [ '<STR_LIT:4>' ] . data , <EOL> '<STR_LIT>' ) <EOL> def test_remove ( self ) : <EOL> raw_tt = self . eg . root [ '<STR_LIT>' ] <EOL> for name in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> self . tt . new_blob ( name ) . data = '<STR_LIT>' <EOL> self . assertTrue ( '<STR_LIT>' in self . tt ) <EOL> self . assertTrue ( '<STR_LIT>' in raw_tt ) <EOL> self . assertTrue ( '<STR_LIT:3>' in raw_tt [ '<STR_LIT>' ] ) <EOL> del self . tt [ '<STR_LIT>' ] <EOL> self . assertTrue ( '<STR_LIT>' not in self . tt ) <EOL> self . assertTrue ( '<STR_LIT>' in raw_tt ) <EOL> self . assertTrue ( '<STR_LIT:3>' not in raw_tt [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( '<STR_LIT>' in self . tt ) <EOL> self . assertTrue ( '<STR_LIT>' in raw_tt ) <EOL> del self . tt [ '<STR_LIT>' ] <EOL> self . assertTrue ( '<STR_LIT>' not in self . tt ) <EOL> self . assertTrue ( '<STR_LIT>' not in raw_tt ) <EOL> self . assertRaises ( KeyError , lambda : self . tt [ '<STR_LIT>' ] ) <EOL> self . assertRaises ( KeyError , lambda : self . tt [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( self . tt [ '<STR_LIT>' ] . data , '<STR_LIT>' ) <EOL> self . assertEqual ( self . tt [ '<STR_LIT>' ] . data , '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> setup_logger ( '<STR_LIT>' ) <EOL> unittest . main ( ) </s>
