source: pyenvjasmine/pyenvjasmine/tests/test_runner.py@ 24:e235afb1bc67

Last change on this file since 24:e235afb1bc67 was 24:e235afb1bc67, checked in by Borja Lopez <borja@…>, 4 years ago

Updated docs and some test files to reflect the change TestRunner/Runner.

Bumped version to 0.1.7

File size: 3.8 KB
Line 
1import unittest
2import os
3
4from pyenvjasmine.runner import Runner
5
6
7class 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)
Note: See TracBrowser for help on using the repository browser.