[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 |
|
---|
| 40 | nosetests --cover-package=pyenvjasmine --cover-erase \
|
---|
| 41 | --with-coverage --with-doctest $*
|
---|
| 42 |
|
---|
[8] | 43 | .. note::
|
---|
| 44 |
|
---|
| 45 | If you have installed pyenvjasmine in *development mode*, you can simply
|
---|
| 46 | run::
|
---|
| 47 |
|
---|
[11] | 48 | nosetests -c nose.cfg
|
---|
[8] | 49 |
|
---|
[11] | 50 | to run the tests from within the pyenvjasmine sources directory.
|
---|
[8] | 51 |
|
---|
[0] | 52 |
|
---|
| 53 | Run your own tests
|
---|
| 54 | ------------------
|
---|
| 55 |
|
---|
[11] | 56 | The easiest way is to put your "specs" (JavaScript tests) into some directory
|
---|
| 57 | in your code, then in your python tests, add a new TestCase with just one test
|
---|
| 58 | that runs all your JavaScript tests.
|
---|
[0] | 59 |
|
---|
[11] | 60 | The simplest solution is to set capture_output to False, so you see the output
|
---|
| 61 | from the js tests on the console. Something like this::
|
---|
[0] | 62 |
|
---|
| 63 | import unittest
|
---|
[24] | 64 | from pyenvjasmine.runner import Runner
|
---|
[0] | 65 |
|
---|
| 66 | class JavaScriptTests(unittest.TestCase):
|
---|
| 67 | def test_my_javascript(self):
|
---|
[24] | 68 | runner = Runner(
|
---|
| 69 | testdir='/path/to/my/testdir',
|
---|
| 70 | configfile='relative/path/to/configfile')
|
---|
[0] | 71 | runner.run(capture_output=False)
|
---|
| 72 |
|
---|
| 73 |
|
---|
[11] | 74 | If you want a more integrated test control, you could set capture_output to
|
---|
| 75 | True, then parse the test output that is returned from the run() method, with
|
---|
| 76 | something like this::
|
---|
[0] | 77 |
|
---|
[11] | 78 | import unittest
|
---|
[24] | 79 | from pyenvjasmine.runner import Runner
|
---|
[11] | 80 |
|
---|
| 81 | class JavaScriptTests(unittest.TestCase):
|
---|
[0] | 82 | def test_my_javascript_no_output(self):
|
---|
[24] | 83 | runner = Runner(
|
---|
| 84 | testdir='/path/to/my/testdir',
|
---|
| 85 | configfile='relative/path/to/configfile')
|
---|
[0] | 86 | res = runner.run(capture_output=True)
|
---|
| 87 | lines = res.splitlines()
|
---|
| 88 | self.assertTrue('Failed: 0' in lines)
|
---|
| 89 |
|
---|
[8] | 90 |
|
---|
| 91 | .. _envjasmine : https://github.com/trevmex/EnvJasmine
|
---|
| 92 | .. _pip: http://www.pip-installer.org/en/latest/index.html
|
---|
| 93 | .. _easy_install: http://peak.telecommunity.com/DevCenter/EasyInstall
|
---|