source: pyenvjasmine/pyenvjasmine/tests/test_runner.py@ 26:14c16e5cbe03

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

Replaced nose with py.test and adapted all existing tests

File size: 3.3 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 # output is the resulting stdout from a subprocess call, which is a
17 # bytes object, hence the b'' for the checks
18 assert b'Failed: 0' in stdout
19 assert b'Passed: 5' in stdout
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')
29 jstests = Runner(
30 rootdir=envjasmine_dir,
31 testdir=sample,
32 configfile=conf_file,
33 )
34 success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js')
35 lines = stdout.splitlines()
36 # output is the resulting stdout from a subprocess call, which is a
37 # bytes object, hence the b'' in the endswith/startswith calls
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
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')
52 jstests = Runner(
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()
61 assert expected == actual
62
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')
71 jstests = Runner(
72 rootdir=envjasmine_dir,
73 testdir=sample,
74 browser_configfile=browser_conf_file
75 )
76 success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js')
77 assert not success
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()
89 assert res == '--environment=WIN'
90 os.name = 'posix'
91 res = get_environment()
92 assert res == '--environment=UNIX'
93 finally:
94 os.name = old_os_name
Note: See TracBrowser for help on using the repository browser.