blob: a546f8c6bb0608775fc05947a44dab10dad4aa2f [file] [log] [blame]
Matthew Treinish8b372892012-12-07 17:13:16 -05001Test Data/Configuration
2-----------------------
3- Assume nothing about existing test data
4- Tests should be self contained (provide their own data)
5- Clean up test data at the completion of each test
6- Use configuration files for values that will vary by environment
7
8
9General
10-------
11- Put two newlines between top-level code (funcs, classes, etc)
12- Put one newline between methods in classes and anywhere else
13- Long lines should be wrapped in parentheses
14 in preference to using a backslash for line continuation.
15- Do not write "except:", use "except Exception:" at the very least
16- Include your name with TODOs as in "#TODO(termie)"
17- Do not name anything the same name as a built-in or reserved word Example::
18
19 def list():
20 return [1, 2, 3]
21
22 mylist = list() # BAD, shadows `list` built-in
23
24 class Foo(object):
25 def list(self):
26 return [1, 2, 3]
27
28 mylist = Foo().list() # OKAY, does not shadow built-in
29
30Imports
31-------
32- Do not import objects, only modules (*)
33- Do not import more than one module per line (*)
34- Do not make relative imports
35- Order your imports by the full module path
36- Organize your imports according to the following template
37
38Example::
39
40 # vim: tabstop=4 shiftwidth=4 softtabstop=4
41 {{stdlib imports in human alphabetical order}}
42 \n
43 {{third-party lib imports in human alphabetical order}}
44 \n
45 {{tempest imports in human alphabetical order}}
46 \n
47 \n
48 {{begin your code}}
49
50
51Human Alphabetical Order Examples
52---------------------------------
53Example::
54
55 import httplib
56 import logging
57 import random
58 import StringIO
ivan-zhu1feeb382013-01-24 10:14:39 +080059 import testtools
Matthew Treinish8b372892012-12-07 17:13:16 -050060 import time
Matthew Treinish8b372892012-12-07 17:13:16 -050061
62 import eventlet
63 import webob.exc
64
65 import tempest.config
66 from tempest.services.compute.json.limits_client import LimitsClientJSON
67 from tempest.services.compute.xml.limits_client import LimitsClientXML
68 from tempest.services.volume.volumes_client import VolumesClientJSON
69 import tempest.test
70
71
72Docstrings
73----------
74Example::
75
76 """A one line docstring looks like this and ends in a period."""
77
78
79 """A multi line docstring has a one-line summary, less than 80 characters.
80
81 Then a new paragraph after a newline that explains in more detail any
82 general information about the function, class or method. Example usages
83 are also great to have here if it is a complex class for function.
84
85 When writing the docstring for a class, an extra line should be placed
86 after the closing quotations. For more in-depth explanations for these
87 decisions see http://www.python.org/dev/peps/pep-0257/
88
89 If you are going to describe parameters and return values, use Sphinx, the
90 appropriate syntax is as follows.
91
92 :param foo: the foo parameter
93 :param bar: the bar parameter
94 :returns: return_type -- description of the return value
95 :returns: description of the return value
96 :raises: AttributeError, KeyError
97 """
98
99
100Dictionaries/Lists
101------------------
102If a dictionary (dict) or list object is longer than 80 characters, its items
103should be split with newlines. Embedded iterables should have their items
104indented. Additionally, the last item in the dictionary should have a trailing
105comma. This increases readability and simplifies future diffs.
106
107Example::
108
109 my_dictionary = {
110 "image": {
111 "name": "Just a Snapshot",
112 "size": 2749573,
113 "properties": {
114 "user_id": 12,
115 "arch": "x86_64",
116 },
117 "things": [
118 "thing_one",
119 "thing_two",
120 ],
121 "status": "ACTIVE",
122 },
123 }
124
125
126Calling Methods
127---------------
128Calls to methods 80 characters or longer should format each argument with
129newlines. This is not a requirement, but a guideline::
130
131 unnecessarily_long_function_name('string one',
132 'string two',
133 kwarg1=constants.ACTIVE,
134 kwarg2=['a', 'b', 'c'])
135
136
137Rather than constructing parameters inline, it is better to break things up::
138
139 list_of_strings = [
140 'what_a_long_string',
141 'not as long',
142 ]
143
144 dict_of_numbers = {
145 'one': 1,
146 'two': 2,
147 'twenty four': 24,
148 }
149
150 object_one.call_a_method('string three',
151 'string four',
152 kwarg1=list_of_strings,
153 kwarg2=dict_of_numbers)
154
155
Matthew Treinish89273ee2013-02-12 13:52:09 -0500156openstack-common
157----------------
158
159A number of modules from openstack-common are imported into the project.
160
161These modules are "incubating" in openstack-common and are kept in sync
162with the help of openstack-common's update.py script. See:
163
164 http://wiki.openstack.org/CommonLibrary#Incubation
165
166The copy of the code should never be directly modified here. Please
167always update openstack-common first and then run the script to copy
168the changes across.
169
170
Matthew Treinish8b372892012-12-07 17:13:16 -0500171OpenStack Trademark
172-------------------
173
Matthew Treinish89273ee2013-02-12 13:52:09 -0500174OpenStack is a registered trademark of the OpenStack Foundation, and uses the
Matthew Treinish8b372892012-12-07 17:13:16 -0500175following capitalization:
176
177 OpenStack
178
179
180Commit Messages
181---------------
182Using a common format for commit messages will help keep our git history
183readable. Follow these guidelines:
184
185 First, provide a brief summary (it is recommended to keep the commit title
186 under 50 chars).
187
188 The first line of the commit message should provide an accurate
189 description of the change, not just a reference to a bug or
190 blueprint. It must be followed by a single blank line.
191
192 If the change relates to a specific driver (libvirt, xenapi, qpid, etc...),
193 begin the first line of the commit message with the driver name, lowercased,
194 followed by a colon.
195
196 Following your brief summary, provide a more detailed description of
197 the patch, manually wrapping the text at 72 characters. This
198 description should provide enough detail that one does not have to
199 refer to external resources to determine its high-level functionality.
200
201 Once you use 'git review', two lines will be appended to the commit
202 message: a blank line followed by a 'Change-Id'. This is important
203 to correlate this commit with a specific review in Gerrit, and it
204 should not be modified.
205
206For further information on constructing high quality commit messages,
207and how to split up commits into a series of changes, consult the
208project wiki:
209
210 http://wiki.openstack.org/GitCommitMessages