source: pyenvjasmine/pyenvjasmine/tests/test_runner.py@ 31:d66aca501fe9

Last change on this file since 31:d66aca501fe9 was 31:d66aca501fe9, checked in by Borja Lopez <borja@…>, 6 years ago

Extended asserts on a couple of tests with js test failures
(asserting that the js test run failed + how many tests failed)

File size: 3.1 KB
Line 
1import os
2import pytest
3
4from pyenvjasmine.runner import Runner, get_environment
5
6
7class TestsRunner(object):
8
9 def test_runner_defaults(self):
10 """
11 Test the runner, using default values (which wil run the demo specs)
12 """
13 jstests = Runner()
14 success, stdout = jstests.run()
15 assert success
16 assert 'Failed: 0' in stdout
17 assert 'Passed: 5' in stdout
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')
27 jstests = Runner(
28 rootdir=envjasmine_dir,
29 testdir=sample,
30 configfile=conf_file,
31 )
32 success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js')
33 lines = stdout.splitlines()
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
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')
48 jstests = Runner(
49 rootdir=envjasmine_dir,
50 testdir=sample,
51 browser_configfile=browser_conf_file
52 )
53 expected = jstests.create_testRunnerHtml()
54 success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js')
55 assert not success
56 assert 'Failed: 2' in stdout
57 with open("browser.runner.html",'r') as file:
58 actual = file.read()
59 assert expected == actual
60
61 def test_runner_with_browser_configfile(self):
62 """
63 Test the runner, giving it some parameters incl the browser config file
64 """
65 here = os.path.dirname(__file__)
66 sample = os.path.join(here, 'sample')
67 browser_conf_file = os.path.join(sample, 'browser.configfile.js')
68 envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
69 jstests = Runner(
70 rootdir=envjasmine_dir,
71 testdir=sample,
72 browser_configfile=browser_conf_file
73 )
74 success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js')
75 assert not success
76 assert 'Failed: 2' in stdout
77
78 def test_get_environment(self):
79 """
80 Testing the OS specific code
81 Could not figure out how to do this using mock,
82 so monkey patching the old way.
83 """
84 old_os_name = os.name
85 try:
86 os.name = 'nt'
87 res = get_environment()
88 assert res == '--environment=WIN'
89 os.name = 'posix'
90 res = get_environment()
91 assert res == '--environment=UNIX'
92 finally:
93 os.name = old_os_name
Note: See TracBrowser for help on using the repository browser.