1 | import unittest
|
---|
2 | import os
|
---|
3 |
|
---|
4 | from pyenvjasmine.runner import Runner
|
---|
5 |
|
---|
6 |
|
---|
7 | class RunnerTests(unittest.TestCase):
|
---|
8 | def setUp(self):
|
---|
9 | pass
|
---|
10 |
|
---|
11 | def tearDown(self):
|
---|
12 | pass
|
---|
13 |
|
---|
14 | def test_runner_defaults(self):
|
---|
15 | """
|
---|
16 | Test the runner, using default values (which wil run the demo specs)
|
---|
17 | """
|
---|
18 | jstests = Runner()
|
---|
19 | output = jstests.run()
|
---|
20 | # output is the resulting stdout from a subprocess call, which is a
|
---|
21 | # bytes object, hence the b'' for the checks
|
---|
22 | self.assertTrue(b'Failed: 0' in output)
|
---|
23 | self.assertTrue(b'Passed: 5' in output)
|
---|
24 |
|
---|
25 | def test_runner_params(self):
|
---|
26 | """
|
---|
27 | Test the runner, giving it some parameters
|
---|
28 | """
|
---|
29 | here = os.path.dirname(__file__)
|
---|
30 | sample = os.path.join(here, 'sample')
|
---|
31 | conf_file = os.path.join(sample, 'configfile.js')
|
---|
32 | envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
|
---|
33 | jstests = Runner(
|
---|
34 | rootdir=envjasmine_dir,
|
---|
35 | testdir=sample,
|
---|
36 | configfile=conf_file,
|
---|
37 | )
|
---|
38 | output = jstests.run(spec='tests/specs/test_demo.spec.js')
|
---|
39 | lines = output.splitlines()
|
---|
40 | # output is the resulting stdout from a subprocess call, which is a
|
---|
41 | # bytes object, hence the b'' in the endswith/startswith calls
|
---|
42 | self.assertTrue(lines[0].endswith(b'specs/test_demo.spec.js'),
|
---|
43 | "wrong output: %s" % str(output))
|
---|
44 | self.assertTrue(lines[1].startswith(b'[ Envjs/1.6 (Rhino;'),
|
---|
45 | "wrong output: %s" % str(output))
|
---|
46 | self.assertTrue(b'Passed: 4' in lines)
|
---|
47 | self.assertTrue(b'Failed: 0' in lines)
|
---|
48 | self.assertTrue(b'Total : 4' in lines)
|
---|
49 |
|
---|
50 | def test_write_browser_htmlfile_markup_is_correct(self):
|
---|
51 | """
|
---|
52 | Test the created markup
|
---|
53 | """
|
---|
54 | here = os.path.dirname(__file__)
|
---|
55 | sample = os.path.join(here, 'sample')
|
---|
56 | browser_conf_file = os.path.join(sample, 'browser.configfile.js')
|
---|
57 | envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
|
---|
58 | jstests = Runner(
|
---|
59 | rootdir=envjasmine_dir,
|
---|
60 | testdir=sample,
|
---|
61 | browser_configfile=browser_conf_file
|
---|
62 | )
|
---|
63 | expected = jstests.create_testRunnerHtml()
|
---|
64 | jstests.run(spec='tests/specs/test_demo.spec.js')
|
---|
65 | with open("browser.runner.html",'r') as file:
|
---|
66 | actual = file.read()
|
---|
67 | self.assertEqual(expected, actual)
|
---|
68 |
|
---|
69 | def test_runner_with_browser_configfile(self):
|
---|
70 | """
|
---|
71 | Test the runner, giving it some parameters incl the browser config file
|
---|
72 | """
|
---|
73 | here = os.path.dirname(__file__)
|
---|
74 | sample = os.path.join(here, 'sample')
|
---|
75 | browser_conf_file = os.path.join(sample, 'browser.configfile.js')
|
---|
76 | envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
|
---|
77 | jstests = Runner(
|
---|
78 | rootdir=envjasmine_dir,
|
---|
79 | testdir=sample,
|
---|
80 | browser_configfile=browser_conf_file
|
---|
81 | )
|
---|
82 | jstests.run(spec='tests/specs/test_demo.spec.js')
|
---|
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 | from pyenvjasmine.runner import get_environment
|
---|
91 | import os
|
---|
92 | old_os_name = os.name
|
---|
93 | try:
|
---|
94 | os.name = 'nt'
|
---|
95 | res = get_environment()
|
---|
96 | self.assertEqual(res, '--environment=WIN')
|
---|
97 | os.name = 'posix'
|
---|
98 | res = get_environment()
|
---|
99 | self.assertEqual(res, '--environment=UNIX')
|
---|
100 | finally:
|
---|
101 | os.name = old_os_name
|
---|
102 |
|
---|
103 | def test_not_capture_output(self):
|
---|
104 | """
|
---|
105 | Running a test without capturing output
|
---|
106 | """
|
---|
107 | jstests = Runner()
|
---|
108 | output = jstests.run(capture_output=False)
|
---|
109 | self.assertEqual(output, None)
|
---|