[0] | 1 | import os
|
---|
[26] | 2 | import pytest
|
---|
[0] | 3 |
|
---|
[26] | 4 | from pyenvjasmine.runner import Runner, get_environment
|
---|
[0] | 5 |
|
---|
| 6 |
|
---|
[26] | 7 | class TestsRunner(object):
|
---|
[0] | 8 |
|
---|
| 9 | def test_runner_defaults(self):
|
---|
| 10 | """
|
---|
| 11 | Test the runner, using default values (which wil run the demo specs)
|
---|
| 12 | """
|
---|
[24] | 13 | jstests = Runner()
|
---|
[26] | 14 | success, stdout = jstests.run()
|
---|
| 15 | assert success
|
---|
[10] | 16 | # output is the resulting stdout from a subprocess call, which is a
|
---|
| 17 | # bytes object, hence the b'' for the checks
|
---|
[26] | 18 | assert b'Failed: 0' in stdout
|
---|
| 19 | assert b'Passed: 5' in stdout
|
---|
[0] | 20 |
|
---|
| 21 | def test_runner_params(self):
|
---|
| 22 | """
|
---|
| 23 | Test the runner, giving it some parameters
|
---|
| 24 | """
|
---|
| 25 | here = os.path.dirname(__file__)
|
---|
| 26 | sample = os.path.join(here, 'sample')
|
---|
| 27 | conf_file = os.path.join(sample, 'configfile.js')
|
---|
| 28 | envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
|
---|
[24] | 29 | jstests = Runner(
|
---|
[0] | 30 | rootdir=envjasmine_dir,
|
---|
| 31 | testdir=sample,
|
---|
| 32 | configfile=conf_file,
|
---|
| 33 | )
|
---|
[26] | 34 | success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js')
|
---|
| 35 | lines = stdout.splitlines()
|
---|
[10] | 36 | # output is the resulting stdout from a subprocess call, which is a
|
---|
| 37 | # bytes object, hence the b'' in the endswith/startswith calls
|
---|
[26] | 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
|
---|
[0] | 43 |
|
---|
| 44 | def test_write_browser_htmlfile_markup_is_correct(self):
|
---|
| 45 | """
|
---|
| 46 | Test the created markup
|
---|
| 47 | """
|
---|
| 48 | here = os.path.dirname(__file__)
|
---|
| 49 | sample = os.path.join(here, 'sample')
|
---|
| 50 | browser_conf_file = os.path.join(sample, 'browser.configfile.js')
|
---|
| 51 | envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
|
---|
[24] | 52 | jstests = Runner(
|
---|
[0] | 53 | rootdir=envjasmine_dir,
|
---|
| 54 | testdir=sample,
|
---|
| 55 | browser_configfile=browser_conf_file
|
---|
| 56 | )
|
---|
| 57 | expected = jstests.create_testRunnerHtml()
|
---|
| 58 | jstests.run(spec='tests/specs/test_demo.spec.js')
|
---|
| 59 | with open("browser.runner.html",'r') as file:
|
---|
| 60 | actual = file.read()
|
---|
[26] | 61 | assert expected == actual
|
---|
[10] | 62 |
|
---|
[0] | 63 | def test_runner_with_browser_configfile(self):
|
---|
| 64 | """
|
---|
| 65 | Test the runner, giving it some parameters incl the browser config file
|
---|
| 66 | """
|
---|
| 67 | here = os.path.dirname(__file__)
|
---|
| 68 | sample = os.path.join(here, 'sample')
|
---|
| 69 | browser_conf_file = os.path.join(sample, 'browser.configfile.js')
|
---|
| 70 | envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
|
---|
[24] | 71 | jstests = Runner(
|
---|
[0] | 72 | rootdir=envjasmine_dir,
|
---|
| 73 | testdir=sample,
|
---|
| 74 | browser_configfile=browser_conf_file
|
---|
| 75 | )
|
---|
[26] | 76 | success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js')
|
---|
| 77 | assert not success
|
---|
[0] | 78 |
|
---|
| 79 | def test_get_environment(self):
|
---|
| 80 | """
|
---|
| 81 | Testing the OS specific code
|
---|
| 82 | Could not figure out how to do this using mock,
|
---|
| 83 | so monkey patching the old way.
|
---|
| 84 | """
|
---|
| 85 | old_os_name = os.name
|
---|
| 86 | try:
|
---|
| 87 | os.name = 'nt'
|
---|
| 88 | res = get_environment()
|
---|
[26] | 89 | assert res == '--environment=WIN'
|
---|
[0] | 90 | os.name = 'posix'
|
---|
| 91 | res = get_environment()
|
---|
[26] | 92 | assert res == '--environment=UNIX'
|
---|
[0] | 93 | finally:
|
---|
| 94 | os.name = old_os_name
|
---|