RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Per Øyvind Karlsen Root: /v/rpm/cvs Email: [email protected] Module: rpm Date: 06-Aug-2009 02:49:40 Branch: HEAD Handle: 2009080600493801 Added files: rpm/python/test test_rpm.py Modified files: rpm CHANGES Makefile.am rpm/python Makefile.am Log: python: start on implementing proper regression tests. Summary: Revision Changes Path 1.3083 +1 -0 rpm/CHANGES 2.239 +1 -1 rpm/Makefile.am 1.86 +5 -0 rpm/python/Makefile.am 1.2 +78 -0 rpm/python/test/test_rpm.py ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/CHANGES ============================================================================ $ cvs diff -u -r1.3082 -r1.3083 CHANGES --- rpm/CHANGES 24 Jul 2009 20:56:46 -0000 1.3082 +++ rpm/CHANGES 6 Aug 2009 00:49:38 -0000 1.3083 @@ -1,5 +1,6 @@ 5.2b1 -> 5.3a1 + - proyvind: python: start on implementing proper regression tests. - proyvind: js: fix internal build on Linux. - proyvind: filetriggers: fix missing file suffix for scripts. (from unity linux). - proyvind: rpm4compat: add wrappers for renamed rpmdb*->rpmmi* functions. @@ . patch -p0 <<'@@ .' Index: rpm/Makefile.am ============================================================================ $ cvs diff -u -r2.238 -r2.239 Makefile.am --- rpm/Makefile.am 10 May 2009 14:05:01 -0000 2.238 +++ rpm/Makefile.am 6 Aug 2009 00:49:39 -0000 2.239 @@ -31,7 +31,7 @@ rpm.magic rpmqv.c \ python/mpw/Makefile.am python/mpw/test/* python/test/resources/* python/test/dscmp \ python/test/psTest.py python/test/testhdr python/test/testit python/test/testmi \ - python/test/testrollback.py python/test/dsMerge.py \ + python/test/testrollback.py python/test/dsMerge.py python/test/test_rpm.py \ python/rpm/__init__.py python/[a-z]* python/Makefile.in python/Makefile.am \ tests/cudf-test-1-0.src.rpm \ tests/devtool-sanity-1.0-1.src.rpm \ @@ . patch -p0 <<'@@ .' Index: rpm/python/Makefile.am ============================================================================ $ cvs diff -u -r1.85 -r1.86 Makefile.am --- rpm/python/Makefile.am 30 Jun 2009 16:44:57 -0000 1.85 +++ rpm/python/Makefile.am 6 Aug 2009 00:49:39 -0000 1.86 @@ -59,3 +59,8 @@ .PHONY: lint lint: $(LINT) $(DEFS) $(INCLUDES) $(splint_srcs) + +# FIXME: using .libs/ is not really correct, but whatever +check-local: + @export PYTHONPATH=$(PYTHONPATH):$(shell pwd):$(shell pwd)/.libs/ && \ + cd test && python test_rpm.py @@ . patch -p0 <<'@@ .' Index: rpm/python/test/test_rpm.py ============================================================================ $ cvs diff -u -r0 -r1.2 test_rpm.py --- /dev/null 2009-08-06 02:45:29 +0200 +++ test_rpm.py 2009-08-06 02:49:39 +0200 @@ -0,0 +1,78 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (c) 2009 Per Ãyvind Karlsen <[email protected]> +# +import sys, random, rpm, unittest, os, subprocess +from test.test_support import rmtree + +DICT = {} + +class Test_loadHeader(unittest.TestCase): + def setUp(self): + self.topdir = "%s/tmp" % os.getcwdu() + self.package = "%s/RPMS/noarch/simple-1.0-1-foo2009.1.noarch.rpm" % self.topdir + + build = subprocess.Popen(["--define", "_topdir %s" % self.topdir, "-bb", "resources/simple.spec"], + executable="rpm", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True) + self.assertFalse(build.wait()) + self.assertTrue(os.path.isfile(self.package)) + + def test_loadHeader(self): + ts = rpm.TransactionSet() + file = open(self.package) + DICT['hdr'] = h = ts.hdrFromFdno(file.fileno()) + file.close() + self.assertEqual(h['name'], "simple") + self.assertEqual(h['epoch'], 1) + self.assertEqual(h['version'], "1.0") + self.assertEqual(h['release'], "1") + self.assertEqual(h['disttag'], "foo") + self.assertEqual(h['distepoch'], "2009.1") + + def tearDown(self): + rmtree(self.topdir) + +class Test_labelCompare(unittest.TestCase): + + def setUp(self): + self.labels = (tuple(DICT['hdr'].sprintf("%{epoch} %{version} %{release} %{distepoch}").split()), ("1", "2.1", "2", "2010.1")) + + def test_evr(self): + le = self.labels[0][0:3] + ge = self.labels[1][0:3] + self.assertEqual(rpm.labelCompare(le, ge), -1) + self.assertEqual(rpm.labelCompare(ge, le), 1) + self.assertEqual(rpm.labelCompare(ge, ge), 0) + self.assertEqual(rpm.labelCompare(ge, ge), 0) + + def test_evrd(self): + le = self.labels[0] + ge = self.labels[1] + self.assertEqual(rpm.labelCompare(le, ge), -1) + self.assertEqual(rpm.labelCompare(ge, le), 1) + self.assertEqual(rpm.labelCompare(ge, ge), 0) + self.assertEqual(rpm.labelCompare(ge, ge), 0) + + def test_None(self): + no = (None, None, None, None) + yes = self.labels[0] + # first without distepoch + self.assertEqual(rpm.labelCompare(yes[0:3], no[0:3]), 1) + self.assertEqual(rpm.labelCompare(no[0:3], yes[0:3]), -1) + self.assertEqual(rpm.labelCompare(no[0:3], no[0:3]), 0) + # then again with distepoch + self.assertEqual(rpm.labelCompare(yes, no), 1) + self.assertEqual(rpm.labelCompare(no, yes), -1) + self.assertEqual(rpm.labelCompare(no, no), 0) + +def test_main(): + from test import test_support + test_support.run_unittest( + Test_loadHeader, + Test_labelCompare) + test_support.reap_children() + + +if __name__ == "__main__": + test_main() @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository [email protected]
