Can build a simple and useful unit test system in python exploiting first class functions, dynamic checks on the names of functions, and a naming convention.
See codepad.org for coloured src and a sample run, or github for a "gist" with highlighted source.
### Begin unit test code
def test_function1():
# Do some test code
# return True on Pass, False on Fail
def test_function2_EXPECTED_FAIL():
# Do some test (more) code
# return True on Pass, False on Fail
def test_functionN():
# Do some test (more) code
# return True on Pass, False on Fail
# Build a list of test functions to run
# as test cases
tests = [ test_function1
, test_function2_EXPECTED_FAIL
# as many as you like...
, test_functionN
]
def main():
failed = []
# Invoke each test case in turn
for t in tests:
if not t():
# Can check names of test functions
# to detect expected fails
if t.__name__.endswith("_EXPECTED_FAIL"):
continue
# Record fails for later report
failed.append(t.__name__)
# Can stop on 1st fail if desired
# return 1
# Print the list of tests that failed, if any
for f in failed:
print "FAIL:",f
# Invoke the test runner
if __name__ == "__main__":
main()
### End unit test code
Tile based game development tutorial.
A series of blog articles on Maze generation algorithms.
A C pre processor (cpp) in python. A programmers text editor Kod for OSX based on the google chrome tab UI.
No comments:
Post a Comment