Skip to content

Commit

Permalink
Add script for running tests
Browse files Browse the repository at this point in the history
Add codecov test requirements
  • Loading branch information
Erotemic committed Jan 12, 2020
1 parent 2eb1cd9 commit 3734399
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 6 deletions.
26 changes: 26 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[run]
branch = True
source = ubelt

[report]
exclude_lines =
pragma: no cover
.* # pragma: no cover
.* # nocover
def __repr__
raise AssertionError
raise NotImplementedError
if 0:
if trace is not None
verbose = .*
^ *raise
^ *pass *$
if _debug:
if __name__ == .__main__.:
.*if six.PY2:

omit =
ubelt/tests/*
ubelt/_win32_links.py
ubelt/__main__.py
*/setup.py
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ line_profiler.egg-info/
MANIFEST
pypi-site-docs.zip
index.html

.coverage
tests/htmlcov
23 changes: 19 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ install:

script:
# Test the installed multibuild wheel
- cd tests && travis_wait pytest && cd ..
- travis_wait ./run_tests.py

after_success:
- codecov
Expand All @@ -65,12 +65,27 @@ after_success:
echo $PYUTILS_TWINE_PASSWORD
echo $PYUTILS_CI_GITHUB_SECRET
# In your repo directory run the command to ensure travis recognizes the repo
# It will say: Detected repository as <user>/<repo>, is this correct? |yes|
# Answer yes before running the encrypt commands.
travis status
# encrypt relevant travis variables (requires travis cli)
#sudo apt install ruby ruby-dev -y
#sudo gem install travis
travis encrypt PYUTILS_TWINE_USERNAME=$PYUTILS_TWINE_USERNAME
travis encrypt PYUTILS_TWINE_PASSWORD=$PYUTILS_TWINE_PASSWORD
travis encrypt PYUTILS_CI_GITHUB_SECRET=$PYUTILS_CI_GITHUB_SECRET
SECURE_TWINE_USERNAME=$(travis encrypt --no-interactive PYUTILS_TWINE_USERNAME=$PYUTILS_TWINE_USERNAME)
SECURE_TWINE_PASSWORD=$(travis encrypt --no-interactive PYUTILS_TWINE_PASSWORD=$PYUTILS_TWINE_PASSWORD)
SECURE_CI_GITHUB_SECRET=$(travis encrypt --no-interactive PYUTILS_CI_GITHUB_SECRET=$PYUTILS_CI_GITHUB_SECRET)
echo "
Add the following lines to your .travis.yml
env:
global:
- secure: $SECURE_TWINE_USERNAME
- secure: $SECURE_TWINE_PASSWORD
- secure: $SECURE_CI_GITHUB_SECRET
"
# HOW TO ENCRYPT YOUR SECRET GPG KEY
IDENTIFIER=PyUtils
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changes
=======

3.0.2
~~~~~
* BUG: fix ``__version__`` attribute in Python 2 CLI.

3.0.1
~~~~~
* BUG: fix calling the package from the command line
Expand Down
4 changes: 4 additions & 0 deletions clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ echo "start clean"
rm -rf _skbuild
rm -rf _line_profiler.c
rm -rf *.so
rm -rf line_profiler/_line_profiler.c
rm -rf line_profiler/*.so
rm -rf build
rm -rf line_profiler.egg-info
rm -rf dist
rm -rf mb_work
rm -rf wheelhouse
rm -rf pip-wheel-metadata
rm -rf htmlcov

rm distutils.errors || echo "skip rm"

Expand Down
7 changes: 5 additions & 2 deletions requirements/tests.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
pytest
ubelt
pytest >= 3.3.1
pytest-cov
coverage >= 4.3.4
codecov >= 2.0.15
ubelt >= 0.8.7
53 changes: 53 additions & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from os.path import dirname, join, abspath
import sys
import os

if __name__ == '__main__':
cwd = os.getcwd()
repo_dir = abspath(dirname(__file__))
test_dir = join(repo_dir, 'tests')
print('cwd = {!r}'.format(cwd))

import pytest

# Prefer testing the installed version, but fallback to testing the
# development version.
try:
import ubelt as ub
except ImportError:
print('running this test script requires ubelt')
raise
# Statically check if ``line_profiler`` is installed outside of the repo.
# To do this, we make a copy of PYTHONPATH, remove the repodir, and use
# ubelt to check to see if ``line_profiler`` can be resolved to a path.
temp_path = list(map(abspath, sys.path))
if repo_dir in temp_path:
temp_path.remove(repo_dir)
modpath = ub.modname_to_modpath('line_profiler', sys_path=temp_path)
if modpath is not None:
# If it does, then import it. This should cause the installed version
# to be used on further imports even if the repo_dir is in the path.
print('Using installed version of line_profiler')
module = ub.import_module_from_path(modpath, index=0)
print('Installed module = {!r}'.format(module))
else:
print('No installed version of line_profiler found')

try:
print('Changing dirs to test_dir={!r}'.format(test_dir))
os.chdir(test_dir)

package_name = 'line_profiler'
pytest_args = [
'--cov-config', '../.coveragerc',
'--cov-report', 'html',
'--cov-report', 'term',
'--cov=' + package_name,
]
pytest_args = pytest_args + sys.argv[1:]
sys.exit(pytest.main(pytest_args))
finally:
os.chdir(cwd)
print('Restoring cwd = {!r}'.format(cwd))

0 comments on commit 3734399

Please sign in to comment.