Skip to content

Commit

Permalink
Rewrite test script to python. Invoke it from .travis.yml. Add some d…
Browse files Browse the repository at this point in the history
…ocs. (google#413)

* Add virtualenv and pip-tools to Developers-Guide.md

* Rewrite testing scripts to Python. Add nodejs build to ".travis.yml".
  • Loading branch information
franekp authored and berggren committed Aug 30, 2017
1 parent 4f96398 commit b5d875a
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 64 deletions.
4 changes: 3 additions & 1 deletion utils/pylintrc → .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ bad-names=foo,bar,baz,toto,tutu,tata
# not require a docstring
no-docstring-rgx=__.*__

# Minimum line length for functions/classes that require docstrings, shorter
# ones are exempt.
docstring-min-length=25

[DESIGN]

Expand Down Expand Up @@ -285,4 +288,3 @@ int-import-graph=
# Exceptions that will emit a warning when being caught. Defaults to
# "Exception"
overgeneral-exceptions=Exception

19 changes: 13 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
sudo: false
language: python
python:
- "2.7"
# command to install dependencies
python: '2.7'
node_js: '8'
cache:
- yarn
- pip

install:
- "pip install ."
# command to run tests
script: nosetests
- pip install .
- yarn install

script:
- ./run_tests.py --full
- yarn run build
8 changes: 8 additions & 0 deletions docs/Developers-Guide.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
### Developers guide

#### Python dependencies
We use pip-tools and virtualenv for development. Pip-tools must be installed
inside a virtualenv, installing it system-wide will cause issues.
If you want to add a new python dependency, please add it to `requirements.in`
and then run pip-compile to pin it's version in `requirements.txt`.
Use `pip-sync` instead of `pip install -r requirements.txt` when possible.
Use `pip-compile --upgrade` to keep dependencies up to date.

#### Installing Node.js and Yarn
Add Node.js 8.x repo

Expand Down
123 changes: 123 additions & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env python
"""Main entry point for running tests and linters."""
from __future__ import print_function

import subprocess
import argparse
import time

def run_python_tests(coverage=False):
try:
if coverage:
subprocess.check_call(
'nosetests --with-coverage'
+ ' --cover-package=timesketch_api_client,timesketch'
+ ' api_client/python/timesketch_api_client/ timesketch/',
shell=True,
)
else:
subprocess.check_call(['nosetests'])
finally:
subprocess.check_call(['rm', '-f', '.coverage'])

def run_python_linter():
subprocess.check_call(['pylint', 'timesketch'])
subprocess.check_call(
'PYTHONPATH=api_client/python/:$PYTHONPATH'
+ ' pylint timesketch_api_client',
shell=True,
)
subprocess.check_call(['pylint', 'run_tests'])
subprocess.check_call(['pylint', 'setup'])

def run_python(args):
if not args.no_tests:
run_python_tests(coverage=args.coverage)
if not args.no_lint:
run_python_linter()

def run_javascript_tests(coverage=False):
# pylint: disable=unused-argument
return NotImplemented

def run_javascript_linter():
return NotImplemented

def run_javascript(args):
if not args.no_tests:
run_javascript_tests(coverage=args.coverage)
if not args.no_lint:
run_javascript_linter()

def run_selenium(args):
# pylint: disable=unused-argument
return NotImplemented

def parse_cli_args(args=None):
"""Parse command-line arguments to this script.
Args:
args: List of cli arguments not including program name
Returns:
Instance of argparse.Namespace with the following boolean attributes:
py, js, selenium, full, no_lint, no_tests, coverage
Raises:
SystemExit if arguments are invalid or --help is present.
"""
p = argparse.ArgumentParser(
description="Run Python and JS unit tests and linters."
+ " Skip selenium tests by default."
)
p.add_argument(
'--py', action='store_true',
help='Run Python tests and linters only.'
)
p.add_argument(
'--js', action='store_true',
help='Run Javascript tests and linters only.'
)
p.add_argument(
'--selenium', action='store_true',
help='Run end-to-end selenium tests only.'
)
p.add_argument(
'--full', action='store_true',
help='Run everything, including selenium.'
)
p.add_argument(
'--no-lint', action='store_true',
help='Skip all linters.'
)
p.add_argument(
'--no-tests', action='store_true',
help='Skip tests, run only linters.'
)
p.add_argument(
'--coverage', action='store_true',
help='Print code coverage report.'
)
return p.parse_args(args)

def main():
start_time = time.time()
args = parse_cli_args()

if args.py:
run_python(args)
elif args.js:
run_javascript(args)
elif args.selenium:
run_selenium(args)
elif args.full:
run_python(args)
run_javascript(args)
run_selenium(args)
else:
run_python(args)
run_javascript(args)

print('Done in %.2fs' % (time.time() - start_time))

main()
25 changes: 0 additions & 25 deletions utils/run_linter.sh

This file was deleted.

32 changes: 0 additions & 32 deletions utils/run_tests.sh

This file was deleted.

0 comments on commit b5d875a

Please sign in to comment.