diff options
| -rw-r--r-- | SUBMITTING_PATCHES.md | 26 | ||||
| -rwxr-xr-x | run_tests | 54 | ||||
| -rw-r--r-- | tests/fixtures/.gitignore | 2 |
3 files changed, 76 insertions, 6 deletions
diff --git a/SUBMITTING_PATCHES.md b/SUBMITTING_PATCHES.md index 07f76616..e8a72e87 100644 --- a/SUBMITTING_PATCHES.md +++ b/SUBMITTING_PATCHES.md | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | [TOC] | ||
| 2 | |||
| 1 | # Short Version | 3 | # Short Version |
| 2 | 4 | ||
| 3 | - Make small logical changes. | 5 | - Make small logical changes. |
| @@ -52,17 +54,29 @@ Run `flake8` on changes modules: | |||
| 52 | 54 | ||
| 53 | flake8 file.py | 55 | flake8 file.py |
| 54 | 56 | ||
| 55 | Note that repo generally follows [Google's python style guide] | 57 | Note that repo generally follows [Google's python style guide] rather than |
| 56 | (https://google.github.io/styleguide/pyguide.html) rather than [PEP 8] | 58 | [PEP 8], so it's possible that the output of `flake8` will be quite noisy. |
| 57 | (https://www.python.org/dev/peps/pep-0008/), so it's possible that | 59 | It's not mandatory to avoid all warnings, but at least the maximum line |
| 58 | the output of `flake8` will be quite noisy. It's not mandatory to | 60 | length should be followed. |
| 59 | avoid all warnings, but at least the maximum line length should be | ||
| 60 | followed. | ||
| 61 | 61 | ||
| 62 | If there are many occurrences of the same warning that cannot be | 62 | If there are many occurrences of the same warning that cannot be |
| 63 | avoided without going against the Google style guide, these may be | 63 | avoided without going against the Google style guide, these may be |
| 64 | suppressed in the included `.flake8` file. | 64 | suppressed in the included `.flake8` file. |
| 65 | 65 | ||
| 66 | [Google's python style guide]: https://google.github.io/styleguide/pyguide.html | ||
| 67 | [PEP 8]: https://www.python.org/dev/peps/pep-0008/ | ||
| 68 | |||
| 69 | |||
| 70 | ## Running tests | ||
| 71 | |||
| 72 | There is a [`./run_tests`](./run_tests) helper script for quickly invoking all | ||
| 73 | of our unittests. The coverage isn't great currently, but it should still be | ||
| 74 | run for all commits. | ||
| 75 | |||
| 76 | Adding more unittests for changes you make would be greatly appreciated :). | ||
| 77 | Check out the [tests/](./tests/) subdirectory for more details. | ||
| 78 | |||
| 79 | |||
| 66 | ## Check the license | 80 | ## Check the license |
| 67 | 81 | ||
| 68 | repo is licensed under the Apache License, 2.0. | 82 | repo is licensed under the Apache License, 2.0. |
diff --git a/run_tests b/run_tests new file mode 100755 index 00000000..f72b22c5 --- /dev/null +++ b/run_tests | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | #!/usr/bin/python | ||
| 2 | # -*- coding:utf-8 -*- | ||
| 3 | # Copyright 2019 The Android Open Source Project | ||
| 4 | # | ||
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 6 | # you may not use this file except in compliance with the License. | ||
| 7 | # You may obtain a copy of the License at | ||
| 8 | # | ||
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 10 | # | ||
| 11 | # Unless required by applicable law or agreed to in writing, software | ||
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 14 | # See the License for the specific language governing permissions and | ||
| 15 | # limitations under the License. | ||
| 16 | |||
| 17 | """Wrapper to run pytest with the right settings.""" | ||
| 18 | |||
| 19 | from __future__ import print_function | ||
| 20 | |||
| 21 | import errno | ||
| 22 | import os | ||
| 23 | import subprocess | ||
| 24 | import sys | ||
| 25 | |||
| 26 | |||
| 27 | def run_pytest(cmd, argv): | ||
| 28 | """Run the unittests via |cmd|.""" | ||
| 29 | try: | ||
| 30 | subprocess.check_call([cmd] + argv) | ||
| 31 | return 0 | ||
| 32 | except OSError as e: | ||
| 33 | if e.errno == errno.ENOENT: | ||
| 34 | print('%s: unable to run `%s`: %s' % (__file__, cmd, e), file=sys.stderr) | ||
| 35 | print('%s: Try installing pytest: sudo apt-get install python-pytest' % | ||
| 36 | (__file__,), file=sys.stderr) | ||
| 37 | return 1 | ||
| 38 | else: | ||
| 39 | raise | ||
| 40 | |||
| 41 | |||
| 42 | def main(argv): | ||
| 43 | """The main entry.""" | ||
| 44 | # Add the repo tree to PYTHONPATH as the tests expect to be able to import | ||
| 45 | # modules directly. | ||
| 46 | topdir = os.path.dirname(os.path.realpath(__file__)) | ||
| 47 | pythonpath = os.environ.get('PYTHONPATH', '') | ||
| 48 | os.environ['PYTHONPATH'] = '%s:%s' % (topdir, pythonpath) | ||
| 49 | |||
| 50 | return run_pytest('pytest', argv) | ||
| 51 | |||
| 52 | |||
| 53 | if __name__ == '__main__': | ||
| 54 | sys.exit(main(sys.argv[1:])) | ||
diff --git a/tests/fixtures/.gitignore b/tests/fixtures/.gitignore new file mode 100644 index 00000000..7b3d2db9 --- /dev/null +++ b/tests/fixtures/.gitignore | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | /.repo_not.present.gitconfig.json | ||
| 2 | /.repo_test.gitconfig.json | ||
