diff --git a/tests/actionsapitests.py b/tests/actionsapitests.py
index c5f61fb3..85fb5252 100644
--- a/tests/actionsapitests.py
+++ b/tests/actionsapitests.py
@@ -12,6 +12,9 @@ import unittest
import zipfile
import shutil
import os
+import pwd
+import grp
+import time
import testcase
@@ -25,7 +28,7 @@ class ActionsAPITestCase(testcase.TestCase):
return
self.f = zipfile.ZipFile("helloworld-0.1-1.pisi", "r")
self.filelist = []
-
+
for file in self.f.namelist():
self.filelist.append(file)
@@ -53,7 +56,7 @@ class ActionsAPITestCase(testcase.TestCase):
"install/var/goodbye", \
"install/var/hello", \
"metadata.xml"]
-
+
'''check number of files in package'''
self.assertEqual(fileContent.__len__(), self.filelist.__len__())
@@ -61,6 +64,139 @@ class ActionsAPITestCase(testcase.TestCase):
for file in self.filelist:
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):
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)
shutil.rmtree('tests/actionsapitests/adirectory/withanothername')
- def testShelltoolsCanAccessFile(self):
- from pisi.actionsapi.shelltools import can_access_file
+ def testShelltoolsCopyTree(self):
+ from pisi.actionsapi.shelltools import copytree
- 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'))
+ copytree('tests/actionsapitests/linkeddir', 'tests/actionsapitests/adirectory')
+ 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/linkeddir/file'))
+ self.assertEqual(os.path.getsize('tests/actionsapitests/adirectory/linkeddir/file'), 321)
+ shutil.rmtree('tests/actionsapitests/adirectory/linkeddir')
- def testShelltoolsCanAccessDir(self):
- from pisi.actionsapi.shelltools import can_access_directory
+ copytree('tests/actionsapitests/linkeddir', 'tests/actionsapitests/adirectory/withanothername')
+ 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'))
- self.assert_(not can_access_directory('tests/actionsapitests/adirectoryX'))
- self.assert_(can_access_directory('tests/actionsapitests/linktoadirectory'))
+ def testShelltoolsTouch(self):
+ from pisi.actionsapi.shelltools import touch
-
- def testShelltoolsMakedirs(self):
- from pisi.actionsapi.shelltools import makedirs
+ touch('tests/actionsapitests/file-touch')
+ self.assert_(os.path.exists('tests/actionsapitests/file-touch'))
+ os.remove('tests/actionsapitests/file-touch')
- makedirs('tests/actionsapitests/testdirectory/into/a/directory')
- self.assertEqual(os.path.exists('tests/actionsapitests/testdirectory/into/a/directory'), True)
- shutil.rmtree('tests/actionsapitests/testdirectory')
+ atime = int(time.time())
+ touch('tests/actionsapitests/file')
+ self.assertEqual(os.path.getsize('tests/actionsapitests/file'), 321)
+ self.assert_(atime <= os.stat('tests/actionsapitests/file').st_atime)
- def testShelltoolsEcho(self):
- from pisi.actionsapi.shelltools import echo
+ def testShelltoolsCd(self):
+ from pisi.actionsapi.shelltools import cd
- 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')
+ current = os.getcwd()
+ cd('tests/actionsapitests')
+ self.assertEqual(os.path.getsize('file'), 321)
+ cd()
+ self.assertEqual(os.path.getsize('actionsapitests/file'), 321)
+ os.chdir(current)
+ def testShelltoolsLs(self):
+ from pisi.actionsapi.shelltools import ls
+
+ 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):
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)
os.remove('tests/actionsapitests/systest')
-
-
suite = unittest.makeSuite(ActionsAPITestCase)
diff --git a/tests/configfiletests.py b/tests/configfiletests.py
index b0395001..95c0637d 100644
--- a/tests/configfiletests.py
+++ b/tests/configfiletests.py
@@ -35,7 +35,7 @@ class ConfigFileTestCase(unittest.TestCase):
self.assertEqual(cf.dirs.archives_dir, "/disk2/pisi/archives")
# test default values
- self.assertEqual(cf.dirs.tmp_dir, "/var/tmp/pisi")
+ self.assertEqual(cf.dirs.tmp_dir, "/var/pisi")
def testAccessMethods(self):
cf = self.cf
diff --git a/tests/helloworld/actions.py b/tests/helloworld/actions.py
index ccf59890..443847a5 100644
--- a/tests/helloworld/actions.py
+++ b/tests/helloworld/actions.py
@@ -20,16 +20,16 @@ WorkDir = "hello-1.3"
def setup():
autotools.configure()
-
+
def build():
autotools.make()
def install():
- autotools.install()
+ autotools.install()
'''/opt/helloworld/'''
pisitools.dodir("/opt/helloworld")
-
+
'''/usr/share/doc/helloworld-0.1-1/Makefile.am'''
pisitools.dodoc("Makefile.am")
@@ -58,7 +58,7 @@ def install():
pisitools.dobin("src/helloworld")
'''/bin/helloworld'''
pisitools.dobin("src/helloworld", "/bin")
-
+
'''/usr/sbin/helloworld'''
pisitools.dosbin("src/helloworld")
'''/sbin/helloworld'''
@@ -97,6 +97,6 @@ def install():
shelltools.unlink("%s/sys/helloworld/helloworld" % get.installDIR())
'''delete /sys/helloworld'''
shelltools.unlinkDir("%s/sys/helloworld" % get.installDIR())
-
+
'''generate /usr/lib/helloworld.o'''
libtools.gen_usr_ldscript("helloworld.o")
diff --git a/tests/helloworld/pspec.xml b/tests/helloworld/pspec.xml
index 936871f2..0e6b2c28 100644
--- a/tests/helloworld/pspec.xml
+++ b/tests/helloworld/pspec.xml
@@ -15,7 +15,7 @@
component
Dummy HelloWorld for testing ActionsAPI
Dummy HelloWorld for testing ActionsAPI
- http://cekirdek.uludag.org.tr/~eray/hello-1.3.tar.gz
+ http://ftp.club.cc.cmu.edu/pub/gnu/hello/hello-1.3.tar.gz
diff --git a/tests/packagetests.py b/tests/packagetests.py
index 93d3ecf0..1a8fd789 100644
--- a/tests/packagetests.py
+++ b/tests/packagetests.py
@@ -30,7 +30,7 @@ class PackageTestCase(testcase.TestCase):
testdir = os.path.join(cur, "tests/popt")
pkg_path = os.path.join(tmpdir, self.pkgName)
- pkg = package.Package(pkg_path, "w")
+ pkg = pisi.package.Package(pkg_path, "w")
os.chdir(testdir)
pkg.add_to_package("files.xml")
@@ -39,7 +39,7 @@ class PackageTestCase(testcase.TestCase):
pkg.close()
- pkg = package.Package(pkg_path)
+ pkg = pisi.package.Package(pkg_path)
pkg.extract_file("files.xml", cur)
if not os.path.exists("files.xml"):
self.fail("Package extract error")
diff --git a/tests/specfiletests.py b/tests/specfiletests.py
index a5f918c4..74673baa 100644
--- a/tests/specfiletests.py
+++ b/tests/specfiletests.py
@@ -19,13 +19,13 @@ class SpecFileNewTestCase(unittest.TestCase):
def setUp(self):
self.spec = specfile.SpecFile()
self.spec.read("tests/popt/pspec.xml")
-
+
def testFields(self):
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,
"66f3c77b87a160951b180447f4a6dce68ad2f71b")
@@ -49,24 +49,15 @@ class SpecFileNewTestCase(unittest.TestCase):
def testIsAPartOf(self):
# test existence in Source
+
if not "app:console" in self.spec.source.isA:
self.fail("Failed to match IsA in Source")
if not isinstance(self.spec.source.isA, list):
self.fail("source.isA is not a list, but it must be...")
-
+
if "system.base" != self.spec.source.partOf:
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):
if self.spec.errors():
self.fail("Failed to verify specfile")