r518 - in tags: . v7-V1-2R3/v7
by gnichols@fedoraproject.org
Author: gnichols
Date: 2010-05-28 14:30:09 +0000 (Fri, 28 May 2010)
New Revision: 518
Added:
tags/v7-V1-2R3/
tags/v7-V1-2R3/v7/version.py
Log:
tag version
Copied: tags/v7-V1-2R3 (from rev 517, trunk)
Copied: tags/v7-V1-2R3/v7/version.py (from rev 335, trunk/v7/version.py)
===================================================================
--- tags/v7-V1-2R3/v7/version.py (rev 0)
+++ tags/v7-V1-2R3/v7/version.py 2010-05-28 14:30:09 UTC (rev 518)
@@ -0,0 +1,5 @@
+
+# v7/version.py is automatically-generated - DO NOT EDIT
+version = '1.2'
+release = '3'
+rhel_version = '5'
13 years, 11 months
r517 - trunk/tests/info
by gnichols@fedoraproject.org
Author: gnichols
Date: 2010-05-28 14:27:44 +0000 (Fri, 28 May 2010)
New Revision: 517
Modified:
trunk/tests/info/info.py
Log:
591357 - RHEL6 info test: no --no-progressbar option for sosreport
Modified: trunk/tests/info/info.py
===================================================================
--- trunk/tests/info/info.py 2010-05-26 14:43:06 UTC (rev 516)
+++ trunk/tests/info/info.py 2010-05-28 14:27:44 UTC (rev 517)
@@ -313,17 +313,32 @@
def generateSystemReport(self):
- outputDirectory = os.getcwd()
- reportCommand = "sosreport -n selinux"
- if "Red Hat" in self.redHatRelease.getProduct():
- if self.redHatRelease.getVersion() == 4:
- reportCommand = "sysreport"
- elif self.redHatRelease.getVersion() == 5:
- reportCommand = reportCommand + " --no-progressbar"
-
- pipe = os.popen("echo -e '\n\n' | %s -k rpm.rpmva=off 2>&1" % reportCommand)
- result = False
- while True:
+
+ result = False
+ # for RHEL 4, use sysreport
+ if "Red Hat" in self.redHatRelease.getProduct() and self.redHatRelease.getVersion() == 4:
+ result = self.__processSystemReport("sysreport")
+ # otherwise, uses sosreport
+ else:
+ # try --no-progressbar for some RHEL5's
+ result = self.__processSystemReport("sosreport -n selinux --no-progressbar")
+ # if that fails, leave off --no-progressbar
+ if not result:
+ result = self.__processSystemReport("sosreport -n selinux")
+
+
+ dmidecode = "/usr/sbin/dmidecode"
+ if os.path.exists(dmidecode):
+ if not os.system(dmidecode) is 0:
+ print "Note: %s returned an error." % (dmidecode)
+
+
+ return result
+
+ def __processSystemReport(self, reportCommand):
+ pipe = os.popen("echo -e '\n\n' | %s -k rpm.rpmva=off 2>&1" % reportCommand)
+ result = False
+ while True:
line = pipe.readline()
if line:
print line.strip()
@@ -339,7 +354,8 @@
print tarFile
sys.stdout.flush()
- if tarFile:
+ if tarFile:
+ outputDirectory = os.getcwd()
shutil.copy(tarFile, outputDirectory)
print "Copied %s %s to %s" % (reportCommand, tarFile, outputDirectory)
sys.stdout.flush()
@@ -347,15 +363,8 @@
break
else:
break
- pipe.close()
-
- dmidecode = "/usr/sbin/dmidecode"
- if os.path.exists(dmidecode):
- if not os.system(dmidecode) is 0:
- print "Note: %s returned an error." % (dmidecode)
-
-
- return result
+ pipe.close()
+ return result
def run(self):
13 years, 11 months
r516 - trunk
by gnichols@fedoraproject.org
Author: gnichols
Date: 2010-05-26 14:43:06 +0000 (Wed, 26 May 2010)
New Revision: 516
Modified:
trunk/v7.spec.in
Log:
changelog
Modified: trunk/v7.spec.in
===================================================================
--- trunk/v7.spec.in 2010-05-26 14:40:31 UTC (rev 515)
+++ trunk/v7.spec.in 2010-05-26 14:43:06 UTC (rev 516)
@@ -68,11 +68,17 @@
/usr/share/man/man8/v7.8.gz
%changelog
+* Wed May 26 2010 Greg Nichols <gnichols(a)redhat.com>
+
+V7 1.2 R3
+
+ 591357 - RHEL6 info test: no --no-progressbar option for sosreport
+
* Tue May 17 2010 Greg Nichols <gnichols(a)redhat.com>
V7 1.2 R2
576497 - fv_* is not listed in v7 print on rhel55-server-x86_64-xen system
-
+
* Tue Apr 27 2010 Greg Nichols <gnichols(a)redhat.com>
V7 1.2 R1
13 years, 11 months
r515 - trunk/tests/info
by gnichols@fedoraproject.org
Author: gnichols
Date: 2010-05-26 14:40:31 +0000 (Wed, 26 May 2010)
New Revision: 515
Modified:
trunk/tests/info/info.py
Log:
591357 - RHEL6 info test: no --no-progressbar option for sosreport
Modified: trunk/tests/info/info.py
===================================================================
--- trunk/tests/info/info.py 2010-05-26 14:38:33 UTC (rev 514)
+++ trunk/tests/info/info.py 2010-05-26 14:40:31 UTC (rev 515)
@@ -314,9 +314,13 @@
def generateSystemReport(self):
outputDirectory = os.getcwd()
- reportCommand = "sosreport -n selinux --no-progressbar"
- if "Red Hat" in self.redHatRelease.getProduct() and self.redHatRelease.getVersion() == 4:
- reportCommand = "sysreport"
+ reportCommand = "sosreport -n selinux"
+ if "Red Hat" in self.redHatRelease.getProduct():
+ if self.redHatRelease.getVersion() == 4:
+ reportCommand = "sysreport"
+ elif self.redHatRelease.getVersion() == 5:
+ reportCommand = reportCommand + " --no-progressbar"
+
pipe = os.popen("echo -e '\n\n' | %s -k rpm.rpmva=off 2>&1" % reportCommand)
result = False
while True:
13 years, 11 months
r514 - trunk
by gnichols@fedoraproject.org
Author: gnichols
Date: 2010-05-26 14:38:33 +0000 (Wed, 26 May 2010)
New Revision: 514
Modified:
trunk/Makefile
Log:
R3
Modified: trunk/Makefile
===================================================================
--- trunk/Makefile 2010-05-20 14:10:42 UTC (rev 513)
+++ trunk/Makefile 2010-05-26 14:38:33 UTC (rev 514)
@@ -14,7 +14,7 @@
# Author: Greg Nichols
V7_VERSION := 1.2
-V7_RELEASE := 2
+V7_RELEASE := 3
V7_VERSION_RELEASE := $(V7_VERSION)-$(V7_RELEASE)
V7_VERSION_PY := v7/version.py
V7_SVN_MODULE := svn+ssh://svn.fedorahosted.org/svn/v7
13 years, 11 months
r513 - in trunk: . tools tools/bin
by gnichols@fedoraproject.org
Author: gnichols
Date: 2010-05-20 14:10:42 +0000 (Thu, 20 May 2010)
New Revision: 513
Added:
trunk/tools/unittest.py
Removed:
trunk/unittests/
Modified:
trunk/tools/bin/v7-mount-data-image
trunk/tools/rhts-regression-test.xml
trunk/tools/rhtsvirtualreserve-ia64.xml
trunk/tools/rhtsvirtualreserve-x86_64.xml
Log:
moving unit test code to tools
Modified: trunk/tools/bin/v7-mount-data-image
===================================================================
--- trunk/tools/bin/v7-mount-data-image 2010-05-20 12:31:09 UTC (rev 512)
+++ trunk/tools/bin/v7-mount-data-image 2010-05-20 14:10:42 UTC (rev 513)
@@ -48,6 +48,7 @@
(options,args) = parser.parse_args()
fvTest = FvTest("fv_generic")
+fvTest.configureHypervisor()
if options.unmount:
if options.loopBackDevice:
fvTest.loopBackDevice = options.loopBackDevice
Modified: trunk/tools/rhts-regression-test.xml
===================================================================
--- trunk/tools/rhts-regression-test.xml 2010-05-20 12:31:09 UTC (rev 512)
+++ trunk/tools/rhts-regression-test.xml 2010-05-20 14:10:42 UTC (rev 513)
@@ -5,6 +5,7 @@
<recipeSet>
<recipe testrepo='development'>
+
<distroRequires>ARCH = i386</distroRequires>
<distroRequires>FAMILY = RedHatEnterpriseLinuxServer5</distroRequires>
<distroRequires>NAME = RHEL5-Server-U3</distroRequires>
@@ -22,6 +23,7 @@
<addrepo>http://qafiler.bos.redhat.com/testkits/V7/RHEL4/</addrepo>
<test role='STANDALONE' name='/distribution/v7/single'/>
</recipe>
+
<recipe testrepo='development'>
<distroRequires>ARCH = x86_64</distroRequires>
<distroRequires>FAMILY = RedHatEnterpriseLinuxServer5</distroRequires>
Modified: trunk/tools/rhtsvirtualreserve-ia64.xml
===================================================================
--- trunk/tools/rhtsvirtualreserve-ia64.xml 2010-05-20 12:31:09 UTC (rev 512)
+++ trunk/tools/rhtsvirtualreserve-ia64.xml 2010-05-20 14:10:42 UTC (rev 513)
@@ -12,6 +12,7 @@
<hostRequires>HVM = 1</hostRequires>
<hostRequires>MEMORY >= 2048</hostRequires>
<addrepo>http://porkchop.redhat.com/released/RHEL-5-Server-Supplementary/U3/ia64/o...</addrepo>
+ <addrepo>http://qafiler.bos.redhat.com/testkits/V7/RHEL5/</addrepo>
<test role='STANDALONE' name='/distribution/install'/>
<test role='STANDALONE' name='/distribution/pkginstall'>
<params>
@@ -24,37 +25,12 @@
</params>
</test>
<test role='STANDALONE' name='/distribution/virt/start_stop'/>
- <guestrecipe testrepo='development' guestname='ia64_pv_guest' guestargs=' --nonsparse --paravirt --file /var/lib/xen/images/ia64_pv_guest.img -s 10 ' whiteboard='domU:paravirt on partition '>
- <distroRequires>ARCH = ia64</distroRequires>
- <distroRequires>FAMILY = RedHatEnterpriseLinuxServer5</distroRequires>
- <distroRequires>NAME = RHEL5-Server-U3</distroRequires>
- <distroRequires>RELEASED = 1</distroRequires>
- <addrepo>http://qafiler.bos.redhat.com/testkits/HTS/RHEL5/</addrepo>
- <installPackage>kernel-xen</installPackage>
- <test role='STANDALONE' name='/distribution/install'/>
- <test role='STANDALONE' name='/distribution/virt/guestutils'/>
- <test role='STANDALONE' name='/distribution/reservesys'>
+ <test role='STANDALONE' name='/distribution/reservesys'>
<params>
<param name='RESERVEBY' value='gnichols(a)redhat.com'/>
<param name='RESERVETIME' value='86400'/>
</params>
</test>
- </guestrecipe>
- <guestrecipe testrepo='development' guestname='ia64_hvm_guest' guestargs=' --nonsparse --hvm --file /var/lib/xen/images/ia64_hvm_guest.img -s 10 ' whiteboard='domU:hvm on partition'>
- <distroRequires>ARCH = ia64</distroRequires>
- <distroRequires>FAMILY = RedHatEnterpriseLinuxServer5</distroRequires>
- <distroRequires>NAME = RHEL5-Server-U3</distroRequires>
- <distroRequires>RELEASED = 1</distroRequires>
- <addrepo>http://qafiler.bos.redhat.com/testkits/HTS/RHEL5/</addrepo>
- <test role='STANDALONE' name='/distribution/install'/>
- <test role='STANDALONE' name='/distribution/virt/guestutils'/>
- <test role='STANDALONE' name='/distribution/reservesys'>
- <params>
- <param name='RESERVEBY' value='gnichols(a)redhat.com'/>
- <param name='RESERVETIME' value='86400'/>
- </params>
- </test>
- </guestrecipe>
</recipe>
</recipeSet>
</job>
Modified: trunk/tools/rhtsvirtualreserve-x86_64.xml
===================================================================
--- trunk/tools/rhtsvirtualreserve-x86_64.xml 2010-05-20 12:31:09 UTC (rev 512)
+++ trunk/tools/rhtsvirtualreserve-x86_64.xml 2010-05-20 14:10:42 UTC (rev 513)
@@ -1,24 +1,19 @@
<job>
<workflow>Virtual Workflow</workflow>
<submitter>gnichols(a)redhat.com</submitter>
- <whiteboard>2 Xen nonsparse block device rhel5.3 x86_64, pv/hvm guests on rhel5.3 x86_64 dom0 INSTALL ONLY </whiteboard>
+ <whiteboard>2 Xen nonsparse block device rhel5.5 x86_64 </whiteboard>
<recipeSet>
<recipe testrepo='development'>
<distroRequires>ARCH = x86_64</distroRequires>
<distroRequires>FAMILY = RedHatEnterpriseLinuxServer5</distroRequires>
- <distroRequires>NAME = RHEL5-Server-U3</distroRequires>
- <distroRequires>RELEASED = 1</distroRequires>
+ <distroRequires>NAME = RHEL5-Server-U5</distroRequires>
<hostRequires>ARCH = x86_64</hostRequires>
<hostRequires>HVM = 1</hostRequires>
<hostRequires>MEMORY >= 2048</hostRequires>
- <addrepo>http://porkchop.redhat.com/released/RHEL-5-Server-Supplementary/U3/x86_64...</addrepo>
+ <installPackage>-kernel-xen</installPackage>
+ <addrepo>http://porkchop.redhat.com/released/RHEL-5-Server-Supplementary/U4/x86_64...</addrepo>
<addrepo>http://qafiler.bos.redhat.com/testkits/V7/RHEL5/</addrepo>
<test role='STANDALONE' name='/distribution/install'/>
- <test role='STANDALONE' name='/distribution/pkginstall'>
- <params>
- <param name='PKGARGNAME' value='xen-x86_64-guest-firmware'/>
- </params>
- </test>
<test role='STANDALONE' name='/distribution/virt/install'>
<params>
<param name='KILLTIMEOVERRIDE' value='59280'/>
Copied: trunk/tools/unittest.py (from rev 512, trunk/unittests/unittest.py)
===================================================================
--- trunk/tools/unittest.py (rev 0)
+++ trunk/tools/unittest.py 2010-05-20 14:10:42 UTC (rev 513)
@@ -0,0 +1,129 @@
+#!/usr/bin/env python
+# Copyright (c) 2010 Red Hat, Inc. All rights reserved. This copyrighted material
+# is made available to anyone wishing to use, modify, copy, or
+# redistribute it subject to the terms and conditions of the GNU General
+# Public License v.2.
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Author: David Sommerseth <davids(a)redhat.com>
+#
+
+import os, sys
+
+class UnitTest(object):
+ "Unified unit test class"
+
+ def __init__(self, srcrootdir):
+ "UnitTest constructor. srcrootdir argument must point at the source root directory"
+ self.imported_mods = []
+ self.mod_impcount = 0
+ self.mod_impfail = 0
+ self.mod_testpass = 0
+ self.mod_testfail = 0
+ self.mod_testmiss = 0
+ self.rootdir = srcrootdir
+ sys.path.insert(0, self.rootdir)
+
+
+ def LoadModules(self, modules):
+ """Loads all the defined modules. The modules argument takes a tuple list
+ consisting of ('subdir','module name')"""
+
+ for (directory, mod) in modules:
+ # Check if the directory is in the "include" path
+ try:
+ sys.path.index('%s/%s' % (self.rootdir,directory))
+ except ValueError:
+ # Not found, insert it
+ sys.path.insert(0, '%s/%s' % (self.rootdir, directory))
+
+ try:
+ impmod = __import__(mod)
+ print "** Imported %s/%s" % (directory, mod)
+ self.imported_mods.append({'name': '%s/%s' %(directory, mod),
+ 'module': impmod})
+ self.mod_impcount += 1
+ except ImportError, e:
+ print "!! ** ERROR ** Failed to import %s/%s (Exception: %s)" % (directory, mod, str(e))
+ self.mod_impfail += 1
+
+ return True
+
+
+ def RunTests(self):
+ "Runs the unit_test() function in all successfully imported modules"
+
+ for m in self.imported_mods:
+ try:
+ # Check if the unit_test() function exists and is callable before trying
+ # to run the unit test
+ if callable(m['module'].unit_test):
+ print
+ print 78 * '-'
+ print "** Running unit test for: %s" % m['name']
+ print 78 * '-'
+ res = m['module'].unit_test()
+ if res == 0:
+ print "** Result of %s: PASS" % m['name']
+ self.mod_testpass += 1
+ else:
+ print "** Result of %s: FAILED (return code: %s)" % (m['name'], str(res))
+ self.mod_testfail += 1
+ print 78 * '='
+ else:
+ self.mod_testmiss += 1
+ print "!!! ** ERROR ** Could not run %s::unit_test()" % m['name']
+ except AttributeError:
+ self.mod_testmiss += 1
+ print "!!! ** ERROR ** No %s::unit_test() method found" % m['name']
+
+
+ def PrintTestSummary(self):
+ "Prints a result summary of all the tests"
+ print
+ print " --------------------"
+ print " ** TEST SUMMARY ** "
+ print " --------------------"
+ print
+ print " - Modules:"
+ print " Declared for test: %i" % (self.mod_impcount + self.mod_impfail)
+ print " Successfully imported: %i" % self.mod_impcount
+ print " Failed import: %i" % self.mod_impfail
+ print
+ print " - Tests:"
+ print " Tests scheduled: %i" % (self.mod_testpass + self.mod_testfail + self.mod_testmiss)
+ print " Sucessfully tests: %i" % self.mod_testpass
+ print " Failed tests: %i" % self.mod_testfail
+ print " Missing unit_test() %i" % self.mod_testmiss
+ print
+
+
+if __name__ == '__main__':
+
+ # Retrieve the root directory if the source dir
+ # - use the first occurence of the 'v7' subdir as the root dirq
+ srcrootdir_ar = os.getcwd().split('/')
+ rootdir = '/'.join(srcrootdir_ar[0:srcrootdir_ar.index('v7')+1])
+ print "** Source root dir: %s" % rootdir
+
+ # Prepare the unit tester
+ tests = UnitTest(rootdir)
+
+ # Load defined modules ('subdir','import name')
+ tests.LoadModules((('v7','redhatrelease'),
+ ('v7','command'),
+ ('v7','hal'),
+ ('v7','hash'),
+ ('tests/info', 'info')
+ ))
+ # Run all tests
+ tests.RunTests()
+ tests.PrintTestSummary()
+
13 years, 11 months
r512 - in trunk: unittests v7
by David Sommerseth
Author: dsommers
Date: 2010-05-20 12:31:09 +0000 (Thu, 20 May 2010)
New Revision: 512
Modified:
trunk/unittests/unittest.py
trunk/v7/hash.py
Log:
Added unit-test for v7/hash.py
Also rearranged the code a little bit. Tested on Fedora 13 and
RHEL4.6(!)
Signed-off-by: David Sommerseth <davids(a)redhat.com>
Modified: trunk/unittests/unittest.py
===================================================================
--- trunk/unittests/unittest.py 2010-05-20 09:45:54 UTC (rev 511)
+++ trunk/unittests/unittest.py 2010-05-20 12:31:09 UTC (rev 512)
@@ -120,6 +120,7 @@
tests.LoadModules((('v7','redhatrelease'),
('v7','command'),
('v7','hal'),
+ ('v7','hash'),
('tests/info', 'info')
))
# Run all tests
Modified: trunk/v7/hash.py
===================================================================
--- trunk/v7/hash.py 2010-05-20 09:45:54 UTC (rev 511)
+++ trunk/v7/hash.py 2010-05-20 12:31:09 UTC (rev 512)
@@ -16,28 +16,35 @@
# The Report object packages and/or presents test results in text, rpm, or html form.
#
+import sys
+
hashModule = None
try:
- import hashlib
- hashModule = hashlib
+ hashModule = __import__('hashlib')
except:
- pass
-
-if not hashModule:
try:
- import md5
- hashModule = md5
+ hashModule = __import__('md5')
except:
print "Error: could not find hash library"
-if __name__ == "__main__":
+
+def unit_test():
print hashModule
content = "Boo"
m=hashModule.md5()
m.update(content)
- print content
-
+ digest = m.hexdigest()
+ print "Digest test of '%s': %s ..." % (content, digest),
+ if digest == '2e4d1b829d740c57ff602b7d3d8658a5':
+ print "PASS"
+ return 0
+ else:
+ print "FAILED"
+ return 1
+
+if __name__ == "__main__":
+ sys.exit(unit_test())
13 years, 11 months
r511 - trunk/v7
by David Sommerseth
Author: dsommers
Date: 2010-05-20 09:45:54 +0000 (Thu, 20 May 2010)
New Revision: 511
Modified:
trunk/v7/hal.py
Log:
Fixed an error in v7.hal::dumpall(), using dump() instead of dumpDevice() Signed-off-by: David Sommerseth <davids(a)redhat.com>
Modified: trunk/v7/hal.py
===================================================================
--- trunk/v7/hal.py 2010-05-20 09:45:46 UTC (rev 510)
+++ trunk/v7/hal.py 2010-05-20 09:45:54 UTC (rev 511)
@@ -65,7 +65,7 @@
return rv
def dumpall(self):
"Dump device properties for all devices (like lshal)"
- return "\n".join([self.dump(udi) for udi in self.__GetAllDevices()])
+ return "\n".join([self.dumpDevice(udi) for udi in self.__GetAllDevices()])
def dump(self): return self.dumpall()
def getUSBBusAndPort(self, device):
13 years, 11 months
r510 - in trunk: tests/info v7
by David Sommerseth
Author: dsommers
Date: 2010-05-20 09:45:46 +0000 (Thu, 20 May 2010)
New Revision: 510
Modified:
trunk/tests/info/info.py
trunk/v7/command.py
trunk/v7/hal.py
trunk/v7/redhatrelease.py
Log:
Added unit-test features to a few modules
Signed-off-by: David Sommerseth <davids(a)redhat.com>
Modified: trunk/tests/info/info.py
===================================================================
--- trunk/tests/info/info.py 2010-05-20 09:45:36 UTC (rev 509)
+++ trunk/tests/info/info.py 2010-05-20 09:45:46 UTC (rev 510)
@@ -374,10 +374,12 @@
return 1
+def unit_test():
+ test = InfoTest()
+ return test.do(sys.argv)
+
if __name__ == "__main__":
- test = InfoTest()
- returnValue = test.do(sys.argv)
- sys.exit(returnValue)
+ sys.exit(unit_test())
Modified: trunk/v7/command.py
===================================================================
--- trunk/v7/command.py 2010-05-20 09:45:36 UTC (rev 509)
+++ trunk/v7/command.py 2010-05-20 09:45:46 UTC (rev 510)
@@ -245,8 +245,7 @@
-if __name__ == "__main__":
-
+def unit_test():
try:
# positive test: run
command = Command("ls -a")
@@ -309,4 +308,5 @@
except V7CommandException, e:
print e
-
+if __name__ == "__main__":
+ unit_test()
Modified: trunk/v7/hal.py
===================================================================
--- trunk/v7/hal.py 2010-05-20 09:45:36 UTC (rev 509)
+++ trunk/v7/hal.py 2010-05-20 09:45:46 UTC (rev 510)
@@ -10,6 +10,7 @@
import dbus
import re
import string
+import sys
from v7.device import HalDevice
from v7.deviceDetector import DeviceDetector
@@ -112,6 +113,14 @@
return device.getProperty('info.product')
+def unit_test():
+ try:
+ h=Hal()
+ print h.dumpall()
+ return 0
+ except Exception, e:
+ print str(e)
+ return 1
+
if __name__ == "__main__":
- h=Hal()
- print h.dumpall()
+ sys.exit(unit_test())
Modified: trunk/v7/redhatrelease.py
===================================================================
--- trunk/v7/redhatrelease.py 2010-05-20 09:45:36 UTC (rev 509)
+++ trunk/v7/redhatrelease.py 2010-05-20 09:45:46 UTC (rev 510)
@@ -178,7 +178,7 @@
if not self.isValid():
print "Not Valid"
-if __name__ == "__main__":
+def unit_test():
PASSED = 0
FAILED = 1
result = PASSED
@@ -236,9 +236,9 @@
print "FAILED"
else:
print "PASSED"
- exit(result)
-
+ return result
-
-
-
\ No newline at end of file
+
+if __name__ == "__main__":
+ exit(unit_test())
+
13 years, 11 months
r509 - in trunk: . unittests
by David Sommerseth
Author: dsommers
Date: 2010-05-20 09:45:36 +0000 (Thu, 20 May 2010)
New Revision: 509
Added:
trunk/unittests/
trunk/unittests/unittest.py
Log:
Added a simple unit-test framework
The unit-test script can be defined to load defined modules and it will
run a function named unit_test() in the imported modules. It is expected
that the unit_test() function will return 0 on success, otherwise it is
logged as an error.
Signed-off-by: David Sommerseth <davids(a)redhat.com>
Added: trunk/unittests/unittest.py
===================================================================
--- trunk/unittests/unittest.py (rev 0)
+++ trunk/unittests/unittest.py 2010-05-20 09:45:36 UTC (rev 509)
@@ -0,0 +1,128 @@
+#!/usr/bin/env python
+# Copyright (c) 2010 Red Hat, Inc. All rights reserved. This copyrighted material
+# is made available to anyone wishing to use, modify, copy, or
+# redistribute it subject to the terms and conditions of the GNU General
+# Public License v.2.
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Author: David Sommerseth <davids(a)redhat.com>
+#
+
+import os, sys
+
+class UnitTest(object):
+ "Unified unit test class"
+
+ def __init__(self, srcrootdir):
+ "UnitTest constructor. srcrootdir argument must point at the source root directory"
+ self.imported_mods = []
+ self.mod_impcount = 0
+ self.mod_impfail = 0
+ self.mod_testpass = 0
+ self.mod_testfail = 0
+ self.mod_testmiss = 0
+ self.rootdir = srcrootdir
+ sys.path.insert(0, self.rootdir)
+
+
+ def LoadModules(self, modules):
+ """Loads all the defined modules. The modules argument takes a tuple list
+ consisting of ('subdir','module name')"""
+
+ for (directory, mod) in modules:
+ # Check if the directory is in the "include" path
+ try:
+ sys.path.index('%s/%s' % (self.rootdir,directory))
+ except ValueError:
+ # Not found, insert it
+ sys.path.insert(0, '%s/%s' % (self.rootdir, directory))
+
+ try:
+ impmod = __import__(mod)
+ print "** Imported %s/%s" % (directory, mod)
+ self.imported_mods.append({'name': '%s/%s' %(directory, mod),
+ 'module': impmod})
+ self.mod_impcount += 1
+ except ImportError, e:
+ print "!! ** ERROR ** Failed to import %s/%s (Exception: %s)" % (directory, mod, str(e))
+ self.mod_impfail += 1
+
+ return True
+
+
+ def RunTests(self):
+ "Runs the unit_test() function in all successfully imported modules"
+
+ for m in self.imported_mods:
+ try:
+ # Check if the unit_test() function exists and is callable before trying
+ # to run the unit test
+ if callable(m['module'].unit_test):
+ print
+ print 78 * '-'
+ print "** Running unit test for: %s" % m['name']
+ print 78 * '-'
+ res = m['module'].unit_test()
+ if res == 0:
+ print "** Result of %s: PASS" % m['name']
+ self.mod_testpass += 1
+ else:
+ print "** Result of %s: FAILED (return code: %s)" % (m['name'], str(res))
+ self.mod_testfail += 1
+ print 78 * '='
+ else:
+ self.mod_testmiss += 1
+ print "!!! ** ERROR ** Could not run %s::unit_test()" % m['name']
+ except AttributeError:
+ self.mod_testmiss += 1
+ print "!!! ** ERROR ** No %s::unit_test() method found" % m['name']
+
+
+ def PrintTestSummary(self):
+ "Prints a result summary of all the tests"
+ print
+ print " --------------------"
+ print " ** TEST SUMMARY ** "
+ print " --------------------"
+ print
+ print " - Modules:"
+ print " Declared for test: %i" % (self.mod_impcount + self.mod_impfail)
+ print " Successfully imported: %i" % self.mod_impcount
+ print " Failed import: %i" % self.mod_impfail
+ print
+ print " - Tests:"
+ print " Tests scheduled: %i" % (self.mod_testpass + self.mod_testfail + self.mod_testmiss)
+ print " Sucessfully tests: %i" % self.mod_testpass
+ print " Failed tests: %i" % self.mod_testfail
+ print " Missing unit_test() %i" % self.mod_testmiss
+ print
+
+
+if __name__ == '__main__':
+
+ # Retrieve the root directory if the source dir
+ # - use the first occurence of the 'v7' subdir as the root dirq
+ srcrootdir_ar = os.getcwd().split('/')
+ rootdir = '/'.join(srcrootdir_ar[0:srcrootdir_ar.index('v7')+1])
+ print "** Source root dir: %s" % rootdir
+
+ # Prepare the unit tester
+ tests = UnitTest(rootdir)
+
+ # Load defined modules ('subdir','import name')
+ tests.LoadModules((('v7','redhatrelease'),
+ ('v7','command'),
+ ('v7','hal'),
+ ('tests/info', 'info')
+ ))
+ # Run all tests
+ tests.RunTests()
+ tests.PrintTestSummary()
+
Property changes on: trunk/unittests/unittest.py
___________________________________________________________________
Name: svn:executable
+ *
13 years, 11 months