[csw-devel] SF.net SVN: gar:[8134] csw/mgar/pkg/tests

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Sun Jan 24 08:18:53 CET 2010


Revision: 8134
          http://gar.svn.sourceforge.net/gar/?rev=8134&view=rev
Author:   wahwah
Date:     2010-01-24 07:18:53 +0000 (Sun, 24 Jan 2010)

Log Message:
-----------
mGAR v2: tests, separated the library and the executable, better API for variables.

Modified Paths:
--------------
    csw/mgar/pkg/tests/gartest.py

Added Paths:
-----------
    csw/mgar/pkg/tests/run_tests.py

Modified: csw/mgar/pkg/tests/gartest.py
===================================================================
--- csw/mgar/pkg/tests/gartest.py	2010-01-24 01:31:18 UTC (rev 8133)
+++ csw/mgar/pkg/tests/gartest.py	2010-01-24 07:18:53 UTC (rev 8134)
@@ -12,36 +12,14 @@
 """A module used to do end-to-end testing of GAR."""
 
 MAKEFILE_TMPL = """# GAR Makefile generated by $test_id
-#
-GARNAME = $garname
-GARVERSION = $garversion
-CATEGORIES = $profile
-DESCRIPTION = $description
+#for varname in $garvars
+$varname = $garvars[$varname]
+#end for
 #if $blurb
 define BLURB
   blurb
 endef
 #end if
-#if $upstream_url
-SPKG_SOURCEURL = $upstream_url
-#end if
-#if $master_sites
-MASTER_SITES = $master_sites
-#end if
-## PATCHFILES =
-## DISTFILES  = $(GARNAME)-$(GARVERSION).tar.gz
-## UFILES_REGEX = $(GARNAME)-(\d+(?:\.\d+)*).tar.gz
-## CATALOGNAME =
-## ARCHALL = 0
-## PACKAGES =
-CONFIGURE_SCRIPTS =
-BUILD_SCRIPTS =
-INSTALL_SCRIPTS =
-TEST_SCRIPTS =
-#if $configure_args
-CONFIGURE_ARGS = $configure_args
-#end if
-## BUILD64 =
 include gar/category.mk
 #if $install_files
 post-install-modulated:
@@ -64,36 +42,47 @@
   Can create a GAR build and execute it.
   """
   def __init__(self):
+    self.packages = None
     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.built = False
+    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 = {
-        "garname": "testbuild",
+        "garvars": self.garvars,
         "garsrc": "/home/maciej/src/opencsw/gar/v2-dirpackage",
         "blurb": None,
-        "description": u"A test package from %s" % self,
-        "profile": "lib",
-        "configure_args": "$(DIRPATHS)",
-        "upstream_url": "http://www.opencsw.org/",
-        "master_sites": None,
         "install_files": self.install_files,
-        "garversion": "0.0.1",
         "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()
+      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)
     print t
@@ -103,7 +92,7 @@
 
   def Build(self):
     if self.built:
-    	return 0
+      return 0
     args = ["gmake", "dirpackage"]
     gar_proc = subprocess.Popen(args, cwd=self.tmpdir,
                                 stdout=subprocess.PIPE,
@@ -112,26 +101,38 @@
     ret = gar_proc.wait()
     if ret:
       print "ERROR: GAR run has failed."
+      print stdout
+      print stderr
       self.built = False
     else:
-    	self.built = True
+      self.built = True
     return ret
 
   def GetBuiltPackages(self):
     if not self.built:
-    	raise Error("The packages have not been built yet.")
+      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")))
-    packages = [opencsw.DirectoryFormatPackage(os.path.join(DIR_PKG_OUT_DIR, z)) for x, y, z in pkglist]
-    return packages
+      # 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]
+
   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,
@@ -140,29 +141,4 @@
   def __del__(self):
     shutil.rmtree(self.tmpdir)
 
-
-class FooUnitTest(unittest.TestCase):
-  """This is the docstring for the FooUnitTest."""
-
-  def testSomething(self):
-    """This is a doc string for the test method.
-    
-    You can write more text here.
-    """
-    mybuild = GarBuild()
-    mybuild.tmpldata["garname"] = "blah"
-    mybuild.AddInstallFile("/opt/csw/share/foo", "bar!\n")
-    mybuild.WriteGarFiles()
-    self.assertEquals(0, mybuild.Build())
-    packages = mybuild.GetBuiltPackages()
-    for pkg in packages:
-    	print pkg
-    	print pkg.GetParsedPkginfo()
-    # package = mybuild.GetFirstDirFormatPackage()
-    # self.assertEqual("blah", package.catalogname)
-
-
-if __name__ == '__main__':
-  unittest.main()
-
 # vim:set ts=2 sts=2 sw=2 expandtab:

Added: csw/mgar/pkg/tests/run_tests.py
===================================================================
--- csw/mgar/pkg/tests/run_tests.py	                        (rev 0)
+++ csw/mgar/pkg/tests/run_tests.py	2010-01-24 07:18:53 UTC (rev 8134)
@@ -0,0 +1,26 @@
+# $Id$
+
+import unittest
+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.GarBuild()
+    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"))
+
+
+if __name__ == '__main__':
+  unittest.main()
+
+# vim:set ts=2 sts=2 sw=2 expandtab:


Property changes on: csw/mgar/pkg/tests/run_tests.py
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:keywords
   + Id


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