Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: autotest.py

Issue 29350236: Issue 4373 - Made jshydra compatible with Python 3 (Closed)
Patch Set: Use urllib2, removed redundant future import, added option to test without caching Created Aug. 30, 2016, 11:33 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « abp_rewrite.py ('k') | tox.ini » ('j') | utils.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python
2 # coding: utf-8
3
4 # This Source Code is subject to the terms of the Mozilla Public License 1 # This Source Code is subject to the terms of the Mozilla Public License
5 # version 2.0 (the "License"). You can obtain a copy of the License at 2 # version 2.0 (the "License"). You can obtain a copy of the License at
6 # http://mozilla.org/MPL/2.0/. 3 # http://mozilla.org/MPL/2.0/.
7 4
5 from __future__ import print_function
6
8 import sys 7 import sys
9 import os 8 import os
10 import subprocess
11 import re 9 import re
12 import difflib 10 import difflib
13 import utils 11
12 import abp_rewrite
14 13
15 14
16 def run_tests(): 15 def run_tests():
17 application = utils.ensureJSShell() 16 testDir = os.path.join(os.path.dirname(__file__), 'autotest')
18 env = { 17 succeed = True
19 'LD_LIBRARY_PATH': os.path.relpath(os.path.dirname(application)),
20 }
21 18
22 baseDir = os.path.dirname(utils.__file__)
23 testDir = os.path.join(baseDir, 'autotest')
24 for file in os.listdir(testDir): 19 for file in os.listdir(testDir):
25 if not re.search(r'^test_.*\.js$', file): 20 if not re.search(r'^test_.*\.js$', file):
26 continue 21 continue
27 22
28 file = os.path.join(testDir, file) 23 file = os.path.join(testDir, file)
29 handle = open(file, 'r') 24 handle = open(file, 'r')
30 name = None 25 name = None
31 arguments = None 26 arguments = None
32 for line in handle: 27 for line in handle:
33 match = re.search(r'^//\s*([A-Za-z]+):\s*(.*?)\s*$', line) 28 match = re.search(r'^//\s*([A-Za-z]+):\s*(.*?)\s*$', line)
34 if match and match.group(1).lower() == 'name': 29 if match and match.group(1).lower() == 'name':
35 name = match.group(2) 30 name = match.group(2)
36 elif match and match.group(1).lower() == 'arguments': 31 elif match and match.group(1).lower() == 'arguments':
37 arguments = match.group(2).split(' ') 32 arguments = match.group(2).split(' ')
38 handle.close() 33 handle.close()
39 34
40 if arguments == None: 35 if arguments == None:
41 continue 36 continue
42 37
43 command = [application, os.path.join(baseDir, 'jshydra.js'), file] + arg uments 38 output = abp_rewrite.rewrite_js(arguments, file)
44 out = subprocess.check_output(command, stderr=subprocess.STDOUT, env=env ).replace('\r', '') 39 expected = open(file + '.expected', 'rU').read()
45 expected = open(file + '.expected', 'r').read().replace('\r', '') 40 if output == expected:
46 if out == expected: 41 print(name + ' passed')
47 print '%s passed' % name
48 else: 42 else:
49 print '%s failed! Log:' % name 43 succeed = False
50 for line in difflib.unified_diff(expected.split('\n'), out.split('\n '), fromfile=file + '.expected', tofile=file + '.output'): 44 print(name + ' failed! Log:')
51 print line 45 for line in difflib.unified_diff(expected.splitlines(),
52 print 46 output.splitlines(),
47 fromfile=file + '.expected',
48 tofile=file + '.output'):
49 print(line)
50 print()
51
52 return succeed
53 53
54 if __name__ == '__main__': 54 if __name__ == '__main__':
55 run_tests() 55 sys.exit(not run_tests())
OLDNEW
« no previous file with comments | « abp_rewrite.py ('k') | tox.ini » ('j') | utils.py » ('J')

Powered by Google App Engine
This is Rietveld