source: pyenvjasmine/pyenvjasmine/tests/test_runner.py@ 42:a67c2fe2b2aa

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

Fixed typo (enviroment/environment)

File size: 7.8 KB
Line 
1import os
2
3from pyenvjasmine.runner import Runner, get_environment
4
5
6class TestsRunnerRhino(object):
7
8 """
9 Run the full tests using the old rhino+jasmine1 env
10 """
11
12 def test_runner_defaults(self):
13 """
14 Test the runner, using default values (which wil run the demo specs)
15 """
16 jstests = Runner(testing_environment='rhino')
17 success, stdout = jstests.run()
18 assert success
19 assert 'Failed: 0' in stdout
20 assert 'Passed: 5' in stdout
21
22 def test_runner_params(self):
23 """
24 Test the runner, giving it some parameters
25 """
26 here = os.path.dirname(__file__)
27 sample = os.path.join(here, 'sample')
28 conf_file = os.path.join(sample, 'configfile.js')
29 envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
30 jstests = Runner(
31 testing_environment='rhino',
32 rootdir=envjasmine_dir,
33 testdir=sample,
34 configfile=conf_file,
35 )
36 success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js')
37 lines = stdout.splitlines()
38 assert lines[0].endswith('specs/test_demo.spec.js')
39 assert lines[1].startswith('[ Envjs/1.6 (Rhino;')
40 assert 'Passed: 4' in lines
41 assert 'Failed: 0' in lines
42 assert '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 testing_environment='rhino',
54 rootdir=envjasmine_dir,
55 testdir=sample,
56 browser_configfile=browser_conf_file
57 )
58 expected = jstests.create_testRunnerHtml()
59 success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js')
60 assert not success
61 assert 'Failed: 2' in stdout
62 with open("browser.runner.html",'r') as file:
63 actual = file.read()
64 assert expected == actual
65
66 def test_runner_with_browser_configfile(self):
67 """
68 Test the runner, giving it some parameters incl the browser config file
69 """
70 here = os.path.dirname(__file__)
71 sample = os.path.join(here, 'sample')
72 browser_conf_file = os.path.join(sample, 'browser.configfile.js')
73 envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
74 jstests = Runner(
75 testing_environment='rhino',
76 rootdir=envjasmine_dir,
77 testdir=sample,
78 browser_configfile=browser_conf_file
79 )
80 success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js')
81 assert not success
82 assert 'Failed: 2' in stdout
83
84 def test_get_environment(self):
85 """
86 Testing the OS specific code
87 Could not figure out how to do this using mock,
88 so monkey patching the old way.
89 """
90 old_os_name = os.name
91 try:
92 os.name = 'nt'
93 res = get_environment()
94 assert res == '--environment=WIN'
95 os.name = 'posix'
96 res = get_environment()
97 assert res == '--environment=UNIX'
98 finally:
99 os.name = old_os_name
100
101 def test_did_test_pass(self):
102 # there is some coverage done with the previous tests,
103 # but we want to test also the case when a test failed
104 # and it does not appear in the "Failed:" report
105 jstests = Runner(testing_environment='rhino')
106 success = jstests.did_test_pass('')
107 assert not success
108 success = jstests.did_test_pass('some random data '*50)
109 assert not success
110 success = jstests.did_test_pass('some data FAILED some more data')
111 assert not success
112 success = jstests.did_test_pass('some data FAILEDsome more data')
113 assert not success
114 success = jstests.did_test_pass('Failed: 0')
115 assert success
116 success = jstests.did_test_pass('Failed: 0 FAILED')
117 assert not success
118 success = jstests.did_test_pass('FAILEDFailed: 0')
119 assert not success
120 success = jstests.did_test_pass('Failed: 0FAILED')
121 assert not success
122 success = jstests.did_test_pass('Failed: 1')
123 assert not success
124 success = jstests.did_test_pass('Failed: -11')
125 assert not success
126 success = jstests.did_test_pass('Failed: something-not-a-number')
127 assert not success
128
129class TestsRunnerPhantomjs(object):
130
131 """
132 Run the full tests using the phantom+jasmine3 env
133 """
134
135 def test_write_browser_htmlfile_markup_is_correct(self):
136 """
137 Test the created markup
138 The config file doesn't contain the mock files so jasmine tests
139 are expected to fail
140 """
141 here = os.path.dirname(__file__)
142 sample = os.path.join(here, 'sample')
143 browser_conf_file = os.path.join(sample, 'browser.configfile_no_mocks.js')
144 envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
145 jstests = Runner(
146 testing_environment='phantomjs',
147 rootdir=envjasmine_dir,
148 testdir=sample,
149 browser_configfile=browser_conf_file
150 )
151 expected = jstests.create_testRunnerHtml()
152 jstests.write_browser_htmlfile()
153 success, stdout = jstests.run()
154 assert not success
155 assert '2 test(s) FAILED:' in stdout
156 with open("browser.runner.html",'r') as file:
157 actual = file.read()
158 assert expected == actual
159
160 def test_runner_with_browser_configfile(self):
161 """
162 Test the runner, giving it some parameters incl the browser config file
163 The config file contains the mock files so jasmine tests are expected
164 to pass
165 """
166 here = os.path.dirname(__file__)
167 sample = os.path.join(here, 'sample')
168 browser_conf_file = os.path.join(sample, 'browser.configfile.js')
169 envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
170 jstests = Runner(
171 testing_environment='phantomjs',
172 rootdir=envjasmine_dir,
173 testdir=sample,
174 browser_configfile=browser_conf_file
175 )
176 success, stdout = jstests.run()
177 assert success
178 assert '0 failures' in stdout
179
180 def test_did_test_pass(self):
181 # there is some coverage done with the previous tests,
182 # but we want to test also the case when a test failed
183 # and it does not appear in the "Failed:" report
184 here = os.path.dirname(__file__)
185 sample = os.path.join(here, 'sample')
186 browser_conf_file = os.path.join(sample, 'browser.configfile.js')
187
188 jstests = Runner(
189 testing_environment='phantomjs',
190 browser_configfile=browser_conf_file
191 )
192 success = jstests.did_test_pass('')
193 assert not success
194 success = jstests.did_test_pass('some random data '*50)
195 assert not success
196 success = jstests.did_test_pass('some data FAILED some more data')
197 assert not success
198 success = jstests.did_test_pass('some data FAILEDsome more data')
199 assert not success
200 success = jstests.did_test_pass('0 failures')
201 assert success
202 success = jstests.did_test_pass('0 failures FAILED')
203 assert not success
204 success = jstests.did_test_pass('0Failed: failures')
205 assert not success
206 success = jstests.did_test_pass('1 test(s) FAILED:')
207 assert not success
208 success = jstests.did_test_pass('-11 test(s) FAILED:')
209 assert not success
210 success = jstests.did_test_pass('something-not-a-number test(s) FAILED:')
211 assert not success
Note: See TracBrowser for help on using the repository browser.