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