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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Tue May 14 00:53:53 CEST 2013


Revision: 21068
          http://gar.svn.sourceforge.net/gar/?rev=21068&view=rev
Author:   wahwah
Date:     2013-05-13 22:53:53 +0000 (Mon, 13 May 2013)
Log Message:
-----------
generate-catalog-file: More unit tests

To smoke-test the basic generation functions.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/generate_catalog_file.py
    csw/mgar/gar/v2/lib/python/generate_catalog_file_test.py

Modified: csw/mgar/gar/v2/lib/python/generate_catalog_file.py
===================================================================
--- csw/mgar/gar/v2/lib/python/generate_catalog_file.py	2013-05-13 20:29:51 UTC (rev 21067)
+++ csw/mgar/gar/v2/lib/python/generate_catalog_file.py	2013-05-13 22:53:53 UTC (rev 21068)
@@ -80,9 +80,9 @@
     out_file = os.path.join(out_dir, CATALOG_FN)
     if os.path.exists(out_file):
       raise Error("File %s already exists." % out_file)
-    lines = self._GenerateCatalogLines()
+    lines = self._GenerateCatalogAsLines()
     with open(out_file, "w") as fd:
-      fd.write("\n".join(lines))
+      fd.write("\n".join(lines).encode('utf-8'))
 
   def _GenerateCatalogAsLines(self):
     """Return the complete catalog as a list of lines."""
@@ -104,7 +104,7 @@
         catalog_data = self.pkgcache.GetDeps(pkg_data["md5_sum"])
         lines.append(catalog_data['pkginfo_name'])
     with open(out_file, "w") as fd:
-      fd.write("\n".join(lines))
+      fd.write("\n".join(lines).encode('utf-8'))
 
 
 def main():

Modified: csw/mgar/gar/v2/lib/python/generate_catalog_file_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/generate_catalog_file_test.py	2013-05-13 20:29:51 UTC (rev 21067)
+++ csw/mgar/gar/v2/lib/python/generate_catalog_file_test.py	2013-05-13 22:53:53 UTC (rev 21068)
@@ -4,6 +4,8 @@
 import mox
 import generate_catalog_file
 import rest
+import __builtin__
+import io
 
 PKG_DATA_1 = {
         "basename": "389_admin-1.1.29,REV=2012.05.02-SunOS5.10-sparc-CSW.pkg.gz",
@@ -69,6 +71,38 @@
       EXPECTED_LINE,
     ], cfg._GenerateCatalogAsLines())
 
+  def testGenerateCatalog(self):
+    mock_pkgcache = self.mox.CreateMock(rest.CachedPkgstats)
+    mock_rest = self.mox.CreateMock(rest.RestClient)
+    self.mox.StubOutWithMock(__builtin__, 'open')
+    cfg = generate_catalog_file.CatalogFileGenerator("dublin",
+                                                     "sparc",
+                                                     "SunOS5.10",
+                                                     mock_pkgcache, mock_rest)
+    mock_rest.GetCatalog('dublin', 'sparc', 'SunOS5.10').AndReturn([PKG_DATA_1])
+    md5_sum = 'fdb7912713da36afcbbe52266c15cb3f'
+    mock_rest.GetCatalogData(md5_sum).AndReturn(FAKE_CATALOG_DATA)
+    fake_file = io.BytesIO();
+    open('fake-dir/catalog', 'w').AndReturn(fake_file)
+    self.mox.ReplayAll()
+    cfg.GenerateCatalog('fake-dir')
 
+  def testGenerateDescriptions(self):
+    mock_pkgcache = self.mox.CreateMock(rest.CachedPkgstats)
+    mock_rest = self.mox.CreateMock(rest.RestClient)
+    self.mox.StubOutWithMock(__builtin__, 'open')
+    cfg = generate_catalog_file.CatalogFileGenerator("dublin",
+                                                     "sparc",
+                                                     "SunOS5.10",
+                                                     mock_pkgcache, mock_rest)
+    md5_sum = 'fdb7912713da36afcbbe52266c15cb3f'
+    mock_pkgcache.GetDeps(md5_sum).AndReturn(FAKE_CATALOG_DATA)
+    mock_rest.GetCatalog('dublin', 'sparc', 'SunOS5.10').AndReturn([PKG_DATA_1])
+    fake_file = io.BytesIO();
+    open('fake-dir/descriptions', 'w').AndReturn(fake_file)
+    self.mox.ReplayAll()
+    cfg.GenerateDescriptions('fake-dir')
+
+
 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