Changeset 12:b385d1bc24d6 in pyenvjasmine
- Timestamp:
- Apr 24, 2015, 8:47:01 AM (10 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- pyenvjasmine
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pyenvjasmine/runner.py
r0 r12 7 7 Get the environment parameter, depending on OS (Win/Unix). 8 8 """ 9 if os.name == 'nt': # not tested!9 if os.name == 'nt': # not tested! 10 10 environment = '--environment=WIN' 11 11 else: … … 23 23 24 24 def __init__(self, rootdir=None, testdir=None, configfile=None, 25 25 browser_configfile=None): 26 26 """ 27 27 Set up paths, by default everything is … … 39 39 the tests in browser. 40 40 """ 41 if rootdir is None: 42 here = os.path.dirname(__file__) 43 rootdir = os.path.join(here, 'envjasmine') 44 if testdir is None: 45 testdir = rootdir 46 self.testdir = testdir 47 self.rootdir = rootdir 41 here = os.path.dirname(__file__) 42 self.libdir = here 43 self.rootdir = rootdir or os.path.join(here, 'envjasmine') 44 self.testdir = testdir or self.rootdir 48 45 self.configfile = configfile 49 46 self.browser_configfile = browser_configfile 47 self.runner_html = os.path.join(here, 'runner.html') 50 48 51 49 def run(self, spec=None, capture_output=True): … … 56 54 """ 57 55 environment = get_environment() 58 rhino_path = os.path.join(self.rootdir, 59 'lib', 'rhino', 'js.jar') 60 envjasmine_js_path = os.path.join(self.rootdir, 61 'lib', 'envjasmine.js') 56 rhino_path = os.path.join(self.rootdir, 'lib', 'rhino', 'js.jar') 57 envjasmine_js_path = os.path.join(self.rootdir, 'lib', 'envjasmine.js') 62 58 rootdir_param = '--rootDir=%s' % self.rootdir 63 59 testdir_param = '--testDir=%s' % self.testdir … … 65 61 self.write_browser_htmlfile() 66 62 67 command = ['java', '-Duser.timezone=US/Eastern', 68 '-Dfile.encoding=utf-8', '-jar', rhino_path, 69 envjasmine_js_path, 70 '--disableColor', 71 environment, rootdir_param, testdir_param 72 ] 63 command = [ 64 'java', 65 '-Duser.timezone=US/Eastern', 66 '-Dfile.encoding=utf-8', 67 '-jar', 68 rhino_path, 69 envjasmine_js_path, 70 '--disableColor', 71 environment, 72 rootdir_param, 73 testdir_param 74 ] 75 73 76 if self.configfile and os.path.exists(self.configfile): 74 77 command.append('--configFile=%s' % self.configfile) 78 75 79 # if we were asked to test only some of the spec files, 76 80 # addd them to the command line: … … 79 83 spec = [spec] 80 84 command.extend(spec) 85 81 86 shell = False 87 stdout = None 88 stderr = None 82 89 if capture_output: 90 # override if we want to capture the output of the test run 83 91 stdout = subprocess.PIPE 84 92 stderr = subprocess.PIPE 85 else: 86 stdout = None 87 stderr = None 88 p = subprocess.Popen(command, shell=shell, 89 stdout=stdout, stderr=stderr) 93 94 p = subprocess.Popen(command, shell=shell, stdout=stdout, 95 stderr=stderr) 90 96 (res, stderr) = p.communicate() 91 97 return res … … 93 99 def write_browser_htmlfile(self): 94 100 markup = self.create_testRunnerHtml() 95 with open("browser.runner.html", 'w') as file:101 with open("browser.runner.html", 'w') as file: 96 102 file.write(markup) 97 103 98 104 def create_testRunnerHtml(self): 99 return """ 100 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 101 "http://www.w3.org/TR/html4/loose.dtd"> 102 <html> 103 <head> 104 <title></title> 105 <link rel="stylesheet" type="text/css" href="file:///%(libDir)s/envjasmine/lib/jasmine/jasmine.css"> 106 107 <script type="text/javascript" src="file:///%(libDir)s/envjasmine/lib/jasmine/jasmine.js"></script> 108 <script type="text/javascript" src="file:///%(libDir)s/envjasmine/lib/jasmine/jasmine-html.js"></script> 109 <script type="text/javascript" src="file:///%(libDir)s/envjasmine/lib/jasmine-ajax/mock-ajax.js"></script> 110 <script type="text/javascript" src="file:///%(libDir)s/envjasmine/lib/jasmine-ajax/spec-helper.js"></script> 111 <script type="text/javascript" src="file:///%(libDir)s/envjasmine/lib/jasmine-jquery/jasmine-jquery.js"></script> 112 113 <script type="text/javascript" src="browser.runner.js"></script> 114 <script type="text/javascript"> 115 (function () { 116 "use strict"; 117 var jasmineEnv = jasmine.getEnv(); 118 jasmineEnv.updateInterval = 1000; 119 120 var trivialReporter = new jasmine.TrivialReporter(); 121 jasmineEnv.addReporter(trivialReporter); 122 jasmineEnv.specFilter = function (spec) { 123 return trivialReporter.specFilter(spec); 124 }; 125 126 var currentWindowOnload = window.onload; 127 128 window.onload = function () { 129 if (currentWindowOnload) { 130 currentWindowOnload(); 131 } 132 execJasmine(); 133 }; 134 135 function execJasmine() { 136 jasmineEnv.execute(); 137 } 138 })(); 139 var EnvJasmine = {}; 140 EnvJasmine.jsDir = ""; 141 EnvJasmine.testDir = "%(testDir)s"; 142 EnvJasmine.load = function (path) { 143 appendScript(path); 144 }; 145 EnvJasmine.loadGlobal = function (path) { 146 appendScript(path); 147 }; 148 function appendScript(path){ 149 var script = document.createElement('script'); 150 script.src = path; 151 script.type ='text/javascript'; 152 document.getElementsByTagName('head')[0].appendChild(script); 153 } 154 </script> 155 <script type="text/javascript" src="%(browser_configfile)s"></script> 156 </head> 157 <body> 158 </body> 159 </html> 160 """ %{"libDir": os.path.normpath(os.path.dirname(__file__)), 161 "testDir": os.path.normpath(self.testdir), 162 "browser_configfile": self.browser_configfile} 163 105 with open(self.runner_html, 'r') as runner_html: 106 html = runner_html.read() 107 return html % {"libDir": os.path.normpath(self.libdir), 108 "testDir": os.path.normpath(self.testdir), 109 "browser_configfile": self.browser_configfile}
Note:
See TracChangeset
for help on using the changeset viewer.