[csw-devel] SF.net SVN: gar:[13347] csw/mgar/gar/v2/lib/python

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Thu Feb 17 11:34:37 CET 2011


Revision: 13347
          http://gar.svn.sourceforge.net/gar/?rev=13347&view=rev
Author:   wahwah
Date:     2011-02-17 10:34:37 +0000 (Thu, 17 Feb 2011)

Log Message:
-----------
csw-upload-pkg: A more exhaustive unit test

A new, data-driven unit test, which allows to define conditions in a very
concise way, and expect the right output.

It has a problem that it stops on the first failed tests and doesn't do any
other tests.  It could be rewritten using metaclases, but they would make
the code more complicated than it currently is, which is quite complicated
already.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/csw_upload_pkg.py
    csw/mgar/gar/v2/lib/python/csw_upload_pkg_test.py

Modified: csw/mgar/gar/v2/lib/python/csw_upload_pkg.py
===================================================================
--- csw/mgar/gar/v2/lib/python/csw_upload_pkg.py	2011-02-17 10:28:18 UTC (rev 13346)
+++ csw/mgar/gar/v2/lib/python/csw_upload_pkg.py	2011-02-17 10:34:37 UTC (rev 13347)
@@ -168,6 +168,9 @@
     else:
       archs = (srv4_arch,)
     catalogname = parsed_basename["catalogname"]
+    # This part of code quickly became complicated and should probably be
+    # rewritten.  However, it is unit tested, so all the known cases are
+    # handled as intended.
     catalogs = []
     first_cat_osrel_seen = None
     for arch in archs:

Modified: csw/mgar/gar/v2/lib/python/csw_upload_pkg_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/csw_upload_pkg_test.py	2011-02-17 10:28:18 UTC (rev 13346)
+++ csw/mgar/gar/v2/lib/python/csw_upload_pkg_test.py	2011-02-17 10:34:37 UTC (rev 13347)
@@ -36,7 +36,23 @@
     "size": 7617270,
     "version_string": "7.2,REV=2011.01.21",
 }
+GDB_STRUCT_11 = {
+    "arch": "sparc",
+    "basename": "gdb-7.2,REV=2011.01.21-SunOS5.11-sparc-CSW.pkg.gz",
+    "catalogname": "gdb",
+    "filename_arch": "sparc",
+    "maintainer_email": "pfele... at opencsw.org",
+    "maintainer_full_name": None,
+    "md5_sum": "09cccf8097e982dadbd717910963e378",
+    "mtime": "2011-01-24 03:10:05",
+    "osrel": "SunOS5.11",
+    "pkgname": "CSWgdb",
+    "rev": "2011.01.21",
+    "size": 7617270,
+    "version_string": "7.2,REV=2011.01.21",
+}
 
+
 class Srv4UploaderUnitTest(mox.MoxTestBase):
 
   def test_MatchSrv4ToCatalogsSame(self):
@@ -213,5 +229,74 @@
     self.assertEquals(expected, result)
 
 
+class Srv4UploaderDataDrivenUnitTest(mox.MoxTestBase):
+  """A unit test doing an search over multiple combinations.
+
+  It generalizes the unit test above, and is more data-driven.
+
+  It could be rewriten in a way which generates separate test functions for
+  each data row, but for now, we'll just loop over the data set in one test.
+  """
+
+  DATA = (
+      # in_catalog, pkg, specified, expected_insertions
+      ((None, None, None),  9, None, (9, 10, 11)),
+      ((None, None,    9),  9, None, (9, 10, 11)),
+      ((None,    9,    9),  9, None, (9, 10, 11)),
+      ((   9,    9,    9),  9, None, (9, 10, 11)),
+      ((None,    9,   10),  9, None, (9, 10)),
+      ((   9,    9,   10),  9, None, (9, 10)),
+      ((   9,   10,   10),  9, None, (9,)),
+      ((   9,   10,   10),  9,    9, (9,)),
+      ((   9,   10,   10),  9,   10, (10,)),
+      ((   9,    9,   10),  9,   10, (10,)),
+      ((   9,    9,   10),  9,   11, (11,)),
+      ((      None, None), 10, None, (10, 11)),
+      ((      None,   10), 10, None, (10, 11)),
+      ((        10,   10), 10, None, (10, 11)),
+      ((        10,   11), 10, None, (10,)),
+      ((      None,   10), 10, None, (10, 11,)),
+  )
+  BASENAME = "gdb-7.2,REV=2011.01.21-SunOS5.9-sparc-CSW.pkg.gz"
+  MD5_SUM = "deadbeef61b53638d7813407fab4765b"
+
+  def testAllPossibilities(self):
+    for (in_catalog,
+         pkg_osrel, osrel_spec,
+         expected_rels) in self.DATA:
+      self.DataPointTest(in_catalog, pkg_osrel, osrel_spec, expected_rels)
+
+  def DataPointTest(self, in_catalog, pkg_osrel, osrel_spec, expected_rels):
+    pkg_struct_map = {
+        None: None,
+        9: GDB_STRUCT_9,
+        10: GDB_STRUCT_10,
+        11: GDB_STRUCT_11,
+    }
+    rest_client_mock = self.mox.CreateMock(rest.RestClient)
+    self.mox.StubOutWithMock(rest, "RestClient")
+    rest.RestClient().AndReturn(rest_client_mock)
+    for i, os_n in enumerate(in_catalog, 3 - len(in_catalog)):
+      pkg_struct = pkg_struct_map[os_n]
+      rest_client_mock.Srv4ByCatalogAndCatalogname(
+          'unstable',
+          'sparc',
+          u'SunOS5.%s' % (i + 9), 'gdb').AndReturn(pkg_struct)
+    self.mox.ReplayAll()
+    os_release_to_specify = "SunOS5.%s" % osrel_spec if osrel_spec else None
+    su = csw_upload_pkg.Srv4Uploader(None, os_release=os_release_to_specify)
+    result = su._MatchSrv4ToCatalogs(
+        self.BASENAME,
+        "unstable", "sparc", "SunOS5.%s" % pkg_osrel,
+        self.MD5_SUM)
+    expected = []
+    for n in expected_rels:
+      expected.append(("unstable", "sparc", "SunOS5.%s" % n))
+    expected = tuple(expected)
+    self.assertEquals(expected, result)
+    self.mox.ResetAll()
+    self.mox.UnsetStubs()
+
+
 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