| 1 |
Patching Cheetah |
| 2 |
================ |
| 3 |
|
| 4 |
|
| 5 |
How to commit changes to git, or submit patches, or send pull requests, |
| 6 |
how to run the test suite. Describe distutils and how the regression tests |
| 7 |
work. |
| 8 |
|
| 9 |
File Requirements |
| 10 |
----------------- |
| 11 |
|
| 12 |
|
| 13 |
The code{Template} class contains not only the Cheetah |
| 14 |
infrastructure, but also some convenience methods useful in all |
| 15 |
templates. More methods may be added if it's generally agreed among |
| 16 |
Cheetah developers that the method is sufficiently useful to all |
| 17 |
types of templates, or at least to all types of HTML-output |
| 18 |
templates. If a method is too long to fit into {Template} - |
| 19 |
especially if it has helper methods - put it in a mixin class under |
| 20 |
{Cheetah.Utils} and inherit it. |
| 21 |
|
| 22 |
Routines for a specific problem domain should be put under |
| 23 |
{Cheetah.Tools}, so that it doesn't clutter the namespace unless |
| 24 |
the user asks for it. |
| 25 |
|
| 26 |
Remember: {Cheetah.Utils} is for objects required by any part of |
| 27 |
Cheetah's core. {Cheetah.Tools} is for completely optional objects. |
| 28 |
It should always be possible to delete {Cheetah.Tools} without |
| 29 |
breaking Cheetah's core services. |
| 30 |
|
| 31 |
If a core method needs to look up an attribute defined under |
| 32 |
{Cheetah.Tools}, it should use {hasattr()} and gracefully provide a |
| 33 |
default if the attribute does not exist (meaning the user has not |
| 34 |
imported that subsystem). |
| 35 |
|
| 36 |
Testing Changes and Building Regression Tests |
| 37 |
--------------------------------------------- |
| 38 |
|
| 39 |
|
| 40 |
Cheetah ships with a regression test suite. To run the built-in |
| 41 |
tests, execute at the shell prompt: |
| 42 |
|
| 43 |
:: |
| 44 |
|
| 45 |
cheetah test |
| 46 |
|
| 47 |
To run the test suite with all supported Python versions use ``tox``. |
| 48 |
|
| 49 |
Before checking any changes in, run the tests and verify they all |
| 50 |
pass. That way, users can check out the git version of Cheetah at |
| 51 |
any time with a fairly high confidence that it will work. If you |
| 52 |
fix a bug or add a feature, please take the time to add a test that |
| 53 |
exploits the bug/feature. This will help in the future, to prevent |
| 54 |
somebody else from breaking it again without realizing it. Users |
| 55 |
can also run the test suite to verify all the features work on |
| 56 |
their particular platform and computer. |
| 57 |
|
| 58 |
The general procedure for modifying Cheetah is as follows: |
| 59 |
|
| 60 |
|
| 61 |
#. Write a simple Python program that exploits the bug/feature |
| 62 |
you're working on. You can either write a regression test (see |
| 63 |
below), or a separate program that writes the template output to |
| 64 |
one file and put the expected output in another file; then you can |
| 65 |
run {diff} on the two outputs. ({diff} is a utility included on all |
| 66 |
Unix-like systems. It shows the differences between two files line |
| 67 |
by line. A precompiled Windows version is at |
| 68 |
http://gnuwin32.sourceforge.net/packages/diffutils.htm, and MacOS |
| 69 |
sources at |
| 70 |
http://perso.wanadoo.fr/gilles.depeyrot/DevTools\_en.html.) |
| 71 |
|
| 72 |
#. Make the change in your Cheetah git sandbox or in your installed |
| 73 |
version of Cheetah. If you make it in the sandbox, you'll have to |
| 74 |
run {python setup.py install} before testing it. If you make it in |
| 75 |
the installed version, do { not} run the installer or it will |
| 76 |
overwrite your changes! |
| 77 |
|
| 78 |
#. Run {cheetah test} to verify you didn't break anything. Then run |
| 79 |
your little test program. |
| 80 |
|
| 81 |
#. Repeat steps 2-3 until everything is correct. |
| 82 |
|
| 83 |
#. Turn your little program into a regression test as described |
| 84 |
below. |
| 85 |
|
| 86 |
#. When {cheetah test} runs cleanly with your regression test |
| 87 |
included, update the {docs/news.rst} file and check in your changes. If |
| 88 |
you made the changes in your installed copy of Cheetah, you'll have |
| 89 |
to copy them back into the git sandbox first. If you added any |
| 90 |
files that must be distributed, { be sure to} {cvs add} them before |
| 91 |
committing. Otherwise Cheetah will run fine on your computer but |
| 92 |
fail on anybody else's, and the test suite can't check for this. |
| 93 |
|
| 94 |
#. Announce the change on the cheetahtemplate-discuss list and |
| 95 |
provide a tutorial if necessary. The documentation maintainer will |
| 96 |
update the Users' Guide and Developers' Guide based on this message |
| 97 |
and on the changelog. |
| 98 |
|
| 99 |
|
| 100 |
If you add a directory to Cheetah, you have to mention it in |
| 101 |
{setup.py} or it won't be installed. |
| 102 |
|
| 103 |
The tests are in the {Cheetah.Tests} package, aka the {Cheetah/Tests/} |
| 104 |
directory of your git sandbox. Most of the tests are in |
| 105 |
{SyntaxAndOutput.py}. You can either run all the tests or choose |
| 106 |
which to run: |
| 107 |
|
| 108 |
Run all the tests. (Equivalent to {cheetah test}.) |
| 109 |
|
| 110 |
Run only the tests in that module. |
| 111 |
|
| 112 |
Run only the tests in the class {CGI} inside the module. The class |
| 113 |
must be a direct or indirect subclass of |
| 114 |
{unittest\_local\_copy.TestCase}. |
| 115 |
|
| 116 |
Run the tests in classes {CGI} and {Indenter}. |
| 117 |
|
| 118 |
Run only test {test1}, which is a method in the {CGI} class. |
| 119 |
|
| 120 |
|
| 121 |
To make a SyntaxAndOutput test, first see if your test logically |
| 122 |
fits into one of the existing classes. If so, simply add a method; |
| 123 |
e.g., {test16}. The method should not require any arguments except |
| 124 |
{self}, and should call {.verify(source, expectedOutput)}, where |
| 125 |
the two arguments are a template definition string and a control |
| 126 |
string. The tester will complain if the template output does not |
| 127 |
match the control string. You have a wide variety of placeholder |
| 128 |
variables to choose from, anything that's included in the |
| 129 |
{defaultTestNameSpace} global dictionary. If that's not enough, add |
| 130 |
items to the dictionary, but please keep it from being cluttered |
| 131 |
with wordy esoteric items for a single test). |
| 132 |
|
| 133 |
If your test logically belongs in a separate class, create a |
| 134 |
subclass of {OutputTest}. You do not need to do anything else; the |
| 135 |
test suite will automatically find your class in the module. Having |
| 136 |
a separate class allows you to define state variables needed by |
| 137 |
your tests (see the {CGI} class) or override {.searchList()} (see |
| 138 |
the {Indenter} class) to provide your own searchList. |
| 139 |
|
| 140 |
To modify another test module or create your own test module, |
| 141 |
you'll have to study the existing modules, the |
| 142 |
{unittest\_local\_copy} source, and the {unittest} documentation in |
| 143 |
the Python Library Reference. Note that we are using a hacked |
| 144 |
version of {unittest} to make a more convenient test structure for |
| 145 |
Cheetah. The differences between {unittest\_local\_copy} and |
| 146 |
Python's standard {unittest} are documented at the top of the |
| 147 |
module. |
| 148 |
|
| 149 |
|