[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
|
---|
[30] | 16 | assert 'Failed: 0' in stdout
|
---|
| 17 | assert 'Passed: 5' in stdout
|
---|
[0] | 18 |
|
---|
| 19 | def test_runner_params(self):
|
---|
| 20 | """
|
---|
| 21 | Test the runner, giving it some parameters
|
---|
| 22 | """
|
---|
| 23 | here = os.path.dirname(__file__)
|
---|
| 24 | sample = os.path.join(here, 'sample')
|
---|
| 25 | conf_file = os.path.join(sample, 'configfile.js')
|
---|
| 26 | envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
|
---|
[24] | 27 | jstests = Runner(
|
---|
[0] | 28 | rootdir=envjasmine_dir,
|
---|
| 29 | testdir=sample,
|
---|
| 30 | configfile=conf_file,
|
---|
| 31 | )
|
---|
[26] | 32 | success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js')
|
---|
| 33 | lines = stdout.splitlines()
|
---|
[30] | 34 | assert lines[0].endswith('specs/test_demo.spec.js')
|
---|
| 35 | assert lines[1].startswith('[ Envjs/1.6 (Rhino;')
|
---|
| 36 | assert 'Passed: 4' in lines
|
---|
| 37 | assert 'Failed: 0' in lines
|
---|
| 38 | assert 'Total : 4' in lines
|
---|
[0] | 39 |
|
---|
| 40 | def test_write_browser_htmlfile_markup_is_correct(self):
|
---|
| 41 | """
|
---|
| 42 | Test the created markup
|
---|
| 43 | """
|
---|
| 44 | here = os.path.dirname(__file__)
|
---|
| 45 | sample = os.path.join(here, 'sample')
|
---|
| 46 | browser_conf_file = os.path.join(sample, 'browser.configfile.js')
|
---|
| 47 | envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
|
---|
[24] | 48 | jstests = Runner(
|
---|
[0] | 49 | rootdir=envjasmine_dir,
|
---|
| 50 | testdir=sample,
|
---|
| 51 | browser_configfile=browser_conf_file
|
---|
| 52 | )
|
---|
| 53 | expected = jstests.create_testRunnerHtml()
|
---|
| 54 | jstests.run(spec='tests/specs/test_demo.spec.js')
|
---|
| 55 | with open("browser.runner.html",'r') as file:
|
---|
| 56 | actual = file.read()
|
---|
[26] | 57 | assert expected == actual
|
---|
[10] | 58 |
|
---|
[0] | 59 | def test_runner_with_browser_configfile(self):
|
---|
| 60 | """
|
---|
| 61 | Test the runner, giving it some parameters incl the browser config file
|
---|
| 62 | """
|
---|
| 63 | here = os.path.dirname(__file__)
|
---|
| 64 | sample = os.path.join(here, 'sample')
|
---|
| 65 | browser_conf_file = os.path.join(sample, 'browser.configfile.js')
|
---|
| 66 | envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
|
---|
[24] | 67 | jstests = Runner(
|
---|
[0] | 68 | rootdir=envjasmine_dir,
|
---|
| 69 | testdir=sample,
|
---|
| 70 | browser_configfile=browser_conf_file
|
---|
| 71 | )
|
---|
[26] | 72 | success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js')
|
---|
| 73 | assert not success
|
---|
[0] | 74 |
|
---|
| 75 | def test_get_environment(self):
|
---|
| 76 | """
|
---|
| 77 | Testing the OS specific code
|
---|
| 78 | Could not figure out how to do this using mock,
|
---|
| 79 | so monkey patching the old way.
|
---|
| 80 | """
|
---|
| 81 | old_os_name = os.name
|
---|
| 82 | try:
|
---|
| 83 | os.name = 'nt'
|
---|
| 84 | res = get_environment()
|
---|
[26] | 85 | assert res == '--environment=WIN'
|
---|
[0] | 86 | os.name = 'posix'
|
---|
| 87 | res = get_environment()
|
---|
[26] | 88 | assert res == '--environment=UNIX'
|
---|
[0] | 89 | finally:
|
---|
| 90 | os.name = old_os_name
|
---|