Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 515c3c0

Browse files
committed
Try tox.
1 parent ab67020 commit 515c3c0

File tree

6 files changed

+177
-111
lines changed

6 files changed

+177
-111
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88

99
*.coverage
1010

11+
*.tox
12+
1113
build
1214

1315
dist
1416

1517
debug_script.py
1618

17-
test_output.txt
19+
test_output.txt

circle.yml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,46 @@ machine:
22

33
environment:
44

5-
PLOTLY_PACKAGE_ROOT: /home/ubuntu/${CIRCLE_PROJECT_REPONAME}
65
PLOTLY_CONFIG_DIR: ${HOME}/.plotly
7-
PLOTLY_PYTHON_VERSIONS: 2.7.8 3.3.3 3.4.1
8-
PLOTLY_CORE_REQUIREMENTS_FILE: ${PLOTLY_PACKAGE_ROOT}/requirements.txt
9-
PLOTLY_OPTIONAL_REQUIREMENTS_FILE: ${PLOTLY_PACKAGE_ROOT}/optional-requirements.txt
6+
TOX_TESTENV_PASSENV: PLOTLY_TOX_*
7+
PLOTLY_TOX_PYTHON_27: /home/ubuntu/.pyenv/versions/2.7.10/bin/python2.7
8+
PLOTLY_TOX_PYTHON_33: /home/ubuntu/.pyenv/versions/3.3.3/bin/python3.3
9+
PLOTLY_TOX_PYTHON_34: /home/ubuntu/.pyenv/versions/3.4.3/bin/python3.4
10+
PLOTLY_TOX_PYTHON_35: /home/ubuntu/.pyenv/versions/3.5.0/bin/python3.5
1011

1112
dependencies:
1213

1314
override:
1415

15-
# run all the pre-written installers (this will take a *while*)
16-
- bash circle/setup.sh
17-
18-
# install testing tools for circle's version of things
19-
- pip install nose coverage
16+
# install everything tox knows about and the plotly package.
17+
- pip install tox
18+
- tox --notest
2019
- pip install -I .
2120

2221
# we need to cd out of the project root to ensure the install worked
2322
- cd ~ && python -c "import plotly"
2423

2524
cache_directories:
2625

27-
- "~/.pyenv/versions" # attempt to just cache installed pyenv things
26+
# cache everything that tox installs for us.
27+
- .tox
2828

2929
test:
3030

3131
override:
3232

33-
# run test suite in all our python versions
34-
- bash circle/test.sh
33+
# let tox do its thing. matplotlib is broken at the moment.
34+
- tox -- -a '!matplotlib'
35+
36+
# we setup tox to create coverage reports, move them to artifacts.
37+
- mv ~/${CIRCLE_PROJECT_REPONAME}/.tox/coverage-reports ${CIRCLE_ARTIFACTS}
38+
39+
# import it once normally (ensures .plotly exists)
40+
- python -c "import plotly"
3541

3642
# test that it imports when you don't have write permissions
3743
- sudo chmod -R 444 ${PLOTLY_CONFIG_DIR} && python -c "import plotly"
3844

3945
# test that giving back write permissions works again
4046
# this also has to pass the test suite that follows
4147
- sudo chmod -R 777 ${PLOTLY_CONFIG_DIR} && python -c "import plotly"
42-
43-
# test core things in the general 2.7 version that circle has
44-
- nosetests -x plotly/tests/test_core --with-coverage --cover-package=plotly
45-
- mkdir "${CIRCLE_ARTIFACTS}/2.7" || true
46-
- coverage html -d "${CIRCLE_ARTIFACTS}/2.7" --title=2.7

circle/setup.sh

Lines changed: 0 additions & 44 deletions
This file was deleted.

circle/test.sh

Lines changed: 0 additions & 47 deletions
This file was deleted.

contributing.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,12 @@ pip install -r optional-requirements.txt
100100

101101
##Testing
102102

103-
Our API uses Nose to run tests. (https://nose.readthedocs.org/en/latest/)
103+
We take advantage of two tools to run tests:
104104

105-
###Running Tests
105+
* [`tox`](https://tox.readthedocs.io/en/latest/), which is both a virtualenv management and test tool.
106+
* [`nose`](https://nose.readthedocs.org/en/latest/), which is is an extension of Python's unittest
107+
108+
###Running Tests with `nose`
106109

107110
Since our tests cover *all* the functionality, to prevent tons of errors from showing up and having to parse through a messy output, you'll need to install `optional-requirements.txt` as explained above.
108111

@@ -130,6 +133,47 @@ nosetests -w plotly/tests/test_plotly
130133
nosetests plotly/tests/test_plotly/test_plot.py
131134
```
132135

136+
###Running tests with `tox`
137+
138+
Running tests with tox is much more powerful, but requires a bit more setup.
139+
140+
You'll need to export an environment variable for *each* tox environment you wish to test with. For example, if you want to test with `Python 2.7` and
141+
`Python 3.4`, but only care to check the `core` specs, you would need to ensure that the following variables are exported:
142+
143+
```
144+
export PLOTLY_TOX_PYTHON_27=<python binary>
145+
export PLOTLY_TOX_PYTHON_34=<python binary>
146+
```
147+
148+
Where the `<python binary` is going to be specific to your development setup. As a more complete example, you might have this loaded in a `.bash_profile` (or equivalent shell loader):
149+
150+
```bash
151+
############
152+
# tox envs #
153+
############
154+
155+
export PLOTLY_TOX_PYTHON_27=python2.7
156+
export PLOTLY_TOX_PYTHON_34=python3.4
157+
export TOXENV=py27-core,py34-core
158+
```
159+
160+
Where `TOXENV` is the environment list you want to use when invoking `tox` from the command line. Note that the `PLOTLY_TOX_*` pattern is used to pass in variables for use in the `tox.ini` file. Though this is a little setup, intensive, you'll get the following benefits:
161+
162+
* `tox` will automatically manage a virtual env for each environment you want to test in.
163+
* You only have to run `tox` and know that the module is working in both `Python 2` and `Python 3`.
164+
165+
Finally, `tox` allows you to pass in additional command line arguments that are formatted in (by us) in the `tox.ini` file, see `{posargs}`. This is setup to help with our `nose attr` configuration. To run only tests that are *not* tagged with `slow`, you could use the following command:
166+
167+
```bash
168+
tox -- -a '!slow'
169+
```
170+
171+
Note that anything after `--` is substituted in for `{posargs}` in the tox.ini. For completeness, because it's reasonably confusing, if you want to force a match for *multiple* `nose attr` tags, you comma-separate the tags like so:
172+
173+
```bash
174+
tox -- -a '!slow','!matplotlib'
175+
```
176+
133177
###Writing Tests
134178

135179
You're *strongly* encouraged to write tests that check your added functionality.

tox.ini

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
; Tox is a testing tool that manages virtualenvs for testing multiple Python
2+
; environments in a consistent/controlled way.
3+
4+
; SETTING ENVIRONMENT VARIABLES AND TOX TESTING VARIABLES
5+
;
6+
; You can limit tox testing to certain environments via the `-e` (envlist)
7+
; command line option:
8+
; tox -e py27-core,py34-core
9+
; OR, you can just set the `TOXENV` environment variable, which is handy:
10+
; TOXENV=py27-core,py34-core
11+
;
12+
; Integrating with the virtualenvs in Circle CI is a bit of a pain. For
13+
; whatever reason the "executable" `python35` (at the time of writing) cannot
14+
; be activated directly. Instead the circle.yml file specifies the actual
15+
; binary directly. Because of this, you too have to set the following env
16+
; variables:
17+
; PLOTLY_TOX_PYTHON_27=python2.7
18+
; PLOTLY_TOX_PYTHON_34=python3.4
19+
; ...
20+
; These will be specific to your machine and may not look like the ones above.
21+
; If you're not testing with all the python versions (see TOXENV above),
22+
; there's no need to install and map other versions.
23+
24+
; PASSING ADDITONAL ARGUMENTS TO TEST COMMANDS
25+
; The {posargs} is tox-specific and passes in any command line args after `--`.
26+
; For example, given the testing command in *this* file:
27+
; nosetests {posargs} -x plotly/tests/test_core
28+
;
29+
; The following command:
30+
; tox -- -a '!slow'
31+
;
32+
; Tells tox to call:
33+
; nosetests -a '!slow' -x plotly/tests/test_core
34+
;
35+
; Which is a nice way to skip slow tests for faster testing cycles.
36+
37+
[tox]
38+
; The py{A,B,C}-{X,Y} generates a matrix of envs:
39+
; pyA-X,pyA-Y,pyB-X,pyB-Y,pyC-X,pyC-Y
40+
envlist = py{27,34,35}-{core,optional},py33-core
41+
42+
; Note that envs can be targeted by deps using the <target>: dep syntax.
43+
; Only one dep is allowed per line as of the time of writing. The <target>
44+
; can be a `-` (hyphen) concatenated string of the environments to target
45+
; with the given dep.
46+
47+
; These commands are general and will be run for *all* environments.
48+
[testenv]
49+
passenv=PLOTLY_TOX_*
50+
whitelist_externals=
51+
mkdir
52+
deps=
53+
coverage==4.3.1
54+
mock==2.0.0
55+
nose==1.3.7
56+
requests==2.12.4
57+
six==1.10.0
58+
pytz==2016.10
59+
optional: numpy==1.11.3
60+
optional: ipython[all]==5.1.0
61+
optional: pandas==0.19.2
62+
optional: scipy==0.18.1
63+
64+
; CORE ENVIRONMENTS
65+
[testenv:py27-core]
66+
basepython={env:PLOTLY_TOX_PYTHON_27:}
67+
commands=
68+
python --version
69+
nosetests {posargs} -x plotly/tests/test_core
70+
71+
[testenv:py33-core]
72+
basepython={env:PLOTLY_TOX_PYTHON_33:}
73+
commands=
74+
python --version
75+
nosetests {posargs} -x plotly/tests/test_core
76+
77+
[testenv:py34-core]
78+
basepython={env:PLOTLY_TOX_PYTHON_34:}
79+
commands=
80+
python --version
81+
nosetests {posargs} -x plotly/tests/test_core
82+
83+
[testenv:py35-core]
84+
basepython={env:PLOTLY_TOX_PYTHON_35:}
85+
commands=
86+
python --version
87+
nosetests {posargs} -x plotly/tests/test_core
88+
89+
; OPTIONAL ENVIRONMENTS
90+
[testenv:py27-optional]
91+
basepython={env:PLOTLY_TOX_PYTHON_27:}
92+
commands=
93+
python --version
94+
; Do some coverage reporting. No need to do this for all environments.
95+
mkdir -p {envbindir}/../../coverage-reports/{envname}
96+
coverage erase
97+
coverage run --include="*/plotly/*" --omit="*/tests*" {envbindir}/nosetests {posargs} -x plotly/tests
98+
coverage html -d "{envbindir}/../../coverage-reports/{envname}" --title={envname}
99+
100+
[testenv:py34-optional]
101+
basepython={env:PLOTLY_TOX_PYTHON_34:}
102+
commands=
103+
python --version
104+
nosetests {posargs} -x plotly/tests
105+
106+
[testenv:py35-optional]
107+
basepython={env:PLOTLY_TOX_PYTHON_35:}
108+
commands=
109+
python --version
110+
nosetests {posargs} -x plotly/tests

0 commit comments

Comments
 (0)