[csw-devel] SF.net SVN: gar:[8178] csw/mgar/gar/v2-dirpackage
wahwah at users.sourceforge.net
wahwah at users.sourceforge.net
Mon Jan 25 17:44:36 CET 2010
Revision: 8178
http://gar.svn.sourceforge.net/gar/?rev=8178&view=rev
Author: wahwah
Date: 2010-01-25 16:44:20 +0000 (Mon, 25 Jan 2010)
Log Message:
-----------
mGAR v2-dirpackage: moving the library to lib/python, moving the test definitions to a separate file.
Modified Paths:
--------------
csw/mgar/gar/v2-dirpackage/tests/run_tests.py
Added Paths:
-----------
csw/mgar/gar/v2-dirpackage/lib/python/gartest.py
csw/mgar/gar/v2-dirpackage/lib/python/opencsw_test.py
csw/mgar/gar/v2-dirpackage/tests/example_test.py
Removed Paths:
-------------
csw/mgar/gar/v2-dirpackage/tests/gartest.py
Copied: csw/mgar/gar/v2-dirpackage/lib/python/gartest.py (from rev 8165, csw/mgar/gar/v2-dirpackage/tests/gartest.py)
===================================================================
--- csw/mgar/gar/v2-dirpackage/lib/python/gartest.py (rev 0)
+++ csw/mgar/gar/v2-dirpackage/lib/python/gartest.py 2010-01-25 16:44:20 UTC (rev 8178)
@@ -0,0 +1,185 @@
+# $Id$
+#
+# Style guide:
+# http://code.google.com/p/soc/wiki/PythonStyleGuide
+
+import Cheetah.Template
+import shutil
+import tempfile
+import unittest
+import os
+import os.path
+import subprocess
+import sys
+import opencsw
+
+"""A module used to do end-to-end testing of GAR."""
+
+MAKEFILE_TMPL = """# GAR Makefile generated by $test_id
+#for varname in $sorted($garvars)
+$varname = $garvars[$varname]
+#end for
+#if $blurb
+define BLURB
+ $blurb
+endef
+#end if
+include gar/category.mk
+#if $install_files
+post-install-modulated:
+#for filedir_name, directory, file_name, content in $install_files
+\tginstall -m 755 -d \$(DESTDIR)$directory
+\tginstall -m 644 \$(FILEDIR)/$filedir_name \$(DESTDIR)$directory/$file_name
+#end for
+#end if
+# GAR recipe ends here.
+"""
+TMPDIR_PREFIX = "gartest-"
+# FIXME: This information should be pulled out from GAR
+DIR_PKG_OUT_DIR = os.path.join(os.environ["HOME"], "spool.5.8-sparc")
+
+
+class Error(Exception):
+ pass
+
+
+class GarBuild(object):
+
+ def __init__(self):
+ self.built = False
+ self.packages = None
+ self.cleanup = True
+
+ def GetDebugHelp(self):
+ """To be overriden in subclasses."""
+ return ("When subclassing GarBuild, add here "
+ "information about how to reproduce\n"
+ "the build problem.")
+
+ def Build(self):
+ if self.built:
+ return 0
+ args = ["gmake", "dirpackage"]
+ gar_proc = subprocess.Popen(args, cwd=self.build_dir,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ stdout, stderr = gar_proc.communicate()
+ ret = gar_proc.wait()
+ if ret:
+ print "ERROR: GAR run has failed."
+ print stdout
+ print stderr
+ self.built = False
+ # To allow debugging, don't clean up, leaving the files for inspection.
+ self.cleanup = False
+ print self.GetDebugHelp()
+ else:
+ self.built = True
+ return ret
+
+ def GetBuiltPackages(self):
+ if not self.built:
+ raise Error("The packages have not been built yet.")
+ args = ["gmake", "pkglist"]
+ gar_proc = subprocess.Popen(args, cwd=self.build_dir, stdout=subprocess.PIPE)
+ stdout, stderr = gar_proc.communicate()
+ ret = gar_proc.wait()
+ pkglist = []
+ for line in stdout.splitlines():
+ # directory, catalogname, pkgname
+ pkglist.append(tuple(line.split("\t")))
+ self.packages = [
+ opencsw.DirectoryFormatPackage(
+ os.path.join(DIR_PKG_OUT_DIR, z))
+ for x, y, z in pkglist]
+ return self.packages
+
+ def GetFirstBuiltPackage(self):
+ """Returns only the first package. Easy to use."""
+ packages = self.GetBuiltPackages()
+ if packages:
+ return packages[0]
+
+
+class DynamicGarBuild(GarBuild):
+ """Represents a GAR build.
+
+ Can create a GAR build and execute it.
+ """
+ def __init__(self):
+ super(DynamicGarBuild, self).__init__()
+ self.build_dir = tempfile.mkdtemp(prefix=TMPDIR_PREFIX)
+ self.filedir = os.path.join(self.build_dir, "files")
+ self.makefile_filename = os.path.join(self.build_dir, "Makefile")
+ os.mkdir(self.filedir)
+ self.install_files = []
+ self.garvars = {
+ "GARNAME": "testbuild",
+ "DESCRIPTION": u"A test package from %s" % self,
+ "CATEGORIES": "lib",
+ "CONFIGURE_ARGS": "$(DIRPATHS)",
+ "SPKG_SOURCEURL": "http://www.opencsw.org/",
+ "MASTER_SITES": "",
+ "GARVERSION": "0.0.1",
+ "CONFIGURE_SCRIPTS": "",
+ "BUILD_SCRIPTS": "",
+ "TEST_SCRIPTS": "",
+ "INSTALL_SCRIPTS": "",
+ }
+ self.tmpldata = {
+ "garvars": self.garvars,
+ "garsrc": os.path.join(os.getcwd(), ".."),
+ "blurb": None,
+ "install_files": self.install_files,
+ "build_dir": self.build_dir,
+ "test_id": "$Id$",
+ }
+ os.symlink(self.tmpldata["garsrc"], os.path.join(self.build_dir, "gar"))
+
+ def SetGarVariable(self, varname, value):
+ self.garvars[varname] = value
+
+ def WriteGarFiles(self):
+ for filedir_name, directory, filename, content in self.install_files:
+ file_path = os.path.join(self.filedir, filedir_name)
+ # print "Writing to %s" % file_path
+ fp = open(file_path, "w")
+ fp.write(content)
+ fp.close()
+ searchlist = [self.tmpldata]
+ t = Cheetah.Template.Template(MAKEFILE_TMPL, searchlist)
+ # For easy debugging, but only until we find a better solution, because it
+ # clutters the screen.
+ # print t
+ fp = open(self.makefile_filename, "w")
+ fp.write(str(t))
+ fp.close()
+
+ def AddInstallFile(self, file_path, content):
+ """Creates a file in the package, with the given path and content."""
+ filedir_name = file_path.replace("/", "-")
+ directory, file_name = os.path.split(file_path)
+ self.install_files.append((filedir_name, directory,
+ file_name, content))
+
+ def GetDebugHelp(self):
+ return ("Please look into %s.\n"
+ "Remember to remove it when you're done debugging."
+ % repr(self.build_dir))
+
+ def __del__(self):
+ if self.cleanup:
+ shutil.rmtree(self.build_dir)
+
+
+class StaticGarBuild(GarBuild):
+
+ def __init__(self, build_dir):
+ super(StaticGarBuild, self).__init__()
+ self.build_dir = build_dir
+
+ def __del__(self):
+ if self.cleanup:
+ shutil.rmtree(os.path.join(self.build_dir, "work"))
+
+# vim:set ts=2 sts=2 sw=2 expandtab:
Added: csw/mgar/gar/v2-dirpackage/lib/python/opencsw_test.py
===================================================================
--- csw/mgar/gar/v2-dirpackage/lib/python/opencsw_test.py (rev 0)
+++ csw/mgar/gar/v2-dirpackage/lib/python/opencsw_test.py 2010-01-25 16:44:20 UTC (rev 8178)
@@ -0,0 +1,232 @@
+#!/opt/csw/bin/python2.6
+# $Id$
+
+import opencsw
+import unittest
+import re
+
+CATALOG_DATA_1 = """amavisd_new 2.6.3,REV=2009.04.23 CSWamavisdnew amavisd_new-2.6.3,REV=2009.04.23-SunOS5.8-all-CSW.pkg.gz 831f063d1ba20eb8bea0e0e60ceef3cb 813802 CSWperl|CSWcswclassutils|CSWpmunixsyslog|CSWpmiostringy|CSWpmnetserver|CSWpmmailtools|CSWpmmimetools|CSWpmcompresszlib|CSWpmarchivetar|CSWpmarchivezip|CSWspamassassin|CSWpmberkeleydb|CSWpmconverttnef|CSWpmconvertuulib|CSWpmmaildkim|CSWcommon none
+amsn 0.94 CSWamsn amsn-0.94-SunOS5.8-all-CSW.pkg.gz 99afd828dd38fb39a37cb8ffd448b098 2420919 CSWtcl|CSWtk|CSWtcltls none
+analog 5.32,REV=2003.9.12 CSWanalog analog-5.32,REV=2003.9.12-SunOS5.8-sparc-CSW.pkg.gz a2550ef2e37c67d475a19348b7276a38 711992 CSWcommon none
+angband 3.0.3 CSWangband angband-3.0.3-SunOS5.8-sparc-CSW.pkg.gz 9280ff14bde4523d6032ede46c7630e3 1402841 CSWcommon|CSWgtk none
+anjuta 1.2.2,REV=2005.03.01 CSWanjuta anjuta-1.2.2,REV=2005.03.01-SunOS5.8-sparc-CSW.pkg.gz 095ba6d763f157b0ce38922447c923b2 6502489 CSWaudiofile|CSWbonobo2|CSWcommon|CSWesound|CSWexpat|CSWfconfig|CSWftype2|CSWgconf2|CSWggettext|CSWglib2|CSWgnomekeyring|CSWgnomevfs2|CSWgtk2|CSWiconv|CSWjpeg|CSWlibart|CSWlibatk|CSWlibbonoboui|CSWlibglade2|CSWlibgnome|CSWlibgnomecanvas|CSWlibgnomeprint|CSWlibgnomeprintui|CSWlibgnomeui|CSWlibpopt|CSWlibxft2|CSWlibxml2|CSWlibxrender|CSWorbit2|CSWossl|CSWpango|CSWpcre|CSWvte|CSWzlib none
+ant 1.7.1,REV=2008.10.29 CSWant ant-1.7.1,REV=2008.10.29-SunOS5.8-all-CSW.pkg.gz 0945884a52a3b43b743650c60ac21236 2055045 CSWcommon|CSWxercesj|CSWxmlcommonsext none
+foo 1.7.1,REV=2008.10.29 CSWfoo foo-1.7.1,REV=2008.10.29-SunOS5.8-all-CSW.pkg.gz 0945884a52a3b43b743650c60ac21236 2055045 CSWcommon|CSWxercesj|CSWxmlcommonsext none
+foo_devel 1.7.1,REV=2008.10.29 CSWfoo_devel foo_devel-1.7.1,REV=2008.10.29-SunOS5.8-all-CSW.pkg.gz 0945884a52a3b43b743650c60ac21236 2055045 CSWcommon|CSWxercesj|CSWxmlcommonsext none
+libfoo 1.7.1,REV=2008.10.29 CSWlibfoo libfoo-1.7.1,REV=2008.10.29-SunOS5.8-all-CSW.pkg.gz 0945884a52a3b43b743650c60ac21236 2055045 CSWcommon|CSWxercesj|CSWxmlcommonsext none
+foodoc 1.7.1,REV=2008.10.29 CSWfoodoc foodoc-1.7.1,REV=2008.10.29-SunOS5.8-all-CSW.pkg.gz 0945884a52a3b43b743650c60ac21236 2055045 CSWcommon|CSWxercesj|CSWxmlcommonsext none
+bar 1.7.1,REV=2008.10.29 CSWbar bar-1.7.1,REV=2008.10.29-SunOS5.8-all-CSW.pkg.gz 0945884a52a3b43b743650c60ac21236 2055045 CSWcommon|CSWxercesj|CSWxmlcommonsext none
+antdoc 1.7.1,REV=2008.10.29 CSWantdoc antdoc-1.7.1,REV=2008.10.29-SunOS5.8-all-CSW.pkg.gz e6555e61e7e7f1740935d970e5efad57 5851724 CSWcommon none"""
+TEST_PKGINFO="""ARCH=i386
+BASEDIR=/
+CATEGORY=system
+DESC=GNU Bourne-Again shell (bash) version 3.0
+EMAIL=
+HOTLINE=Please contact your local service provider
+MAXINST=1000
+NAME=GNU Bourne-Again shell (bash)
+PKG=SUNWbash
+SUNW_PKGTYPE=usr
+SUNW_PKGVERS=1.0
+SUNW_PRODNAME=SunOS
+SUNW_PRODVERS=5.10/SunOS Development
+VENDOR=Sun Microsystems, Inc.
+VERSION=11.10.0,REV=2005.01.08.01.09
+PSTAMP=sfw10-patch-x20070430084427
+CLASSES=none
+PATCHLIST=126547-01
+PATCH_INFO_126547-01=Installed: Mon Oct 27 08:52:07 PDT 2008 From: mum Obsoletes: Requires: Incompatibles:
+PKG_SRC_NOVERIFY= none
+PKG_DST_QKVERIFY= none
+PKG_CAS_PASSRELATIVE= none
+#FASPACD= none
+"""
+
+
+class ParsePackageFileNameTest(unittest.TestCase):
+
+ def testParsePackageFileName1(self):
+ test_data = open("example-catalog.txt")
+ split_re = re.compile(r"\s+")
+ for line in test_data:
+ fields = re.split(split_re, line)
+ catalogname = fields[0]
+ pkg_version = fields[1]
+ pkgname = fields[2]
+ file_name = fields[3]
+ pkg_md5 = fields[4]
+ pkg_size = fields[5]
+ depends_on = fields[6]
+ compiled = opencsw.ParsePackageFileName(file_name)
+ self.assertTrue(compiled, "File name %s did not compile" % repr(file_name))
+ self.assertEqual(catalogname, compiled["catalogname"])
+ self.assertEqual(pkg_version, compiled["full_version_string"])
+
+
+class UpgradeTypeTest(unittest.TestCase):
+
+ def testUpgradeType_1(self):
+ pkg = opencsw.CatalogBasedOpencswPackage("analog")
+ pkg.LazyDownloadCatalogData(CATALOG_DATA_1.splitlines())
+ expected_data = {
+ 'catalogname': 'analog',
+ 'full_version_string': '5.32,REV=2003.9.12',
+ 'version': '5.32',
+ 'version_info': {opencsw.MAJOR_VERSION: '5',
+ opencsw.MINOR_VERSION: '32'},
+ 'revision_info': {'REV': '2003.9.12'},
+ }
+ self.assertEqual(expected_data, pkg.GetCatalogPkgData())
+
+ def testUpgradeType_2(self):
+ pkg = opencsw.CatalogBasedOpencswPackage("analog")
+ pkg.LazyDownloadCatalogData(CATALOG_DATA_1.splitlines())
+ unused_old_version_string = "5.32,REV=2003.9.12"
+ new_version_string = "5.32,REV=2003.9.13"
+ upgrade_type, upgrade_description, vs = pkg.UpgradeType(new_version_string)
+ self.assertEqual(opencsw.REVISION, upgrade_type)
+
+ def testUpgradeType_3(self):
+ pkg = opencsw.CatalogBasedOpencswPackage("analog")
+ pkg.LazyDownloadCatalogData(CATALOG_DATA_1.splitlines())
+ unused_old_version_string = "5.32,REV=2003.9.12"
+ new_version_string = "5.33,REV=2003.9.12"
+ upgrade_type, upgrade_description, vs = pkg.UpgradeType(new_version_string)
+ self.assertEqual(opencsw.MINOR_VERSION, upgrade_type)
+
+ def testUpgradeType_4(self):
+ pkg = opencsw.CatalogBasedOpencswPackage("analog")
+ pkg.LazyDownloadCatalogData(CATALOG_DATA_1.splitlines())
+ unused_old_version_string = "5.32,REV=2003.9.12"
+ new_version_string = "6.0,REV=2003.9.12"
+ upgrade_type, upgrade_description, vs = pkg.UpgradeType(new_version_string)
+ self.assertEqual(opencsw.MAJOR_VERSION, upgrade_type)
+
+ def testUpgradeType_5(self):
+ pkg = opencsw.CatalogBasedOpencswPackage("nonexisting")
+ pkg.LazyDownloadCatalogData(CATALOG_DATA_1.splitlines())
+ unused_old_version_string = "5.32,REV=2003.9.12"
+ new_version_string = "6.0,REV=2003.9.12"
+ upgrade_type, upgrade_description, vs = pkg.UpgradeType(new_version_string)
+ self.assertEqual(opencsw.NEW_PACKAGE, upgrade_type)
+
+ def testUpgradeType_6(self):
+ pkg = opencsw.CatalogBasedOpencswPackage("analog")
+ pkg.LazyDownloadCatalogData(CATALOG_DATA_1.splitlines())
+ unused_old_version_string = "5.32,REV=2003.9.12"
+ new_version_string = "5.32,REV=2003.9.12"
+ upgrade_type, upgrade_description, vs = pkg.UpgradeType(new_version_string)
+ self.assertEqual(opencsw.NO_VERSION_CHANGE, upgrade_type)
+
+ def testUpgradeType_7(self):
+ pkg = opencsw.CatalogBasedOpencswPackage("angband")
+ pkg.LazyDownloadCatalogData(CATALOG_DATA_1.splitlines())
+ unused_old_version_string = "3.0.3"
+ new_version_string = "3.0.3,REV=2003.9.12"
+ upgrade_type, upgrade_description, vs = pkg.UpgradeType(new_version_string)
+ self.assertEqual(opencsw.REVISION_ADDED, upgrade_type)
+
+ def testUpgradeType_8(self):
+ pkg = opencsw.CatalogBasedOpencswPackage("angband")
+ pkg.LazyDownloadCatalogData(CATALOG_DATA_1.splitlines())
+ unused_old_version_string = "3.0.3"
+ new_version_string = "3.0.4,REV=2003.9.12"
+ upgrade_type, upgrade_description, vs = pkg.UpgradeType(new_version_string)
+ self.assertEqual(opencsw.PATCHLEVEL, upgrade_type)
+
+class PackageTest(unittest.TestCase):
+
+ def test_2(self):
+ expected = {
+ 'SUNW_PRODVERS': '5.10/SunOS Development',
+ 'PKG_CAS_PASSRELATIVE': ' none',
+ 'PKG_SRC_NOVERIFY': ' none',
+ 'PSTAMP': 'sfw10-patch-x20070430084427',
+ 'ARCH': 'i386',
+ 'EMAIL': '',
+ 'MAXINST': '1000',
+ 'PATCH_INFO_126547-01': 'Installed: Mon Oct 27 08:52:07 PDT 2008 From: mum Obsoletes: Requires: Incompatibles:',
+ 'PKG': 'SUNWbash',
+ 'SUNW_PKGTYPE': 'usr',
+ 'PKG_DST_QKVERIFY': ' none',
+ 'SUNW_PKGVERS': '1.0',
+ 'VENDOR': 'Sun Microsystems, Inc.',
+ 'BASEDIR': '/',
+ 'CLASSES': 'none',
+ 'PATCHLIST': '126547-01',
+ 'DESC': 'GNU Bourne-Again shell (bash) version 3.0',
+ 'CATEGORY': 'system',
+ 'NAME': 'GNU Bourne-Again shell (bash)',
+ 'SUNW_PRODNAME': 'SunOS',
+ 'VERSION': '11.10.0,REV=2005.01.08.01.09',
+ 'HOTLINE': 'Please contact your local service provider',
+ }
+ self.assertEquals(expected,
+ opencsw.ParsePkginfo(TEST_PKGINFO.splitlines()))
+
+ def testSplitByCase1(self):
+ self.assertEquals(["aaa", "bbb"], opencsw.SplitByCase("AAAbbb"))
+
+ def testSplitByCase2(self):
+ self.assertEquals(["aaa", "bbb", "ccc"], opencsw.SplitByCase("AAAbbb-ccc"))
+
+ def testPkgnameToCatName1(self):
+ self.assertEquals("sunw_bash", opencsw.PkgnameToCatName("SUNWbash"))
+
+ def testPkgnameToCatName2(self):
+ self.assertEquals("sunw_bash_s", opencsw.PkgnameToCatName("SUNWbashS"))
+
+ def testPkgnameToCatName3(self):
+ """These are the rules!"""
+ self.assertEquals("sunw_p_ython", opencsw.PkgnameToCatName("SUNWPython"))
+
+ def testPkgnameToCatName4(self):
+ self.assertEquals("stuf_with_some_dashes",
+ opencsw.PkgnameToCatName("STUFwith-some-dashes"))
+
+ def test_4(self):
+ pkginfo_dict = opencsw.ParsePkginfo(TEST_PKGINFO.splitlines())
+ expected = "sunw_bash-11.10.0,REV=2005.01.08.01.09-SunOS5.10-i386-SUNW.pkg"
+ self.assertEquals(expected, opencsw.PkginfoToSrv4Name(pkginfo_dict))
+
+
+class PackageGroupNameTest(unittest.TestCase):
+
+ @classmethod
+ def CreatePkgList(self, catalogname_list):
+ pkg_list = []
+ for name in catalogname_list:
+ pkg = opencsw.CatalogBasedOpencswPackage("foo")
+ pkg.LazyDownloadCatalogData(CATALOG_DATA_1.splitlines())
+ pkg_list.append(pkg)
+ return pkg_list
+
+ def testPackageGroupName_0(self):
+ data = [
+ ("foo", ["foo"]),
+ ("foo", ["foo", "libfoo"]),
+ ("foo", ["foo", "libfoo", "foo_devel"]),
+ ("various packages", ["foo", "libfoo", "foo_devel", "bar"]),
+ ]
+ for expected_name, catalogname_list in data:
+ result = opencsw.CatalogNameGroupName(catalogname_list)
+ self.assertEqual(expected_name, result,
+ "data: %s, expected: %s, got: %s" % (catalogname_list,
+ repr(expected_name),
+ repr(result)))
+
+ def testLongestCommonSubstring_1(self):
+ self.assertEqual(set(["foo"]), opencsw.LongestCommonSubstring("foo", "foo"))
+
+ def testLongestCommonSubstring_2(self):
+ self.assertEqual(set([]), opencsw.LongestCommonSubstring("foo", "bar"))
+
+ def testLongestCommonSubstring_3(self):
+ self.assertEqual(set(["bar"]), opencsw.LongestCommonSubstring("barfoobar", "bar"))
+
+ def testLongestCommonSubstring_4(self):
+ self.assertEqual(set(['bcd', 'hij']), opencsw.LongestCommonSubstring("abcdefghijk", "bcdhij"))
+
+
+if __name__ == '__main__':
+ unittest.main()
Property changes on: csw/mgar/gar/v2-dirpackage/lib/python/opencsw_test.py
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:keywords
+ Id
Added: csw/mgar/gar/v2-dirpackage/tests/example_test.py
===================================================================
--- csw/mgar/gar/v2-dirpackage/tests/example_test.py (rev 0)
+++ csw/mgar/gar/v2-dirpackage/tests/example_test.py 2010-01-25 16:44:20 UTC (rev 8178)
@@ -0,0 +1,40 @@
+# $Id$
+
+import unittest
+import sys
+sys.path.append("../lib/python")
+import gartest
+
+class ExampleEndToEndTest(unittest.TestCase):
+ """An example end-to-end test of GAR."""
+
+ def testPkginfoName(self):
+ """Checks that the GARNAME makes it to the NAME in pkginfo."""
+ mybuild = gartest.DynamicGarBuild()
+ mybuild.SetGarVariable("GARNAME", "foo")
+ mybuild.AddInstallFile("/opt/csw/share/foo", "bar!\n")
+ mybuild.WriteGarFiles()
+ self.assertEquals(0, mybuild.Build())
+ pkg = mybuild.GetFirstBuiltPackage()
+ pkginfo = pkg.GetParsedPkginfo()
+ # By default, the garname should be used to create the catalog name, which
+ # in turn ends up in the NAME field in pkginfo.
+ self.assertTrue(pkginfo["NAME"].startswith("foo"))
+
+
+class StaticBuildTestExample(unittest.TestCase):
+ """An example of a static build.
+
+ This uses a static directory where GAR can be called.
+ """
+
+ def testLooseFiles(self):
+ mybuild = gartest.StaticGarBuild("static/example")
+ mybuild.Build()
+ pkg = mybuild.GetFirstBuiltPackage()
+ pkginfo = pkg.GetParsedPkginfo()
+ # This part would often use "self.assertEqual(<expected>, <actual>)"
+ self.assertTrue(pkginfo["NAME"].startswith("loose"))
+
+# To add more tests, create a Python file similar to this one, and add the
+# corresponding import statement to the run_tests.py file.
Property changes on: csw/mgar/gar/v2-dirpackage/tests/example_test.py
___________________________________________________________________
Added: svn:keywords
+ Id
Deleted: csw/mgar/gar/v2-dirpackage/tests/gartest.py
===================================================================
--- csw/mgar/gar/v2-dirpackage/tests/gartest.py 2010-01-25 16:24:21 UTC (rev 8177)
+++ csw/mgar/gar/v2-dirpackage/tests/gartest.py 2010-01-25 16:44:20 UTC (rev 8178)
@@ -1,176 +0,0 @@
-# $Id$
-
-import Cheetah.Template
-import shutil
-import tempfile
-import unittest
-import os
-import os.path
-import subprocess
-import opencsw
-
-"""A module used to do end-to-end testing of GAR."""
-
-MAKEFILE_TMPL = """# GAR Makefile generated by $test_id
-#for varname in $sorted($garvars)
-$varname = $garvars[$varname]
-#end for
-#if $blurb
-define BLURB
- blurb
-endef
-#end if
-include gar/category.mk
-#if $install_files
-post-install-modulated:
-#for filedir_name, directory, file_name, content in $install_files
-\tginstall -m 755 -d \$(DESTDIR)$directory
-\tginstall -m 644 \$(FILEDIR)/$filedir_name \$(DESTDIR)$directory/$file_name
-#end for
-#end if
-# GAR recipe ends here.
-"""
-TMPDIR_PREFIX = "gartest-"
-# FIXME: This information should be pulled out from GAR
-DIR_PKG_OUT_DIR = os.path.join(os.environ["HOME"], "spool.5.8-sparc")
-
-class Error(Exception):
- pass
-
-
-class GarBuild(object):
-
- def __init__(self):
- self.built = False
- self.packages = None
- self.cleanup = True
-
- def GetDebugHelp(self):
- """To be overriden in subclasses."""
- return ""
-
- def Build(self):
- if self.built:
- return 0
- args = ["gmake", "dirpackage"]
- gar_proc = subprocess.Popen(args, cwd=self.tmpdir,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- stdout, stderr = gar_proc.communicate()
- ret = gar_proc.wait()
- if ret:
- print "ERROR: GAR run has failed."
- print stdout
- print stderr
- self.built = False
- # To allow debugging
- self.cleanup = False
- print self.GetDebugHelp()
- else:
- self.built = True
- return ret
-
- def GetBuiltPackages(self):
- if not self.built:
- raise Error("The packages have not been built yet.")
- args = ["gmake", "pkglist"]
- gar_proc = subprocess.Popen(args, cwd=self.tmpdir, stdout=subprocess.PIPE)
- stdout, stderr = gar_proc.communicate()
- ret = gar_proc.wait()
- pkglist = []
- for line in stdout.splitlines():
- # directory, catalogname, pkgname
- pkglist.append(tuple(line.split("\t")))
- self.packages = [
- opencsw.DirectoryFormatPackage(
- os.path.join(DIR_PKG_OUT_DIR, z))
- for x, y, z in pkglist]
- return self.packages
-
- def GetFirstBuiltPackage(self):
- """Returns only the first package. Easy to use."""
- packages = self.GetBuiltPackages()
- if packages:
- return packages[0]
-
-
-class DynamicGarBuild(GarBuild):
- """Represents a GAR build.
-
- Can create a GAR build and execute it.
- """
- def __init__(self):
- super(DynamicGarBuild, self).__init__()
- self.tmpdir = tempfile.mkdtemp(prefix=TMPDIR_PREFIX)
- self.filedir = os.path.join(self.tmpdir, "files")
- self.makefile_filename = os.path.join(self.tmpdir, "Makefile")
- os.mkdir(self.filedir)
- self.install_files = []
- self.garvars = {
- "GARNAME": "testbuild",
- "DESCRIPTION": u"A test package from %s" % self,
- "CATEGORIES": "lib",
- "CONFIGURE_ARGS": "$(DIRPATHS)",
- "SPKG_SOURCEURL": "http://www.opencsw.org/",
- "MASTER_SITES": "",
- "GARVERSION": "0.0.1",
- "CONFIGURE_SCRIPTS": "",
- "BUILD_SCRIPTS": "",
- "TEST_SCRIPTS": "",
- "INSTALL_SCRIPTS": "",
- }
- self.tmpldata = {
- "garvars": self.garvars,
- "garsrc": os.path.join(os.getcwd(), ".."),
- "blurb": None,
- "install_files": self.install_files,
- "tmpdir": self.tmpdir,
- "test_id": "$Id$",
- }
- os.symlink(self.tmpldata["garsrc"], os.path.join(self.tmpdir, "gar"))
-
- def SetGarVariable(self, varname, value):
- self.garvars[varname] = value
-
- def WriteGarFiles(self):
- # print "The tmpdir is", self.tmpdir
- for filedir_name, directory, filename, content in self.install_files:
- file_path = os.path.join(self.filedir, filedir_name)
- print "Writing to %s" % file_path
- fp = open(file_path, "w")
- fp.write(content)
- fp.close()
- searchlist = [self.tmpldata]
- t = Cheetah.Template.Template(MAKEFILE_TMPL, searchlist)
- # For easy debugging, but only until we find a better solution, because it
- # clutters the screen.
- print t
- fp = open(self.makefile_filename, "w")
- fp.write(str(t))
- fp.close()
-
- def AddInstallFile(self, file_path, content):
- """Creates a file in the package, with the given path and content."""
- filedir_name = file_path.replace("/", "-")
- directory, file_name = os.path.split(file_path)
- self.install_files.append((filedir_name, directory,
- file_name, content))
-
- def GetDebugHelp(self):
- return ("Please look into %s.\n"
- "Remember to remove it when you're done debugging."
- % repr(self.tmpdir))
-
- def __del__(self):
- if self.cleanup:
- shutil.rmtree(self.tmpdir)
-
-
-class StaticGarBuild(GarBuild):
-
- def __init__(self, build_dir):
- super(StaticGarBuild, self).__init__()
- self.build_dir = build_dir
- self.tmpdir = build_dir
-
-# vim:set ts=2 sts=2 sw=2 expandtab:
Modified: csw/mgar/gar/v2-dirpackage/tests/run_tests.py
===================================================================
--- csw/mgar/gar/v2-dirpackage/tests/run_tests.py 2010-01-25 16:24:21 UTC (rev 8177)
+++ csw/mgar/gar/v2-dirpackage/tests/run_tests.py 2010-01-25 16:44:20 UTC (rev 8178)
@@ -2,42 +2,11 @@
# $Id$
import unittest
-import sys
-sys.path.append("../lib/python")
-import gartest
-class ExampleEndToEndTest(unittest.TestCase):
- """An example end-to-end test of GAR."""
+# To add more test files, create <name>.py file and add a corresponding line
+# here:
+from example_test import *
- def testPkginfoName(self):
- """Checks that the GARNAME makes it to the NAME in pkginfo."""
- mybuild = gartest.DynamicGarBuild()
- mybuild.SetGarVariable("GARNAME", "foo")
- mybuild.AddInstallFile("/opt/csw/share/foo", "bar!\n")
- mybuild.WriteGarFiles()
- self.assertEquals(0, mybuild.Build())
- pkg = mybuild.GetFirstBuiltPackage()
- pkginfo = pkg.GetParsedPkginfo()
- # By default, the garname should be used to create the catalog name, which
- # in turn ends up in the NAME field in pkginfo.
- self.assertTrue(pkginfo["NAME"].startswith("foo"))
-
-
-class StaticBuildTestExample(unittest.TestCase):
- """An example of a static build.
-
- This uses a static directory where GAR can be called.
- """
-
- def testLooseFiles(self):
- mybuild = gartest.StaticGarBuild("static/example")
- mybuild.Build()
- pkg = mybuild.GetFirstBuiltPackage()
- pkginfo = pkg.GetParsedPkginfo()
- # This part would often use "self.assertEqual(<expected>, <actual>)"
- self.assertTrue(pkginfo["NAME"].startswith("loose"))
-
-
if __name__ == '__main__':
unittest.main()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the devel
mailing list