merge tests from trunk (we're using this database now)

This commit is contained in:
Uğur Çetin
2007-06-27 08:35:45 +00:00
parent be9f3e0818
commit 6d54236006
6 changed files with 225 additions and 51 deletions
+208 -25
View File
@@ -12,6 +12,9 @@ import unittest
import zipfile import zipfile
import shutil import shutil
import os import os
import pwd
import grp
import time
import testcase import testcase
@@ -61,6 +64,139 @@ class ActionsAPITestCase(testcase.TestCase):
for file in self.filelist: for file in self.filelist:
self.assert_(fileContent.__contains__(file)) self.assert_(fileContent.__contains__(file))
def testShelltoolsCanAccessFile(self):
from pisi.actionsapi.shelltools import can_access_file
self.assert_(can_access_file('tests/actionsapitests/file'))
self.assert_(not can_access_file('tests/actionsapitests/fileX'))
self.assert_(can_access_file('tests/actionsapitests/linktoafile'))
def testShelltoolsCanAccessDir(self):
from pisi.actionsapi.shelltools import can_access_directory
self.assert_(can_access_directory('tests/actionsapitests/adirectory'))
self.assert_(not can_access_directory('tests/actionsapitests/adirectoryX'))
self.assert_(can_access_directory('tests/actionsapitests/linktoadirectory'))
def testShelltoolsMakedirs(self):
from pisi.actionsapi.shelltools import makedirs
makedirs('tests/actionsapitests/testdirectory/into/a/directory')
self.assertEqual(os.path.exists('tests/actionsapitests/testdirectory/into/a/directory'), True)
shutil.rmtree('tests/actionsapitests/testdirectory')
def testShelltoolsEcho(self):
from pisi.actionsapi.shelltools import echo
echo('tests/actionsapitests/echo-file', 'hububat fiyatları')
self.assertEqual(os.path.exists('tests/actionsapitests/echo-file'), True)
self.assertEqual(open('tests/actionsapitests/echo-file').readlines()[0].strip(), "hububat fiyatları")
echo('tests/actionsapitests/echo-file', 'fiyat hububatları')
self.assertEqual(open('tests/actionsapitests/echo-file').readlines()[1].strip(), "fiyat hububatları")
os.remove('tests/actionsapitests/echo-file')
def testShelltoolsChmod(self):
from pisi.actionsapi.shelltools import chmod
chmod('tests/actionsapitests/file')
self.assertEqual(oct(os.stat('tests/actionsapitests/file').st_mode)[-3:], '755')
chmod('tests/actionsapitests/file', 0644)
self.assertEqual(oct(os.stat('tests/actionsapitests/file').st_mode)[-3:], '644')
def testShelltoolsChown(self):
from pisi.actionsapi.shelltools import chown
f = open('tests/actionsapitests/chowntest', 'w')
f.close()
chown('tests/actionsapitests/chowntest')
self.assertEqual(os.stat('tests/actionsapitests/chowntest').st_uid, pwd.getpwnam('root')[2])
self.assertEqual(os.stat('tests/actionsapitests/chowntest').st_gid, grp.getgrnam('root')[2])
chown('tests/actionsapitests/chowntest', 'daemon', 'wheel')
self.assertEqual(os.stat('tests/actionsapitests/chowntest').st_uid, pwd.getpwnam('daemon')[2])
self.assertEqual(os.stat('tests/actionsapitests/chowntest').st_gid, grp.getgrnam('wheel')[2])
os.remove('tests/actionsapitests/chowntest')
def testShelltoolsSym(self):
from pisi.actionsapi.shelltools import sym
sym('tests/actionsapitests/file', 'tests/actionsapitests/filelnk')
self.assert_(os.path.islink('tests/actionsapitests/filelnk'))
self.assertEqual(os.readlink('tests/actionsapitests/filelnk'), 'tests/actionsapitests/file')
os.remove('tests/actionsapitests/filelnk')
def testShelltoolsUnlink(self):
from pisi.actionsapi.shelltools import unlink
f = open('tests/actionsapitests/unlinktest', 'w')
f.close()
os.symlink('tests/actionsapitests/unlinktest', 'tests/actionsapitests/unlinktest-sym')
unlink('tests/actionsapitests/unlinktest')
self.assert_(not os.path.exists('tests/actionsapitests/unlinktest'))
unlink('tests/actionsapitests/unlinktest-sym')
self.assert_(not os.path.exists('tests/actionsapitests/unlinktest-sym'))
def testShelltoolsUnlinkDir(self):
from pisi.actionsapi.shelltools import unlinkDir
os.mkdir('tests/actionsapitests/unlinkdir')
f = open('tests/actionsapitests/unlinkdir/unlinktest', 'w')
f.close()
#FIXME: unlinkDir cannot unlink a link to a directory.
#Instead it deletes content of linked directory, then leaves directory and link
#unlinkDir('tests/actionsapitests/linktoadirectory')
#self.assert_(not os.path.exists('tests/actionsapitests/linktoadirectory'))
#os.symlink('tests/actionsapitests/linkeddir', 'tests/actionsapitests/linktoadirectory')
unlinkDir('tests/actionsapitests/unlinkdir')
self.assert_(not os.path.exists('tests/actionsapitests/unlinkdir'))
def testShelltoolsMove(self):
from pisi.actionsapi.shelltools import move
move('tests/actionsapitests/brokenlink', 'tests/actionsapitests/brokenlink-move')
self.assert_(os.path.islink('tests/actionsapitests/brokenlink-move'))
self.assertEqual(os.readlink('tests/actionsapitests/brokenlink-move'), '/no/such/place')
self.assert_(not os.path.exists('tests/actionsapitests/brokenlink'))
shutil.move('tests/actionsapitests/brokenlink-move', 'tests/actionsapitests/brokenlink')
move('tests/actionsapitests/brokenlink', 'tests/actionsapitests/adirectory/brokenlink-move')
self.assert_(os.path.islink('tests/actionsapitests/adirectory/brokenlink-move'))
self.assertEqual(os.readlink('tests/actionsapitests/adirectory/brokenlink-move'), '/no/such/place')
self.assert_(not os.path.exists('tests/actionsapitests/brokenlink'))
shutil.move('tests/actionsapitests/adirectory/brokenlink-move', 'tests/actionsapitests/brokenlink')
move('tests/actionsapitests/file', 'tests/actionsapitests/adirectory')
self.assert_(os.path.isfile('tests/actionsapitests/adirectory/file'))
self.assertEqual(os.path.getsize('tests/actionsapitests/adirectory/file'), 321)
self.assert_(not os.path.exists('tests/actionsapitests/file'))
shutil.move('tests/actionsapitests/adirectory/file', 'tests/actionsapitests/')
move('tests/actionsapitests/file', 'tests/actionsapitests/file-move')
self.assert_(os.path.isfile('tests/actionsapitests/file-move'))
self.assertEqual(os.path.getsize('tests/actionsapitests/file-move'), 321)
self.assert_(not os.path.exists('tests/actionsapitests/file'))
shutil.move('tests/actionsapitests/file-move', 'tests/actionsapitests/file')
move('tests/actionsapitests/file', 'tests/actionsapitests/adirectory/filewithanothername')
self.assert_(os.path.exists('tests/actionsapitests/adirectory/filewithanothername'))
self.assertEqual(os.path.getsize('tests/actionsapitests/adirectory/filewithanothername'), 321)
self.assert_(not os.path.exists('tests/actionsapitests/file'))
shutil.move('tests/actionsapitests/adirectory/filewithanothername', 'tests/actionsapitests/file')
#FIXME: this type of moving (without changing name) doesn't work
#And I'm not sure the right way is to use 'tests/actionsapitests/adirectory/linkeddir' as dest.
#move('tests/actionsapitests/linkeddir', 'tests/actionsapitests/adirectory')
#self.assert_(os.path.exists('tests/actionsapitests/adirectory/linkeddir/file'))
#self.assertEqual(os.path.getsize('tests/actionsapitests/adirectory/linkeddir/file'), 321)
#shutil.move('tests/actionsapitests/adirectory/linkeddir', 'tests/actionsapitests/linkeddir')
move('tests/actionsapitests/linkeddir', 'tests/actionsapitests/adirectory/withanothername')
self.assert_(os.path.exists('tests/actionsapitests/adirectory/withanothername/file'))
self.assertEqual(os.path.getsize('tests/actionsapitests/adirectory/withanothername/file'), 321)
shutil.move('tests/actionsapitests/adirectory/withanothername', 'tests/actionsapitests/linkeddir')
def testShelltoolsCopy(self): def testShelltoolsCopy(self):
from pisi.actionsapi.shelltools import copy from pisi.actionsapi.shelltools import copy
@@ -109,38 +245,87 @@ class ActionsAPITestCase(testcase.TestCase):
self.assertEqual(os.path.exists('tests/actionsapitests/adirectory/withanothername/file'), True) self.assertEqual(os.path.exists('tests/actionsapitests/adirectory/withanothername/file'), True)
shutil.rmtree('tests/actionsapitests/adirectory/withanothername') shutil.rmtree('tests/actionsapitests/adirectory/withanothername')
def testShelltoolsCanAccessFile(self): def testShelltoolsCopyTree(self):
from pisi.actionsapi.shelltools import can_access_file from pisi.actionsapi.shelltools import copytree
self.assert_(can_access_file('tests/actionsapitests/file')) copytree('tests/actionsapitests/linkeddir', 'tests/actionsapitests/adirectory')
self.assert_(not can_access_file('tests/actionsapitests/fileX')) self.assert_(os.path.exists('tests/actionsapitests/linkeddir/file'))
self.assert_(can_access_file('tests/actionsapitests/linktoafile')) self.assertEqual(os.path.getsize('tests/actionsapitests/linkeddir/file'), 321)
self.assert_(os.path.exists('tests/actionsapitests/adirectory/linkeddir/file'))
self.assertEqual(os.path.getsize('tests/actionsapitests/adirectory/linkeddir/file'), 321)
shutil.rmtree('tests/actionsapitests/adirectory/linkeddir')
def testShelltoolsCanAccessDir(self): copytree('tests/actionsapitests/linkeddir', 'tests/actionsapitests/adirectory/withanothername')
from pisi.actionsapi.shelltools import can_access_directory self.assert_(os.path.exists('tests/actionsapitests/linkeddir/file'))
self.assertEqual(os.path.getsize('tests/actionsapitests/linkeddir/file'), 321)
self.assert_(os.path.exists('tests/actionsapitests/adirectory/withanothername/file'))
self.assertEqual(os.path.getsize('tests/actionsapitests/adirectory/withanothername/file'), 321)
shutil.rmtree('tests/actionsapitests/adirectory/withanothername')
self.assert_(can_access_directory('tests/actionsapitests/adirectory')) def testShelltoolsTouch(self):
self.assert_(not can_access_directory('tests/actionsapitests/adirectoryX')) from pisi.actionsapi.shelltools import touch
self.assert_(can_access_directory('tests/actionsapitests/linktoadirectory'))
touch('tests/actionsapitests/file-touch')
self.assert_(os.path.exists('tests/actionsapitests/file-touch'))
os.remove('tests/actionsapitests/file-touch')
def testShelltoolsMakedirs(self): atime = int(time.time())
from pisi.actionsapi.shelltools import makedirs touch('tests/actionsapitests/file')
self.assertEqual(os.path.getsize('tests/actionsapitests/file'), 321)
self.assert_(atime <= os.stat('tests/actionsapitests/file').st_atime)
makedirs('tests/actionsapitests/testdirectory/into/a/directory') def testShelltoolsCd(self):
self.assertEqual(os.path.exists('tests/actionsapitests/testdirectory/into/a/directory'), True) from pisi.actionsapi.shelltools import cd
shutil.rmtree('tests/actionsapitests/testdirectory')
def testShelltoolsEcho(self): current = os.getcwd()
from pisi.actionsapi.shelltools import echo cd('tests/actionsapitests')
self.assertEqual(os.path.getsize('file'), 321)
cd()
self.assertEqual(os.path.getsize('actionsapitests/file'), 321)
os.chdir(current)
echo('tests/actionsapitests/echo-file', 'hububat fiyatları') def testShelltoolsLs(self):
self.assertEqual(os.path.exists('tests/actionsapitests/echo-file'), True) from pisi.actionsapi.shelltools import ls
self.assertEqual(open('tests/actionsapitests/echo-file').readlines()[0].strip(), "hububat fiyatları")
echo('tests/actionsapitests/echo-file', 'fiyat hububatları')
self.assertEqual(open('tests/actionsapitests/echo-file').readlines()[1].strip(), "fiyat hububatları")
os.remove('tests/actionsapitests/echo-file')
self.assertEqual(os.listdir('tests/actionsapitests'), ls('tests/actionsapitests'))
self.assertEqual(os.listdir('tests/actionsapitests/linkeddir'), ls('tests/actionsapitests/linktoadirectory'))
self.assertEqual(['tests/actionsapitests/file'], ls('tests/actionsapitests/f*'))
def testShelltoolsExport(self):
from pisi.actionsapi.shelltools import export
export('hububat', 'fiyatları')
self.assertEqual(os.environ['hububat'], 'fiyatları')
del(os.environ['hububat'])
def testShelltoolsIsLink(self):
from pisi.actionsapi.shelltools import isLink
self.assert_(isLink('tests/actionsapitests/linktoadirectory'))
self.assert_(isLink('tests/actionsapitests/linktoafile'))
self.assert_(isLink('tests/actionsapitests/brokenlink'))
self.assert_(not isLink('tests/actionsapitests/file'))
self.assert_(not isLink('tests/actionsapitests/adirectory'))
def testShelltoolsIsFile(self):
from pisi.actionsapi.shelltools import isFile
self.assert_(not isFile('tests/actionsapitests/linktoadirectory'))
self.assert_(not isFile('tests/actionsapitests/linktoafile'))
self.assert_(not isFile('tests/actionsapitests/brokenlink'))
self.assert_(isFile('tests/actionsapitests/file'))
self.assert_(not isFile('tests/actionsapitests/adirectory'))
def testShelltoolsIsDirectory(self):
from pisi.actionsapi.shelltools import isDirectory
self.assert_(not isDirectory('tests/actionsapitests/linktoadirectory'))
self.assert_(not isDirectory('tests/actionsapitests/linktoafile'))
self.assert_(not isDirectory('tests/actionsapitests/brokenlink'))
self.assert_(not isDirectory('tests/actionsapitests/file'))
self.assert_(isDirectory('tests/actionsapitests/adirectory'))
def testShelltoolsSystem(self): def testShelltoolsSystem(self):
from pisi.actionsapi.shelltools import system as s from pisi.actionsapi.shelltools import system as s
@@ -150,6 +335,4 @@ class ActionsAPITestCase(testcase.TestCase):
self.assertEqual(os.path.exists('tests/actionsapitests/systest'), True) self.assertEqual(os.path.exists('tests/actionsapitests/systest'), True)
os.remove('tests/actionsapitests/systest') os.remove('tests/actionsapitests/systest')
suite = unittest.makeSuite(ActionsAPITestCase) suite = unittest.makeSuite(ActionsAPITestCase)
+1 -1
View File
@@ -35,7 +35,7 @@ class ConfigFileTestCase(unittest.TestCase):
self.assertEqual(cf.dirs.archives_dir, "/disk2/pisi/archives") self.assertEqual(cf.dirs.archives_dir, "/disk2/pisi/archives")
# test default values # test default values
self.assertEqual(cf.dirs.tmp_dir, "/var/tmp/pisi") self.assertEqual(cf.dirs.tmp_dir, "/var/pisi")
def testAccessMethods(self): def testAccessMethods(self):
cf = self.cf cf = self.cf
+1 -1
View File
@@ -15,7 +15,7 @@
<PartOf>component</PartOf> <PartOf>component</PartOf>
<Summary xml:lang="en">Dummy HelloWorld for testing ActionsAPI</Summary> <Summary xml:lang="en">Dummy HelloWorld for testing ActionsAPI</Summary>
<Description xml:lang="en">Dummy HelloWorld for testing ActionsAPI</Description> <Description xml:lang="en">Dummy HelloWorld for testing ActionsAPI</Description>
<Archive type="targz" sha1sum="c8927baab2aae5fb4d1243067ca5244e3120f2ff">http://cekirdek.uludag.org.tr/~eray/hello-1.3.tar.gz</Archive> <Archive type="targz" sha1sum="c8927baab2aae5fb4d1243067ca5244e3120f2ff">http://ftp.club.cc.cmu.edu/pub/gnu/hello/hello-1.3.tar.gz</Archive>
</Source> </Source>
<Package> <Package>
+2 -2
View File
@@ -30,7 +30,7 @@ class PackageTestCase(testcase.TestCase):
testdir = os.path.join(cur, "tests/popt") testdir = os.path.join(cur, "tests/popt")
pkg_path = os.path.join(tmpdir, self.pkgName) pkg_path = os.path.join(tmpdir, self.pkgName)
pkg = package.Package(pkg_path, "w") pkg = pisi.package.Package(pkg_path, "w")
os.chdir(testdir) os.chdir(testdir)
pkg.add_to_package("files.xml") pkg.add_to_package("files.xml")
@@ -39,7 +39,7 @@ class PackageTestCase(testcase.TestCase):
pkg.close() pkg.close()
pkg = package.Package(pkg_path) pkg = pisi.package.Package(pkg_path)
pkg.extract_file("files.xml", cur) pkg.extract_file("files.xml", cur)
if not os.path.exists("files.xml"): if not os.path.exists("files.xml"):
self.fail("Package extract error") self.fail("Package extract error")
+3 -12
View File
@@ -23,9 +23,9 @@ class SpecFileNewTestCase(unittest.TestCase):
def testFields(self): def testFields(self):
self.assertEqual(self.spec.source.name, "popt") self.assertEqual(self.spec.source.name, "popt")
self.assertEqual(self.spec.source.version, "1.7") self.assertEqual(self.spec.getSourceVersion(), "1.7")
self.assertEqual(self.spec.source.release, "1") self.assertEqual(self.spec.getSourceRelease(), "1")
self.assertEqual(self.spec.source.archive.sha1sum, self.assertEqual(self.spec.source.archive.sha1sum,
"66f3c77b87a160951b180447f4a6dce68ad2f71b") "66f3c77b87a160951b180447f4a6dce68ad2f71b")
@@ -49,6 +49,7 @@ class SpecFileNewTestCase(unittest.TestCase):
def testIsAPartOf(self): def testIsAPartOf(self):
# test existence in Source # test existence in Source
if not "app:console" in self.spec.source.isA: if not "app:console" in self.spec.source.isA:
self.fail("Failed to match IsA in Source") self.fail("Failed to match IsA in Source")
if not isinstance(self.spec.source.isA, list): if not isinstance(self.spec.source.isA, list):
@@ -57,16 +58,6 @@ class SpecFileNewTestCase(unittest.TestCase):
if "system.base" != self.spec.source.partOf: if "system.base" != self.spec.source.partOf:
self.fail("Failed to match PartOf in Source") self.fail("Failed to match PartOf in Source")
# test existence in Package
pkg = self.spec.packages[0]
if not "app:console" in pkg.isA:
self.fail("Failed to match IsA in Package")
if not isinstance(pkg.isA, list):
self.fail("source.isA is not a list, but it must be...")
if "system.base" != pkg.partOf:
self.fail("Failed to match PartOf in Package")
def testVerify(self): def testVerify(self):
if self.spec.errors(): if self.spec.errors():
self.fail("Failed to verify specfile") self.fail("Failed to verify specfile")