Merge lp:~statik/terminator/add-test-goo into lp:terminator/trunk

Proposed by Elliot Murphy
Status: Rejected
Rejected by: Chris Jones
Proposed branch: lp:~statik/terminator/add-test-goo
Merge into: lp:terminator/trunk
Diff against target: 102 lines (+75/-0)
5 files modified
terminatorlib/tests/exampledoctest.txt (+13/-0)
terminatorlib/tests/test_configfile.py (+32/-0)
test (+22/-0)
testing/failure.txt (+4/-0)
testing/success.txt (+4/-0)
To merge this branch: bzr merge lp:~statik/terminator/add-test-goo
Reviewer Review Type Date Requested Status
Terminator Pending
Review via email: mp+16059@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Elliot Murphy (statik) wrote :

Here is some crap to run tests.
You'll need python-twisted-core installed (to get /usr/bin/trial) and python-testtools (to get the awesome testtools module).

Then do ./test and observe the wonderful demonstration of tests being found, passing, failing, skipping, and doctests.

Under the covers it's running 'trial terminatorlib', and if you specify any arguments to ./test they get passed through transparently to trial so you can do all kinds of cool stuff like generate coverage files, etc.

thanks for making terminator.

Revision history for this message
Elliot Murphy (statik) wrote :

BTW this setup.py shows how you could make trial run as part of 'setup.py test', which i think is how you would get tests to be executed during package build in the PPA.

Revision history for this message
Elliot Murphy (statik) wrote :

> BTW this setup.py shows how you could make trial run as part of 'setup.py
> test', which i think is how you would get tests to be executed during package
> build in the PPA.

Link included this time. http://bazaar.launchpad.net/~ubuntuone-control-tower/ubuntuone-storage-protocol/trunk/annotate/head:/setup.py

Revision history for this message
Chris Jones (cmsj) wrote :

Interesting stuff :)
The current trunk, as you probably noticed, has zero test coverage because I fail at this sort of thing.
However, I am working on a honking great refactoring of essentially all of Terminator at lp:~cmsj/+junk/terminator-epic-refactor and some of the new files in terminatorlib do actually have doctests in them, but I'm failing to use what you've done here to make those doctests work.

(given the choice I'd rather craft your test goo into the epic-refactor branch than trunk since in my head trunk is old and busted ;)

Revision history for this message
Chris Jones (cmsj) wrote :

(setting the status of this merge request to Rejected since I instead merged your other awesome test integration into epic-refactor [which btw has now landed on trunk])

Unmerged revisions

800. By Elliot Murphy

Forgot to add the toilet files.

799. By Elliot Murphy

This is a basic example of how to set up a unit testing framework.
It shows both standard unit tests and doctests.
Also shown is skipping tests so you can have tests which only run
in certain environments be skipped rather than failing.
Extra fancy results on the terminal for optimum programmer motivation.
It does not show how to integrate test with setup.py, or how to split
tests into parallel suites for blazing speed.

This is based on using trial as the testrunner, and some convenience
functions from python-testtools that are forward-compatible with python2.7

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'terminatorlib/tests'
2=== added file 'terminatorlib/tests/__init__.py'
3=== added file 'terminatorlib/tests/exampledoctest.txt'
4--- terminatorlib/tests/exampledoctest.txt 1970-01-01 00:00:00 +0000
5+++ terminatorlib/tests/exampledoctest.txt 2009-12-11 21:15:26 +0000
6@@ -0,0 +1,13 @@
7+This is a story about testing. Some people like doctests. Some people hate them.
8+Either way, you can make these tests run as part of a normal unittest suite.
9+The way doctests work is they execute the code after the triple angles, and they
10+'test' that the output matches what should be there.
11+
12+>>> import sys
13+>>> print 'works'
14+works
15+
16+Let's have one which fails
17+>>> print 'fails'
18+fAILs
19+
20
21=== added file 'terminatorlib/tests/test_configfile.py'
22--- terminatorlib/tests/test_configfile.py 1970-01-01 00:00:00 +0000
23+++ terminatorlib/tests/test_configfile.py 2009-12-11 21:15:26 +0000
24@@ -0,0 +1,32 @@
25+import testtools
26+from testtools import skip, skipIf, skipUnless
27+import doctest
28+
29+VERSION = 5
30+
31+class TestConfigFile(testtools.TestCase):
32+ """Testing that config file loading works ok and we catch common
33+ mistakes."""
34+
35+ def setUp(self):
36+ """This is run before every test."""
37+
38+ def tearDown(self):
39+ """This is run after every test."""
40+
41+ def test_which_fails(self):
42+ self.fail("This test fails on purpose")
43+
44+ def test_which_passes(self):
45+ self.assertEqual(5, int('5'))
46+
47+ def test_run_doctests(self):
48+ """Here is a way to wire in some doctests in a text file"""
49+ results = doctest.testfile('exampledoctest.txt')
50+ self.assertEqual(0, results.failed)
51+
52+ @skipIf(VERSION == 5, 'honking is not in version 5')
53+ def test_pickle_honker(self):
54+ """This test fails if version equals 5"""
55+ self.assertNotEqual(version, 5)
56+
57
58=== added file 'test'
59--- test 1970-01-01 00:00:00 +0000
60+++ test 2009-12-11 21:15:26 +0000
61@@ -0,0 +1,22 @@
62+#!/usr/bin/env python
63+
64+import subprocess
65+import sys
66+import os
67+
68+def run_tests():
69+ command = ['trial']
70+ args = sys.argv[1:]
71+ if not args:
72+ args = ['terminatorlib']
73+ was_successful = not subprocess.call(command + args)
74+ return was_successful
75+
76+if __name__ == "__main__":
77+ status = run_tests()
78+ if sys.stdout.isatty():
79+ if status:
80+ os.system('cat testing/success.txt')
81+ else:
82+ os.system('cat testing/failure.txt')
83+ sys.exit(status)
84
85=== added directory 'testing'
86=== added file 'testing/failure.txt'
87--- testing/failure.txt 1970-01-01 00:00:00 +0000
88+++ testing/failure.txt 2009-12-11 21:15:26 +0000
89@@ -0,0 +1,4 @@
90+▞▀▖▛▀▖▌ ▌▞▀▖▌ ▌▜▘▙ ▌▞▀▖ ▛▀▘▞▀▖▜▘▌ ▌ ▌▛▀▖▛▀▘ ▞▚ ▛▀▖▛▀▘▞▀▖▛▀▖▞▀▖▜▘▛▀▖
91+▌ ▙▄▘▌ ▌▚▄ ▙▄▌▐ ▌▌▌▌▄▖ ▙▄ ▙▄▌▐ ▌ ▌ ▌▙▄▘▙▄ ▚ ▌ ▌▙▄ ▚▄ ▙▄▘▙▄▌▐ ▙▄▘
92+▌ ▖▌▚ ▌ ▌▖ ▌▌ ▌▐ ▌▝▌▌ ▌ ▌ ▌ ▌▐ ▌ ▌ ▌▌▚ ▌ ▌▚▘ ▌ ▌▌ ▖ ▌▌ ▌ ▌▐ ▌▚
93+▝▀ ▘ ▘▝▀ ▝▀ ▘ ▘▀▘▘ ▘▝▀ ▘ ▘ ▘▀▘▀▀▘▝▀ ▘ ▘▀▀▘ ▝▘▘ ▀▀ ▀▀▘▝▀ ▘ ▘ ▘▀▘▘ ▘
94
95=== added file 'testing/success.txt'
96--- testing/success.txt 1970-01-01 00:00:00 +0000
97+++ testing/success.txt 2009-12-11 21:15:26 +0000
98@@ -0,0 +1,4 @@
99+▞▀▖▞▀▖▞▀▖▛▀▖ ▜▘▞▀▖▛▀▖▐
100+▌▄▖▌ ▌▌ ▌▌ ▌ ▐ ▌ ▌▙▄▘▐
101+▌ ▌▌ ▌▌ ▌▌ ▌ ▌▐ ▌ ▌▌ ▌▝
102+▝▀ ▝▀ ▝▀ ▀▀ ▝▘ ▝▀ ▀▀ ▝