r182 - branches/rewrite/tests/PackageList

Nat Budin partial-mirror-devel@lists.alioth.debian.org
Thu, 22 Jul 2004 20:45:26 -0600


Author: natbudin-guest
Date: Thu Jul 22 20:45:25 2004
New Revision: 182

Added:
   branches/rewrite/tests/PackageList/test.py
Log:
Added a simple test case for PackageList.


Added: branches/rewrite/tests/PackageList/test.py
==============================================================================
--- (empty file)
+++ branches/rewrite/tests/PackageList/test.py	Thu Jul 22 20:45:25 2004
@@ -0,0 +1,61 @@
+# debpartial-mirror - partial debian mirror package tool
+# (c) 2004 Otavio Salvador <otavio@debian.org>, Nat Budin <natb@brandeis.edu>
+#
+# 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.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+# $Id$
+
+from sys import path, stdout
+path.append("../../src/")
+
+from Package import *
+from PackageList import *
+from logging import *
+import apt_pkg
+
+## Set the debuggin level
+#getLogger().setLevel(DEBUG)
+
+def test(msg, code, packagesfile, should=None):
+    stdout.write("PackageList(%s): %s... " % (packagesfile, msg))
+    try:
+	packagelist = PackageList()
+	parse = apt_pkg.ParseTagFile(open(packagesfile, "r"))
+	while parse.Step() == 1:
+	    packagelist.add(Package(parse.Section))
+	code(PackageList())
+        if not should:
+            print "Works."
+        else:
+            print("Failed. This doesn't found the expected error that should be [%s]."
+                  % should)
+    except NameError, msg:
+        if should == 'NameError':
+            print "Works."
+        else:
+            print("Failed. Got a NameError trying to work with [%s] package."
+                  % (msg.package))
+
+def goodTest(packagelist):
+    pass
+
+def alreadyExistsTest(packagelist):
+    # add the packages over again to generate an Already Exists error
+    parse = apt_pkg.ParseTagFile(open('Packages', "r"))
+    while parse.step() == 1:
+        packagelist.add(Package(parse.Section))
+
+test('Good package test', goodTest, 'Packages')
+test('Package Already Exists', alreadyExistsTest, 'Packages', 'NameError')
+