2013-07-03 23:39:46 +00:00
|
|
|
Neutron Style Commandments
|
2015-11-29 13:18:06 +00:00
|
|
|
==========================
|
2012-04-10 03:12:49 +00:00
|
|
|
|
2013-10-16 11:00:23 +00:00
|
|
|
- Step 1: Read the OpenStack Style Commandments
|
2017-07-21 07:05:21 +00:00
|
|
|
https://docs.openstack.org/hacking/latest/
|
2013-10-16 11:00:23 +00:00
|
|
|
- Step 2: Read on
|
2012-04-10 03:12:49 +00:00
|
|
|
|
2013-10-16 11:00:23 +00:00
|
|
|
Neutron Specific Commandments
|
2015-11-29 13:18:06 +00:00
|
|
|
-----------------------------
|
2012-04-10 03:12:49 +00:00
|
|
|
|
2017-04-12 23:43:44 +00:00
|
|
|
Some rules are enforced by `neutron-lib hacking factory
|
2017-07-21 07:05:21 +00:00
|
|
|
<https://docs.openstack.org/neutron-lib/latest/user/hacking.html>`_
|
2017-04-12 23:43:44 +00:00
|
|
|
while other rules are specific to Neutron repository.
|
|
|
|
|
|
|
|
Below you can find a list of checks specific to this repository.
|
|
|
|
|
2015-01-12 16:04:14 +00:00
|
|
|
- [N322] Detect common errors with assert_called_once_with
|
2015-10-05 22:50:18 +00:00
|
|
|
- [N328] Detect wrong usage with assertEqual
|
2021-05-21 10:05:35 +00:00
|
|
|
- [N329] Use assertCountEqual() instead of assertItemsEqual()
|
2016-01-13 14:18:42 +00:00
|
|
|
- [N330] Use assertEqual(*empty*, observed) instead of
|
|
|
|
assertEqual(observed, *empty*)
|
2016-01-06 03:27:34 +00:00
|
|
|
- [N331] Detect wrong usage with assertTrue(isinstance()).
|
2016-01-28 09:42:53 +00:00
|
|
|
- [N332] Use assertEqual(expected_http_code, observed_http_code) instead of
|
|
|
|
assertEqual(observed_http_code, expected_http_code).
|
2016-01-26 01:52:47 +00:00
|
|
|
- [N340] Check usage of <module>.i18n (and neutron.i18n)
|
|
|
|
- [N341] Check usage of _ from python builtins
|
2016-08-30 10:42:41 +00:00
|
|
|
- [N343] Production code must not import from neutron.tests.*
|
2016-08-29 11:15:30 +00:00
|
|
|
- [N344] Python 3: Do not use filter(lambda obj: test(obj), data). Replace it
|
|
|
|
with [obj for obj in data if test(obj)].
|
2020-06-09 08:43:32 +00:00
|
|
|
- [N346] Use neutron_lib.db.api.sqla_listen rather than sqlalchemy
|
|
|
|
- [N347] Test code must not import mock library
|
2020-07-10 17:14:37 +00:00
|
|
|
- [N348] Test code must not import six library
|
2017-04-12 23:43:44 +00:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
When adding a new hacking check to this repository or ``neutron-lib``, make
|
|
|
|
sure its number (Nxxx) doesn't clash with any other check.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
As you may have noticed, the numbering for Neutron checks has gaps. This is
|
|
|
|
because some checks were removed or moved to ``neutron-lib``.
|
2012-04-10 03:12:49 +00:00
|
|
|
|
|
|
|
Creating Unit Tests
|
|
|
|
-------------------
|
|
|
|
For every new feature, unit tests should be created that both test and
|
|
|
|
(implicitly) document the usage of said feature. If submitting a patch for a
|
|
|
|
bug that had no unit test, a new passing unit test should be added. If a
|
|
|
|
submitted bug fix does have a unit test, be sure to add a new one that fails
|
|
|
|
without the patch and passes with the patch.
|
|
|
|
|
2013-02-23 10:35:28 +00:00
|
|
|
All unittest classes must ultimately inherit from testtools.TestCase. In the
|
2013-07-03 23:39:46 +00:00
|
|
|
Neutron test suite, this should be done by inheriting from
|
2020-01-10 16:28:13 +00:00
|
|
|
neutron.tests.base.BaseTestCase.
|
2013-02-23 10:35:28 +00:00
|
|
|
|
2013-02-06 06:01:30 +00:00
|
|
|
All setUp and tearDown methods must upcall using the super() method.
|
|
|
|
tearDown methods should be avoided and addCleanup calls should be preferred.
|
|
|
|
Never manually create tempfiles. Always use the tempfile fixtures from
|
|
|
|
the fixture library to ensure that they are cleaned up.
|