[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 |
|
---|
| 14 | You can install pyenvjasmine using pip_ or easy_install_::
|
---|
| 15 |
|
---|
| 16 | pip install pyenvjasmine
|
---|
| 17 |
|
---|
| 18 | ::
|
---|
| 19 |
|
---|
| 20 | easy_install pyenvjasmine
|
---|
| 21 |
|
---|
| 22 | Or you can grab the latest sources and install it from there::
|
---|
| 23 |
|
---|
| 24 | python setup.py install
|
---|
| 25 |
|
---|
| 26 | Also, you can use it directly from the sources directory, in *development mode*
|
---|
| 27 | (useful if you want to contribute to the project)::
|
---|
| 28 |
|
---|
| 29 | python setup.py develop
|
---|
| 30 |
|
---|
| 31 | .. note::
|
---|
| 32 |
|
---|
| 33 | More about the *development mode* here:
|
---|
| 34 |
|
---|
| 35 | https://packaging.python.org/en/latest/distributing.html#working-in-development-mode
|
---|
[0] | 36 |
|
---|
| 37 |
|
---|
| 38 | Running the tests of this python module:
|
---|
| 39 | ----------------------------------------
|
---|
| 40 |
|
---|
| 41 | To run the tests on this code here (as opposed to *your* JavaScript
|
---|
| 42 | code you want to test), install this into a virtualenv, install
|
---|
| 43 | nose and maybe coverage in that virtualenv and then run::
|
---|
| 44 |
|
---|
| 45 | nosetests --cover-package=pyenvjasmine --cover-erase \
|
---|
| 46 | --with-coverage --with-doctest $*
|
---|
| 47 |
|
---|
[8] | 48 | .. note::
|
---|
| 49 |
|
---|
| 50 | If you have installed pyenvjasmine in *development mode*, you can simply
|
---|
| 51 | run::
|
---|
| 52 |
|
---|
| 53 | nosetests
|
---|
| 54 |
|
---|
| 55 | to run the tests.
|
---|
| 56 |
|
---|
[0] | 57 |
|
---|
| 58 | Run your own tests
|
---|
| 59 | ------------------
|
---|
| 60 |
|
---|
| 61 | The easiest way is to put your "specs" (JavaScript tests) into
|
---|
| 62 | some directory in your code, then in your python tests, add a new
|
---|
| 63 | TestCase with just one test that runs all your JavaScript tests.
|
---|
| 64 |
|
---|
| 65 | The simplest solution is to set capture_output to False, so you see
|
---|
| 66 | the output from the js tests on the console. Something like this::
|
---|
| 67 |
|
---|
| 68 | import unittest
|
---|
| 69 | from pyenvjasmine.runner import TestRunner
|
---|
| 70 |
|
---|
| 71 | class JavaScriptTests(unittest.TestCase):
|
---|
| 72 | def test_my_javascript(self):
|
---|
| 73 | runner = TestRunner(
|
---|
| 74 | testdir='/path/to/my/testdir',
|
---|
| 75 | configfile='relative/path/to/configfile')
|
---|
| 76 | runner.run(capture_output=False)
|
---|
| 77 |
|
---|
| 78 |
|
---|
| 79 | If you want a more integrated
|
---|
| 80 | test control, you could set capture_output to True, then parse the test
|
---|
| 81 | output that is returned from the run() method, with something like this::
|
---|
| 82 |
|
---|
| 83 | def test_my_javascript_no_output(self):
|
---|
| 84 | runner = TestRunner(
|
---|
| 85 | testdir='/path/to/my/testdir',
|
---|
| 86 | configfile='relative/path/to/configfile')
|
---|
| 87 | res = runner.run(capture_output=True)
|
---|
| 88 | lines = res.splitlines()
|
---|
| 89 | self.assertTrue('Failed: 0' in lines)
|
---|
| 90 |
|
---|
[8] | 91 |
|
---|
| 92 | .. _envjasmine : https://github.com/trevmex/EnvJasmine
|
---|
| 93 | .. _pip: http://www.pip-installer.org/en/latest/index.html
|
---|
| 94 | .. _easy_install: http://peak.telecommunity.com/DevCenter/EasyInstall
|
---|