Quality Control: document and unit test : Test « Development « Python

Python
1. 2D
2. Application
3. Buildin Function
4. Class
5. Data Structure
6. Data Type
7. Development
8. Dictionary
9. Event
10. Exception
11. File
12. Function
13. GUI Pmw
14. GUI Tk
15. Language Basics
16. List
17. Math
18. Network
19. String
20. System
21. Thread
22. Tuple
23. Utility
24. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Python » Development » TestScreenshots 
Quality Control: document and unit test
Quality Control: document and unit test



def average(values):
    """Computes the arithmetic mean of a list of numbers.

    >>> print average([20, 30, 70])
    40.0
    """
    return sum(values, 0.0/ len(values)


import doctest
doctest.testmod()   # automatically validate the embedded tests

#The unittest module is not as effortless as the doctest module, but it allows a 
#more comprehensive set of tests to be maintained in a separate file:

import unittest

class TestStatisticalFunctions(unittest.TestCase):

    def test_average(self):
        self.assertEqual(average([203070])40.0)
        self.assertEqual(round(average([157])1)4.3)
        self.assertRaises(ZeroDivisionError, average, [])
        self.assertRaises(TypeError, average, 203070)

unittest.main() # Calling from the command line invokes all tests


           
       
Related examples in the same category
w_w__w__.__j_a__va2_s_.___c__o___m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.