* use a testcase class for proper API init/shutdown, if that doesn't

work, nothing will anyway :)
  - this new class uses the tmp dir
* make the test cases that access pisi dirs, etc. derive
from the new testcase class
* a silly Option class in config module for those who want
to give options from API. We should have default values there, too (it seems!)
* several fixes in tests, remove old style config accesses etc.
This commit is contained in:
Eray Özkural
2005-10-26 23:28:14 +00:00
parent 081a980268
commit f109b4bd1e
18 changed files with 97 additions and 64 deletions
+12 -4
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Project SYSTEM "Project-3.8.dtd">
<!-- Project file for project pisi -->
<!-- Saved: 2005-10-26, 20:31:35 -->
<!-- Saved: 2005-10-27, 02:03:24 -->
<!-- Copyright (C) 2005 PiSi Development Team, -->
<Project version="3.8">
<ProgLanguage mixed="0">Python</ProgLanguage>
@@ -364,6 +364,14 @@
<Dir>tests</Dir>
<Name>specfilenewtests.py</Name>
</Source>
<Source>
<Dir>tests</Dir>
<Name>ootests.py</Name>
</Source>
<Source>
<Dir>tests</Dir>
<Name>testcase.py</Name>
</Source>
</Sources>
<Forms>
</Forms>
@@ -402,9 +410,9 @@
</Vcs>
<FiletypeAssociations>
<FiletypeAssociation pattern="*.ui.h" type="FORMS" />
<FiletypeAssociation pattern="*.ui" type="FORMS" />
<FiletypeAssociation pattern="*.idl" type="INTERFACES" />
<FiletypeAssociation pattern="*.py" type="SOURCES" />
<FiletypeAssociation pattern="*.ptl" type="SOURCES" />
<FiletypeAssociation pattern="*.idl" type="INTERFACES" />
<FiletypeAssociation pattern="*.ui" type="FORMS" />
<FiletypeAssociation pattern="*.py" type="SOURCES" />
</FiletypeAssociations>
</Project>
+10 -2
View File
@@ -30,10 +30,17 @@ from pisi.util import join_path as join
class Error(pisi.Error):
pass
class Options(object):
def __getattr__(self, name):
if not self.__dict__.has_key(name):
return None
else:
return self.__dict__[name]
class Config(object):
"""Config Singleton"""
def __init__(self, options = None):
def __init__(self, options = Options()):
self.options = options
self.values = ConfigurationFile("/etc/pisi/pisi.conf")
@@ -56,7 +63,8 @@ class Config(object):
dir = self.values.general.destinationdirectory
import os.path
if not os.path.exists(dir):
raise Error, _('Destination directory %s does not exist') % dir
ctx.ui.warning( _('Destination directory %s does not exist. Creating it.') % dir)
os.makedirs(dir)
return dir
def subdir(self, path):
+4 -1
View File
@@ -10,8 +10,11 @@
import unittest
import zipfile
class ActionsAPITestCase(unittest.TestCase):
import testcase
class ActionsAPITestCase(testcase.TestCase):
def setUp(self):
testcase.TestCase.setUp(self)
self.f = zipfile.ZipFile("helloworld-0.1-1.pisi", "r")
self.filelist = []
+3 -12
View File
@@ -20,12 +20,11 @@ from pisi import sourcearchive
from pisi import fetcher
from pisi import util
from pisi.build import BuildContext
from pisi.config import config
from pisi import uri
class ArchiveFileTestCase(unittest.TestCase):
def setUp(self):
pisi.api.init(comar = False)
import testcase
class ArchiveFileTestCase(testcase.TestCase):
def testUnpackTar(self):
bctx = BuildContext("tests/popt/pspec.xml")
@@ -52,8 +51,6 @@ class ArchiveFileTestCase(unittest.TestCase):
self.assertEqual(util.sha1_file(testfile),
"5af9dd7d754f788cf511c57ce0af3d555fed009d")
pisi.api.finalize()
def testUnpackZip(self):
bctx = BuildContext("tests/pccts/pspec.xml")
@@ -73,8 +70,6 @@ class ArchiveFileTestCase(unittest.TestCase):
self.assertEqual(util.sha1_file(testfile),
"f2be0f9783e84e98fe4e2b8201a8f506fcc07a4d")
pisi.api.finalize()
# TODO: no link file in pccts package. Need to find a ZIP file
# containing a symlink
# check for symbolic links
@@ -97,8 +92,6 @@ class ArchiveFileTestCase(unittest.TestCase):
zip.close()
#TODO: do some more work to test the integrity of new zip file
pisi.api.finalize()
def testUnpackZipCond(self):
bctx = BuildContext("tests/pccts/pspec.xml")
@@ -118,6 +111,4 @@ class ArchiveFileTestCase(unittest.TestCase):
testfile = targetDir + "/pccts/history.txt"
assert pathexists(testfile)
pisi.api.finalize()
suite = unittest.makeSuite(ArchiveFileTestCase)
+1
View File
@@ -12,6 +12,7 @@ import unittest
from pisi.configfile import ConfigurationFile
# NB: no need for pisi testcase in these things that do well without pisi init
class ConfigFileTestCase(unittest.TestCase):
def setUp(self):
+3 -2
View File
@@ -18,9 +18,10 @@ from pisi import fetcher
from pisi import util
from pisi import uri
class FetcherTestCase(unittest.TestCase):
import testcase
class FetcherTestCase(testcase.TestCase):
def setUp(self):
pisi.api.init(database = False, comar = False)
testcase.TestCase.setUp(self, database = False)
self.spec = SpecFile()
self.spec.read("tests/popt/pspec.xml")
-1
View File
@@ -12,7 +12,6 @@ import unittest
import os
from pisi import graph
from pisi.config import config
class GraphTestCase(unittest.TestCase):
def setUp(self):
+2 -8
View File
@@ -16,21 +16,16 @@ import pisi.api
import pisi.installdb
from pisi import util
class InstallDBTestCase(unittest.TestCase):
def setUp(self):
pisi.api.init(database = True, comar = False)
import testcase
class InstallDBTestCase(testcase.TestCase):
def testRemoveDummy(self):
ctx.installdb.remove('installtest')
self.assert_(not ctx.installdb.is_installed('installtest'))
pisi.api.finalize()
def testInstall(self):
ctx.installdb.purge('installtest')
ctx.installdb.install('installtest', '0.1', '2', '3')
pisi.api.finalize()
def testRemovePurge(self):
ctx.installdb.install('installtest', '0.1', '2', '3')
@@ -39,6 +34,5 @@ class InstallDBTestCase(unittest.TestCase):
self.assert_(ctx.installdb.is_removed('installtest'))
ctx.installdb.purge('installtest')
self.assert_(not ctx.installdb.is_recorded('installtest'))
pisi.api.finalize()
suite = unittest.makeSuite(InstallDBTestCase)
+5 -6
View File
@@ -13,12 +13,11 @@ import os
from pisi import metadata
from pisi import util
from pisi.config import config
import pisi.context as ctx
import testcase
class MetaDataTestCase(testcase.TestCase):
class MetaDataTestCase(unittest.TestCase):
def setUp(self):
pass
def testRead(self):
md = metadata.MetaData()
md.read('tests/popt/metadata.xml')
@@ -32,7 +31,7 @@ class MetaDataTestCase(unittest.TestCase):
def testWrite(self):
md = self.testRead()
md.write(os.path.join(config.tmp_dir(),'metadata-test.xml' ))
md.write(os.path.join(ctx.config.tmp_dir(),'metadata-test.xml' ))
def testVerify(self):
md = self.testRead()
+3 -6
View File
@@ -17,11 +17,11 @@ from pisi.packagedb import PackageDB
from pisi import util
from pisi.specfile import SpecFile
class PackageDBTestCase(unittest.TestCase):
import testcase
class PackageDBTestCase(testcase.TestCase):
def setUp(self):
pisi.api.init(comar = False)
testcase.TestCase.setUp(self)
self.spec = SpecFile()
self.spec.read('tests/popt/pspec.xml')
@@ -32,13 +32,10 @@ class PackageDBTestCase(unittest.TestCase):
self.assert_(self.pdb.has_package('popt-libs'))
# close the database and remove lock
self.pdb.close()
pisi.api.finalize()
def testRemove(self):
self.pdb.remove_package('popt-libs')
self.assert_(not self.pdb.has_package('popt-libs'))
self.pdb.close()
pisi.api.finalize()
suite = unittest.makeSuite(PackageDBTestCase)
+5 -4
View File
@@ -12,20 +12,21 @@ import unittest
import os
from pisi import util
from pisi.config import config
import pisi.context as ctx
from pisi import package
class PackageTestCase(unittest.TestCase):
import testcase
class PackageTestCase(testcase.TestCase):
def setUp(self):
testcase.TestCase.setUp(self)
self.pkgName = util.package_name("testing",
"5.1",
"2")
def testAddExtract(self):
cur = os.getcwd()
tmpdir = config.tmp_dir()
tmpdir = ctx.config.tmp_dir()
testdir = os.path.join(cur, "tests/popt")
pkg_path = os.path.join(tmpdir, self.pkgName)
+3 -2
View File
@@ -17,10 +17,11 @@ import pisi.sourcedb
from pisi import util
from pisi.specfile import SpecFile
class SourceDBTestCase(unittest.TestCase):
import testcase
class SourceDBTestCase(testcase.TestCase):
def setUp(self):
pisi.api.init(comar = False)
testcase.TestCase.setUp(self)
self.sourcedb = pisi.sourcedb.init()
self.spec = SpecFile()
+7 -4
View File
@@ -12,11 +12,15 @@ import unittest
import os
import pisi.specfilenew as specfile
from pisi.config import config
import pisi.context as ctx
import pisi.util as util
class SpecFileNewTestCase(unittest.TestCase):
import testcase
class SpecFileNewTestCase(testcase.TestCase):
def setUp(self):
testcase.TestCase.setUp(self)
self.spec = specfile.SpecFile()
self.spec.read("tests/popt/pspec.xml")
@@ -72,9 +76,8 @@ class SpecFileNewTestCase(unittest.TestCase):
self.fail("Failed to verify specfile")
def testCopy(self):
util.check_dir(config.tmp_dir())
util.check_dir(ctx.config.tmp_dir())
self.spec.read("tests/popt/pspec.xml")
self.spec.write(os.path.join(config.tmp_dir(), 'popt-copy.pspec.xml'))
suite = unittest.makeSuite(SpecFileNewTestCase)
+7 -4
View File
@@ -12,11 +12,14 @@ import unittest
import os
from pisi import specfile
from pisi.config import config
import pisi.context as ctx
import pisi.util as util
class SpecFileTestCase(unittest.TestCase):
import testcase
class SpecFileTestCase(testcase.TestCase):
def setUp(self):
testcase.TestCase.setUp(self)
self.spec = specfile.SpecFile()
self.spec.read("tests/popt/pspec.xml")
@@ -72,9 +75,9 @@ class SpecFileTestCase(unittest.TestCase):
self.fail("Failed to verify specfile")
def testCopy(self):
util.check_dir(config.tmp_dir())
self.spec.read("tests/popt/pspec.xml")
self.spec.write(os.path.join(config.tmp_dir(), 'popt-copy.pspec.xml'))
util.check_dir(ctx.config.tmp_dir())
self.spec.write(os.path.join(ctx.config.tmp_dir(), 'popt-copy.pspec.xml'))
suite = unittest.makeSuite(SpecFileTestCase)
+27
View File
@@ -0,0 +1,27 @@
# Copyright (C) 2005, TUBITAK/UEKAE
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.
#
import unittest
import os
import pisi
import pisi.api
import pisi.util
import pisi.config
class TestCase(unittest.TestCase):
def setUp(self, comar = False, database = True):
options = pisi.config.Options()
options.destdir = 'tmp'
pisi.api.init(options = options, comar = comar, database = database)
def tearDown(self, ):
pisi.api.finalize()
+1 -1
View File
@@ -15,6 +15,7 @@ from pisi import version
from pisi.util import *
class UtilTestCase(unittest.TestCase):
def setUp(self):
pass
@@ -32,4 +33,3 @@ class UtilTestCase(unittest.TestCase):
suite = unittest.makeSuite(UtilTestCase)
+3 -4
View File
@@ -17,14 +17,13 @@ import types
import pisi
import pisi.api
from pisi import xmlfile
from pisi.config import config
import pisi.context as ctx
import pisi.util as util
from pisi.xmlext import *
class XmlFileTestCase(unittest.TestCase):
import testcase
def setUp(self):
pisi.api.init(database = False, comar = False)
class XmlFileTestCase(testcase.TestCase):
def testMetaClass(self):
+1 -3
View File
@@ -17,8 +17,6 @@ sys.path.append('.')
import pisi.uri
import pisi.specfile
import pisi.util as util
from pisi.config import config
from pisi.fetcher import fetch_url
def scanPSPEC(folder):
@@ -50,7 +48,7 @@ if __name__ == "__main__":
if not isCached(URI.filename(), spec.source.archiveSHA1):
print URI, " -> " , os.path.join(config.archives_dir(), URI.filename())
try:
fetch_url(URI, config.archives_dir())
fetch_url(URI, config.archives_dir())
except pisi.fetcher.FetchError, e:
print e
pass