~ubuntuone-pqm-team/click-reviewers-tools/stable

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Runnable tests:
- bin/click-check-lint: lint tests
- bin/click-check-security: security hook tests
- bin/click-check-desktop: desktop hook tests
- bin/click-run-checks: all tests

Importable tests:
- clickreviews/cr_lint.py: lint tests
- clickreviews/cr_security.py: security hook tests
- clickreviews/cr_desktop.py: desktop hook tests

In general, add or modify tests and report by using:
 self._add_result(<type>, <name>, <message>)

Where <type> is one of 'info', 'warn', 'error'. <name> is the name of the
test (prefixed by <review_type>_), which is set when creating a ClickReview
object. After all tests are run, if there are any errors, the exit status is
'2', if there are no errors but some warnings, the exit status is '1',
otherwise it is '0.

See click-check-skeleton and cr_skeleton.py for how to create new tests. In
short:
 * create a click-check-<something> and a cr_<something>.py script based off of
   the skeleton. IMPORTANT: the new script must be click-check-<something> so
   other tools that use click-reviewers-tools (eg, ubuntu-sdk) can find them.
 * modify click-check-<something> to use cr_<something>.py
 * add tests to cr_<something>.py. If you name the tests 'check_<sometest>'
   ClickReview.do_checks() will enumerate and run them automatically

To run tests, just execute: run-tests

If you are going to develop the tools regularly, you might want to add a bzr
hook to run the testsuite before committing. Eg, add something like this to
~/.bazaar/plugins/hooks/__init__.py:

  #!/usr/bin/python
  from bzrlib.branch import Branch

  def run_tests_crt(local, master, old_revno, old_revid, new_revno, new_revid,
                    seven, eight):
      #print local, master, old_revno, old_revid, new_revno, new_revid, seven, eight
      if 'click-reviewers-tools' in master.base:
          import subprocess
          print ''
          rc = subprocess.call(['./run-tests'])
          if rc != 0:
              import sys
              sys.exit(1)

  Branch.hooks.install_named_hook('pre_commit',
                                  run_tests_crt,
                                  'click-reviewers-tools tests')