<s> import unittest <EOL> import os <EOL> import commands <EOL> from utils import get_temporary_location <EOL> from utils import delete_repository <EOL> from gitpy import LocalRepository <EOL> from gitpy import find_repository <EOL> from gitpy . exceptions import GitException <EOL> class EmptyRepositoryTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . dirname = get_temporary_location ( ) <EOL> self . repo = LocalRepository ( self . dirname ) <EOL> self . assertFalse ( os . path . exists ( self . dirname ) ) <EOL> self . assertFalse ( self . repo . isValid ( ) ) <EOL> def tearDown ( self ) : <EOL> if os . path . exists ( self . dirname ) : <EOL> delete_repository ( self . repo ) <EOL> class BasicRepositories ( EmptyRepositoryTest ) : <EOL> def testRepositoryInit ( self ) : <EOL> self . repo . init ( ) <EOL> self . assertTrue ( self . repo . isValid ( ) ) <EOL> self . failUnless ( os . path . isdir ( self . dirname ) ) <EOL> self . failUnless ( os . path . isdir ( os . path . join ( self . dirname , "<STR_LIT>" ) ) ) <EOL> def testConfiguration ( self ) : <EOL> self . repo . init ( ) <EOL> self . repo . config . setParameter ( '<STR_LIT>' , <NUM_LIT:2> ) <EOL> self . assertEquals ( self . repo . config . getParameter ( '<STR_LIT>' ) , '<STR_LIT:2>' ) <EOL> def testRepositoryInitWhenExists ( self ) : <EOL> os . mkdir ( self . dirname ) <EOL> self . repo . init ( ) <EOL> self . failUnless ( os . path . isdir ( self . dirname ) ) <EOL> self . failUnless ( os . path . isdir ( os . path . join ( self . dirname , "<STR_LIT>" ) ) ) <EOL> class ModifiedRepositoryTest ( EmptyRepositoryTest ) : <EOL> FILENAME = "<STR_LIT>" <EOL> def setUp ( self ) : <EOL> super ( ModifiedRepositoryTest , self ) . setUp ( ) <EOL> self . repo . init ( ) <EOL> with open ( os . path . join ( self . repo . path , self . FILENAME ) , "<STR_LIT:wb>" ) as f : <EOL> print >> f , "<STR_LIT>" <EOL> self . assertFalse ( self . repo . isWorkingDirectoryClean ( ) ) <EOL> class ModifiedRepositories ( ModifiedRepositoryTest ) : <EOL> def testStatus ( self ) : <EOL> untracked = self . repo . getUntrackedFiles ( ) <EOL> self . assertEquals ( untracked , [ self . FILENAME ] ) <EOL> def testAdding ( self ) : <EOL> untracked_files = self . repo . getUntrackedFiles ( ) <EOL> for u in untracked_files : <EOL> self . repo . add ( u ) <EOL> self . assertEquals ( self . repo . getStagedFiles ( ) , untracked_files ) <EOL> self . assertFalse ( self . repo . isWorkingDirectoryClean ( ) ) <EOL> def testCommitting ( self ) : <EOL> self . repo . addAll ( ) <EOL> self . assertNotEquals ( self . repo . getStagedFiles ( ) , [ ] ) <EOL> c = self . repo . commit ( message = "<STR_LIT>" ) <EOL> self . assertTrue ( self . repo . isWorkingDirectoryClean ( ) ) <EOL> self . assertEquals ( self . repo . getStagedFiles ( ) , [ ] ) <EOL> class CleaningUntrackedFiles ( ModifiedRepositoryTest ) : <EOL> def _clean ( self ) : <EOL> self . repo . cleanUntrackedFiles ( ) <EOL> self . failIf ( self . repo . getUntrackedFiles ( ) ) <EOL> def testCleaningUpUntrackedFiles ( self ) : <EOL> with open ( os . path . join ( self . repo . path , "<STR_LIT>" ) , "<STR_LIT:wb>" ) as f : <EOL> print >> f , "<STR_LIT:data>" <EOL> self . failUnless ( self . repo . getUntrackedFiles ( ) ) <EOL> self . _clean ( ) <EOL> dirpath = os . path . join ( self . repo . path , "<STR_LIT>" ) <EOL> os . mkdir ( dirpath ) <EOL> self . _clean ( ) <EOL> self . failIf ( os . path . exists ( dirpath ) ) <EOL> class TestAPI ( ModifiedRepositoryTest ) : <EOL> def test_find_repository ( self ) : <EOL> prev_path = os . path . realpath ( "<STR_LIT:.>" ) <EOL> subpath = os . path . join ( self . repo . path , "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" ) <EOL> os . makedirs ( subpath ) <EOL> os . chdir ( subpath ) <EOL> try : <EOL> repo = find_repository ( ) <EOL> finally : <EOL> os . chdir ( prev_path ) <EOL> self . failUnless ( repo . path == self . repo . path ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
