[Cvsshell-devel] CVS: cvsshell/testing testcases.py,NONE,1.1
Status: Beta
Brought to you by:
stefanheimann
From: Stefan H. <ste...@us...> - 2002-07-29 17:36:52
|
Update of /cvsroot/cvsshell/cvsshell/testing In directory usw-pr-cvs1:/tmp/cvs-serv17680/testing Added Files: testcases.py Log Message: --- NEW FILE: testcases.py --- #!/usr/bin/env python import unittest, os, sys sys.path.insert(0, os.path.join(os.getcwd(), sys.path[0], '..', 'src')) from cvs_shell import Listing, Entry, CvsShell thisDir = os.tmpnam() repository = os.path.join(thisDir, 'repository') workingDir = os.path.join(thisDir, 'workingDir') fNotModified = 'not_modified' fModified = 'modified' fDeleted = 'deleted' fNew = 'new' sampleDir = 'sample_dir' def system(cmd): print cmd os.system(cmd) class RefreshTestCase(unittest.TestCase): def setUp(self): print 'setUp' os.mkdir(thisDir) os.chdir(thisDir) map(os.mkdir, [repository, workingDir, os.path.join(workingDir, sampleDir)]) system('cvs -d %s init' % repository) def createFile(filename): absName = os.path.join(workingDir, filename) print absName f = open(absName, 'w') f.write('you are the file ' + filename) f.close() files = [fNotModified, fModified, fDeleted] map(createFile, files + map(os.path.join, [sampleDir]*3, files)) # python does not support currying os.chdir(workingDir) system("cvs -d %s import -m 'does not matter' workingDir tests start" % repository) system('rm -r %s' % workingDir) os.chdir(thisDir) system('cvs -d %s checkout workingDir' % repository) import time time.sleep(1) # wait one second, so that timestamp differs def modifyFiles(dir): os.chdir(dir) f = open(fModified, 'w') f.write('I am modified.') f.close() f = open(fNew, 'w') f.write('I am new.') f.close() os.remove(fDeleted) map(modifyFiles, [workingDir, os.path.join(workingDir, sampleDir)]) os.chdir(workingDir) self.cvsshell = CvsShell() self.cvsshell.listing = None self.cvsshell.batchMode = 1 def exe(self, cmd): self.cvsshell.evalCommand(cmd) def tearDown(self): os.system('rm -rf %s' % thisDir) def assertPathEqual(self, p1, p2): self.assertEqual(os.path.abspath(p1), os.path.abspath(p2)) def assertEqual(self, expected, real, msg=None): if msg is not None: msg += ' Expected: <%s>, is: <%s>' % (expected, real) unittest.TestCase.assertEqual(self, expected, real, msg) def assertEntries(self, expected): entries = self.cvsshell.listing.entries self.assertEqual(len(expected), len(entries)) i = 0 for (status, name, dir) in expected: entry = entries[i] self.assertEqual(status, entry.status, "entry %s is not ok (status)" % entry.name) self.assertEqual(name, entry.name, "entry %s is not ok (name)." % entry.name) self.assertEqual(dir, entry.dir, "entry %s is not ok (dir)." % entry.name) i = i+1 def testRefreshInInvalidDir(self): self.assertEqual(None, self.cvsshell.listing) os.chdir(thisDir) self.exe('refresh') self.assertEqual(None, self.cvsshell.listing) def testRefreshWithInvalidArg(self): self.assertEqual(None, self.cvsshell.listing) self.exe('refresh foo42') self.assertEqual(None, self.cvsshell.listing) def testNonRecursiveRefreshWithoutArg(self): self.assertEqual(None, self.cvsshell.listing) self.exe('refresh') self.assertEntries([(Entry.S_UNKNOWN, 'new', '.'), (Entry.S_DELETED, 'deleted', '.'), (Entry.S_MODIFIED, 'modified', '.'), (Entry.S_OK, 'not_modified', '.'), (Entry.S_OK, 'sample_dir', '.')]) self.assertPathEqual(workingDir, self.cvsshell.listing.rootDir) self.assertPathEqual(workingDir, os.getcwd()) def testRefreshWithArg(self): self.assertEqual(None, self.cvsshell.listing) self.exe('refresh sample_dir') self.assert_(self.cvsshell.listing is not None) self.assertEntries([(Entry.S_UNKNOWN, 'new', '.'), (Entry.S_DELETED, 'deleted', '.'), (Entry.S_MODIFIED, 'modified', '.'), (Entry.S_OK, 'not_modified', '.')]) self.assertPathEqual(os.path.join(workingDir, 'sample_dir'), self.cvsshell.listing.rootDir) self.assertPathEqual(workingDir, os.getcwd()) def testRecursiveRefreshWithoutArg(self): self.assertEqual(None, self.cvsshell.listing) self.exe('refresh -r') self.assertEntries([(Entry.S_UNKNOWN, 'new', '.'), (Entry.S_DELETED, 'deleted', '.'), (Entry.S_MODIFIED, 'modified', '.'), (Entry.S_OK, 'not_modified', '.'), (Entry.S_OK, 'sample_dir', '.'), (Entry.S_UNKNOWN, 'new', './sample_dir'), (Entry.S_DELETED, 'deleted', './sample_dir'), (Entry.S_MODIFIED, 'modified', './sample_dir'), (Entry.S_OK, 'not_modified', './sample_dir')]) self.assertPathEqual(workingDir, self.cvsshell.listing.rootDir) self.assertPathEqual(workingDir, os.getcwd()) if __name__ == '__main__': savedRC = os.path.join(os.environ['HOME'], '.cvsshellrc-saved') try: os.rename(os.path.join(os.environ['HOME'], '.cvsshellrc'), savedRC) restoreRC = 1 except: restoreRC = 0 unittest.main() if restoreRC: try: os.rename(savedRC,os.path.join(os.environ['HOME'], '.cvsshellrc')) except OSError, msg: print 'could not restore config file:', msg |