| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 """Generator script for Web Bluetooth LayoutTests. | 4 """Generator script for Web Bluetooth LayoutTests. |
| 5 | 5 |
| 6 For each script-tests/X.js creates the following test files depending on the | 6 For each script-tests/X.js creates the following test files depending on the |
| 7 contents of X.js | 7 contents of X.js |
| 8 - getPrimaryService/X.html | 8 - getPrimaryService/X.html |
| 9 - getPrimaryServices/X.html | 9 - getPrimaryServices/X.html |
| 10 - getPrimaryServices/X-with-uuid.html | 10 - getPrimaryServices/X-with-uuid.html |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 # Generate Test Files | 89 # Generate Test Files |
| 90 for template in available_templates: | 90 for template in available_templates: |
| 91 # Read template | 91 # Read template |
| 92 template_file_handle = open(template) | 92 template_file_handle = open(template) |
| 93 template_file_data = template_file_handle.read().decode('utf-8') | 93 template_file_data = template_file_handle.read().decode('utf-8') |
| 94 template_file_handle.close() | 94 template_file_handle.close() |
| 95 | 95 |
| 96 template_name = os.path.splitext(os.path.basename(template))[0] | 96 template_name = os.path.splitext(os.path.basename(template))[0] |
| 97 | 97 |
| 98 result = re.search(r'CALLS\(\[(.*?)\]\)', template_file_data, re.MULTILI
NE | 98 # Find function names in multiline pattern: CALLS( [ function_name,funct
ion_name2[UUID] ]) |
| 99 | re.DOTALL) | 99 result = re.search( |
| 100 r'CALLS\(' + # CALLS( |
| 101 r'[^\[]*' + # Any characters not [, allowing for new lines. |
| 102 r'\[' + # [ |
| 103 r'(.*?)' + # group matching: function_name(), function_name2[UUID] |
| 104 r'\]\)', # adjacent closing characters: ]) |
| 105 template_file_data, re.MULTILINE | re.DOTALL) |
| 100 | 106 |
| 101 if result is None: | 107 if result is None: |
| 102 raise Exception('Template must contain \'CALLS\' tokens') | 108 raise Exception('Template must contain \'CALLS\' tokens') |
| 103 | 109 |
| 104 new_test_file_data = base_template_file_data.replace('TEST', | 110 new_test_file_data = base_template_file_data.replace('TEST', |
| 105 template_file_data) | 111 template_file_data) |
| 106 # Replace CALLS([...]) with CALLS so that we don't have to replace the | 112 # Replace CALLS([...]) with CALLS so that we don't have to replace the |
| 107 # CALLS([...]) for every new test file. | 113 # CALLS([...]) for every new test file. |
| 108 new_test_file_data = new_test_file_data.replace(result.group(), 'CALLS') | 114 new_test_file_data = new_test_file_data.replace(result.group(), 'CALLS') |
| 109 | 115 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 139 # Create or open test file | 145 # Create or open test file |
| 140 test_file_handle = open(generated_test.path, 'wb') | 146 test_file_handle = open(generated_test.path, 'wb') |
| 141 | 147 |
| 142 # Write contents | 148 # Write contents |
| 143 test_file_handle.write(generated_test.data.encode('utf-8')) | 149 test_file_handle.write(generated_test.data.encode('utf-8')) |
| 144 test_file_handle.close() | 150 test_file_handle.close() |
| 145 | 151 |
| 146 | 152 |
| 147 if __name__ == '__main__': | 153 if __name__ == '__main__': |
| 148 sys.exit(main()) | 154 sys.exit(main()) |
| OLD | NEW |