Changeset 26:14c16e5cbe03 in pyenvjasmine
- Timestamp:
- Jan 18, 2018, 12:22:26 PM (7 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 3 added
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
README.rst
r24 r26 38 38 want to test), install pyenvjasmine and then run:: 39 39 40 nosetests --cover-package=pyenvjasmine --cover-erase \ 41 --with-coverage --with-doctest $* 42 43 .. note:: 44 45 If you have installed pyenvjasmine in *development mode*, you can simply 46 run:: 47 48 nosetests -c nose.cfg 49 50 to run the tests from within the pyenvjasmine sources directory. 40 py.test 51 41 52 42 … … 61 51 from the js tests on the console. Something like this:: 62 52 63 import unittest53 import pytest 64 54 from pyenvjasmine.runner import Runner 65 55 66 class JavaScriptTests(unittest.TestCase):56 class TestJavaScript(object): 67 57 def test_my_javascript(self): 68 58 runner = Runner( 69 59 testdir='/path/to/my/testdir', 70 60 configfile='relative/path/to/configfile') 71 runner.run(capture_output=False) 72 73 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:: 77 78 import unittest 79 from pyenvjasmine.runner import Runner 80 81 class JavaScriptTests(unittest.TestCase): 82 def test_my_javascript_no_output(self): 83 runner = Runner( 84 testdir='/path/to/my/testdir', 85 configfile='relative/path/to/configfile') 86 res = runner.run(capture_output=True) 87 lines = res.splitlines() 88 self.assertTrue('Failed: 0' in lines) 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 89 68 90 69 -
pyenvjasmine/tests/test_runner.py
r24 r26 1 import unittest2 1 import os 2 import pytest 3 3 4 from pyenvjasmine.runner import Runner 4 from pyenvjasmine.runner import Runner, get_environment 5 5 6 6 7 class RunnerTests(unittest.TestCase): 8 def setUp(self): 9 pass 10 11 def tearDown(self): 12 pass 7 class TestsRunner(object): 13 8 14 9 def test_runner_defaults(self): … … 17 12 """ 18 13 jstests = Runner() 19 output = jstests.run() 14 success, stdout = jstests.run() 15 assert success 20 16 # output is the resulting stdout from a subprocess call, which is a 21 17 # bytes object, hence the b'' for the checks 22 self.assertTrue(b'Failed: 0' in output)23 self.assertTrue(b'Passed: 5' in output)18 assert b'Failed: 0' in stdout 19 assert b'Passed: 5' in stdout 24 20 25 21 def test_runner_params(self): … … 36 32 configfile=conf_file, 37 33 ) 38 output = jstests.run(spec='tests/specs/test_demo.spec.js')39 lines = output.splitlines()34 success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js') 35 lines = stdout.splitlines() 40 36 # output is the resulting stdout from a subprocess call, which is a 41 37 # bytes object, hence the b'' in the endswith/startswith calls 42 self.assertTrue(lines[0].endswith(b'specs/test_demo.spec.js'), 43 "wrong output: %s" % str(output)) 44 self.assertTrue(lines[1].startswith(b'[ Envjs/1.6 (Rhino;'), 45 "wrong output: %s" % str(output)) 46 self.assertTrue(b'Passed: 4' in lines) 47 self.assertTrue(b'Failed: 0' in lines) 48 self.assertTrue(b'Total : 4' in lines) 38 assert lines[0].endswith(b'specs/test_demo.spec.js') 39 assert lines[1].startswith(b'[ Envjs/1.6 (Rhino;') 40 assert b'Passed: 4' in lines 41 assert b'Failed: 0' in lines 42 assert b'Total : 4' in lines 49 43 50 44 def test_write_browser_htmlfile_markup_is_correct(self): … … 65 59 with open("browser.runner.html",'r') as file: 66 60 actual = file.read() 67 self.assertEqual(expected, actual)61 assert expected == actual 68 62 69 63 def test_runner_with_browser_configfile(self): … … 80 74 browser_configfile=browser_conf_file 81 75 ) 82 jstests.run(spec='tests/specs/test_demo.spec.js') 76 success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js') 77 assert not success 83 78 84 79 def test_get_environment(self): … … 88 83 so monkey patching the old way. 89 84 """ 90 from pyenvjasmine.runner import get_environment91 import os92 85 old_os_name = os.name 93 86 try: 94 87 os.name = 'nt' 95 88 res = get_environment() 96 self.assertEqual(res, '--environment=WIN')89 assert res == '--environment=WIN' 97 90 os.name = 'posix' 98 91 res = get_environment() 99 self.assertEqual(res, '--environment=UNIX')92 assert res == '--environment=UNIX' 100 93 finally: 101 94 os.name = old_os_name 102 103 def test_not_capture_output(self):104 """105 Running a test without capturing output106 """107 jstests = Runner()108 output = jstests.run(capture_output=False)109 self.assertEqual(output, None) -
setup.py
r24 r26 5 5 6 6 requires = [ 7 'nose', 8 'coverage' 7 'coverage', 8 'pytest', 9 'pytest-cov' 9 10 ] 10 11
Note:
See TracChangeset
for help on using the changeset viewer.