blob: 103f8cd76327e74cab3a7330a7091a0517b17f26 [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
59 import time
60 import unittest
61
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
156OpenStack Trademark
157-------------------
158
159OpenStack is a registered trademark of OpenStack, LLC, and uses the
160following capitalization:
161
162 OpenStack
163
164
165Commit Messages
166---------------
167Using a common format for commit messages will help keep our git history
168readable. Follow these guidelines:
169
170 First, provide a brief summary (it is recommended to keep the commit title
171 under 50 chars).
172
173 The first line of the commit message should provide an accurate
174 description of the change, not just a reference to a bug or
175 blueprint. It must be followed by a single blank line.
176
177 If the change relates to a specific driver (libvirt, xenapi, qpid, etc...),
178 begin the first line of the commit message with the driver name, lowercased,
179 followed by a colon.
180
181 Following your brief summary, provide a more detailed description of
182 the patch, manually wrapping the text at 72 characters. This
183 description should provide enough detail that one does not have to
184 refer to external resources to determine its high-level functionality.
185
186 Once you use 'git review', two lines will be appended to the commit
187 message: a blank line followed by a 'Change-Id'. This is important
188 to correlate this commit with a specific review in Gerrit, and it
189 should not be modified.
190
191For further information on constructing high quality commit messages,
192and how to split up commits into a series of changes, consult the
193project wiki:
194
195 http://wiki.openstack.org/GitCommitMessages