[0] | 1 | Python envjasmine wrapper
|
---|
| 2 | =========================
|
---|
| 3 |
|
---|
| 4 | This is a thin python wrapper around the envjasmine_ JavaScript
|
---|
| 5 | testing framework.
|
---|
| 6 |
|
---|
[8] | 7 |
|
---|
| 8 | .. contents::
|
---|
| 9 |
|
---|
| 10 |
|
---|
| 11 | Installation
|
---|
| 12 | ------------
|
---|
| 13 |
|
---|
[24] | 14 | You can install pyenvjasmine using pip_::
|
---|
[8] | 15 |
|
---|
| 16 | pip install pyenvjasmine
|
---|
| 17 |
|
---|
| 18 | Or you can grab the latest sources and install it from there::
|
---|
| 19 |
|
---|
| 20 | python setup.py install
|
---|
| 21 |
|
---|
| 22 | Also, you can use it directly from the sources directory, in *development mode*
|
---|
| 23 | (useful if you want to contribute to the project)::
|
---|
| 24 |
|
---|
[21] | 25 | pip install -e .
|
---|
[8] | 26 |
|
---|
| 27 | .. note::
|
---|
| 28 |
|
---|
| 29 | More about the *development mode* here:
|
---|
| 30 |
|
---|
| 31 | https://packaging.python.org/en/latest/distributing.html#working-in-development-mode
|
---|
[0] | 32 |
|
---|
| 33 |
|
---|
[11] | 34 | Running pyenvjasmine tests
|
---|
| 35 | --------------------------
|
---|
[0] | 36 |
|
---|
[11] | 37 | To run the tests on this code here (as opposed to *your* JavaScript code you
|
---|
| 38 | want to test), install pyenvjasmine and then run::
|
---|
[0] | 39 |
|
---|
[26] | 40 | py.test
|
---|
[8] | 41 |
|
---|
[0] | 42 |
|
---|
| 43 | Run your own tests
|
---|
| 44 | ------------------
|
---|
| 45 |
|
---|
[11] | 46 | The easiest way is to put your "specs" (JavaScript tests) into some directory
|
---|
| 47 | in your code, then in your python tests, add a new TestCase with just one test
|
---|
| 48 | that runs all your JavaScript tests.
|
---|
[0] | 49 |
|
---|
[11] | 50 | The simplest solution is to set capture_output to False, so you see the output
|
---|
| 51 | from the js tests on the console. Something like this::
|
---|
[0] | 52 |
|
---|
[26] | 53 | import pytest
|
---|
[24] | 54 | from pyenvjasmine.runner import Runner
|
---|
[0] | 55 |
|
---|
[26] | 56 | class TestJavaScript(object):
|
---|
[0] | 57 | def test_my_javascript(self):
|
---|
[24] | 58 | runner = Runner(
|
---|
| 59 | testdir='/path/to/my/testdir',
|
---|
| 60 | configfile='relative/path/to/configfile')
|
---|
[26] | 61 | success, stdout = runner.run()
|
---|
| 62 | # assert on success, will be true if tests passed, False if any
|
---|
| 63 | # test failed
|
---|
| 64 | assert success
|
---|
| 65 | # you can inspect stdout if you want to get more info, but it
|
---|
| 66 | # will be printed to the console stdout anyway
|
---|
| 67 | assert b'Total: 120' in stdout
|
---|
[0] | 68 |
|
---|
[8] | 69 |
|
---|
| 70 | .. _envjasmine : https://github.com/trevmex/EnvJasmine
|
---|
| 71 | .. _pip: http://www.pip-installer.org/en/latest/index.html
|
---|
| 72 | .. _easy_install: http://peak.telecommunity.com/DevCenter/EasyInstall
|
---|