1 | import os
|
---|
2 | import pytest
|
---|
3 |
|
---|
4 | from pyenvjasmine.runner import Runner, get_environment
|
---|
5 |
|
---|
6 |
|
---|
7 | class 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 | jstests.run(spec='tests/specs/test_demo.spec.js')
|
---|
55 | with open("browser.runner.html",'r') as file:
|
---|
56 | actual = file.read()
|
---|
57 | assert expected == actual
|
---|
58 |
|
---|
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')
|
---|
67 | jstests = Runner(
|
---|
68 | rootdir=envjasmine_dir,
|
---|
69 | testdir=sample,
|
---|
70 | browser_configfile=browser_conf_file
|
---|
71 | )
|
---|
72 | success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js')
|
---|
73 | assert not success
|
---|
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()
|
---|
85 | assert res == '--environment=WIN'
|
---|
86 | os.name = 'posix'
|
---|
87 | res = get_environment()
|
---|
88 | assert res == '--environment=UNIX'
|
---|
89 | finally:
|
---|
90 | os.name = old_os_name
|
---|