commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r7253 - in trunk/gnue-common: . tests


From: jamest
Subject: [gnue] r7253 - in trunk/gnue-common: . tests
Date: Thu, 24 Mar 2005 22:31:07 -0600 (CST)

Author: jamest
Date: 2005-03-24 22:31:06 -0600 (Thu, 24 Mar 2005)
New Revision: 7253

Added:
   trunk/gnue-common/tests/
   trunk/gnue-common/tests/common_apps_checktype.py
   trunk/gnue-common/tests/common_utils_TextUtils.py
   trunk/gnue-common/tests/runAllTests
Log:
added a tests directory for unit tests
after doing so noticed we already have a unittests directory but that the tests 
in there are broken
i think Apycot uses tests as it's default dir so will leave in place for now


Added: trunk/gnue-common/tests/common_apps_checktype.py
===================================================================
--- trunk/gnue-common/tests/common_apps_checktype.py    2005-03-24 20:30:13 UTC 
(rev 7252)
+++ trunk/gnue-common/tests/common_apps_checktype.py    2005-03-25 04:31:06 UTC 
(rev 7253)
@@ -0,0 +1,130 @@
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise 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, or (at your option) any later version.
+#
+# GNU Enterprise 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 program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Copyright 2001-2005 Free Software Foundation
+#
+# FILE:
+# TextUtils.py
+#
+# DESCRIPTION:
+# Test cases for TextUtils.py module
+#
+# NOTES:
+#
+
+import unittest
+from gnue.common.apps.checktype import *
+
+class ChecktypeTestCase(unittest.TestCase):
+  def setUp(self):
+    self.n = None
+    self.s = 'this is a string'
+    self.u = u'this is a unicode string'
+    self.i = 100
+    self.f = 17.85
+    class p:
+      pass
+    class c (p):
+      pass
+    self.p = p
+    self.c = c
+    self.o = c ()
+
+  def testSingleTypesSuccess(self):
+    """Check single types works properly"""
+    checktype (self.n, NoneType)
+    checktype (self.s, StringType)
+    checktype (self.u, UnicodeType)
+    checktype (self.i, IntType)
+    checktype (self.f, FloatType)
+    checktype (self.c, ClassType)
+    checktype (self.o, InstanceType)
+    checktype (self.o, self.c)
+    checktype (self.o, self.p)
+  
+  def testMultipleTypesSuccess(self):
+    """Check multiple types works properly"""
+    checktype (self.n, [StringType, NoneType])
+    checktype (self.s, [StringType, UnicodeType])
+    checktype (self.u, [StringType, UnicodeType])
+    checktype (self.o, [NoneType, self.c])
+
+  def testSingleTypeFailure(self):
+    try:
+      checktype (self.n, StringType)
+    except TypeError:
+      pass
+    else:
+      self.fail('expected a TypeError')
+      
+    try:
+      checktype (self.s, UnicodeType)
+    except TypeError:
+      pass
+    else:
+      self.fail('expected a TypeError')
+    
+    try:
+      checktype (self.u, StringType)
+    except TypeError:
+      pass
+    else:
+      self.fail('expected a TypeError')
+    
+    try:
+      checktype (self.i, FloatType)
+    except TypeError:
+      pass
+    else:
+      self.fail('expected a TypeError')
+    
+    try:
+      checktype (self.o, IntType)
+    except TypeError:
+      pass
+    else:
+      self.fail('expected a TypeError')
+    
+    try:
+      checktype (self.c, self.c)
+    except TypeError:
+      pass
+    else:
+      self.fail('expected a TypeError')
+
+      
+  def testMultipleTypeFailure(self):
+    try:
+     checktype (self.n, [StringType, UnicodeType])
+    except TypeError:
+      pass
+    else:
+      self.fail('expected a TypeError')
+      
+    try:
+      checktype (self.s, [IntType, FloatType])
+    except TypeError:
+      pass
+    else:
+      self.fail('expected a TypeError')
+    
+def suite():
+  suite = unittest.makeSuite(ChecktypeTestCase,'test')
+  
+if __name__ == "__main__":
+  unittest.main()
\ No newline at end of file

Added: trunk/gnue-common/tests/common_utils_TextUtils.py
===================================================================
--- trunk/gnue-common/tests/common_utils_TextUtils.py   2005-03-24 20:30:13 UTC 
(rev 7252)
+++ trunk/gnue-common/tests/common_utils_TextUtils.py   2005-03-25 04:31:06 UTC 
(rev 7253)
@@ -0,0 +1,56 @@
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise 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, or (at your option) any later version.
+#
+# GNU Enterprise 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 program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Copyright 2001-2005 Free Software Foundation
+#
+# FILE:
+# TextUtils.py
+#
+# DESCRIPTION:
+# Test cases for TextUtils.py module
+#
+# NOTES:
+#
+
+import unittest
+from gnue.common.utils.TextUtils import *
+
+class TextTestCase(unittest.TestCase):
+  def setUp(self):
+    self.shortText="Hello"
+    self.longText="This is a longer line used to test the line wrap.  This is 
only a test"
+
+  def testLineWrap(self):
+    """Check that the basic line wrap function properly wraps lines"""
+    output = lineWrap(self.longText,27)
+    expectedResult = 'This is a longer line \nused to test the line \nwrap.  
This is only a test\n'
+    assert output == expectedResult, 'line wrapped incorrectly'
+    
+  def testLineWrapAlignment(self):
+    """Check that line wrap function properly deals with alignment requests"""
+    expectedResultRight = '     This is a longer line \n     used to test the 
line \n wrap.  This is only a test\n'
+    expectedResultCenter = '  This is a longer line \n  used to test the line 
\nwrap.  This is only a test\n'
+    
+    assert lineWrap(self.longText, 27, alignment=ALIGN_RIGHT) == 
expectedResultRight, 'right alignment incorrect'
+    assert lineWrap(self.longText, 27, alignment=ALIGN_CENTER) == 
expectedResultCenter, 'center alignment incorrect'
+    
+def suite():
+  suite = unittest.makeSuite(TextTestCase,'test')
+
+if __name__ == "__main__":
+  unittest.main()
\ No newline at end of file

Added: trunk/gnue-common/tests/runAllTests
===================================================================
--- trunk/gnue-common/tests/runAllTests 2005-03-24 20:30:13 UTC (rev 7252)
+++ trunk/gnue-common/tests/runAllTests 2005-03-25 04:31:06 UTC (rev 7253)
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+#
+# Modified test script based upon the alltest.py file included 
+# in the python 2.3 unittest examples
+#
+import unittest
+import os, re
+
+def suite():
+  fileFilter = re.compile(".py$")
+
+  allFiles = os.listdir('.')
+  testFiles = filter(fileFilter.search, allFiles)
+  testFiles = [ fileFilter.sub("",filename) for filename in testFiles ]
+   
+  suite = unittest.TestSuite()
+  for module in map(__import__, testFiles):
+    suite.addTest(unittest.findTestCases(module))
+  return suite
+  
+if __name__ == '__main__':
+    unittest.main(defaultTest='suite')
+
+
+





reply via email to

[Prev in Thread] Current Thread [Next in Thread]