OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """ Output file objects for generator. """ | 7 """ Output file objects for generator. """ |
8 | 8 |
9 import difflib | 9 import difflib |
10 import os | 10 import os |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 76 |
77 # Close the file | 77 # Close the file |
78 def Close(self): | 78 def Close(self): |
79 filename = os.path.realpath(self.filename) | 79 filename = os.path.realpath(self.filename) |
80 self.open = False | 80 self.open = False |
81 outtext = ''.join(self.outlist) | 81 outtext = ''.join(self.outlist) |
82 if not self.always_write: | 82 if not self.always_write: |
83 if os.path.isfile(filename): | 83 if os.path.isfile(filename): |
84 intext = open(filename, 'r').read() | 84 intext = open(filename, 'r').read() |
85 else: | 85 else: |
86 intext = None | 86 intext = '' |
87 | 87 |
88 if IsEquivelent(intext, outtext): | 88 if IsEquivelent(intext, outtext): |
89 if GetOption('verbose'): | 89 if GetOption('verbose'): |
90 InfoOut.Log('Output %s unchanged.' % self.filename) | 90 InfoOut.Log('Output %s unchanged.' % self.filename) |
91 return False | 91 return False |
92 | 92 |
93 if GetOption('diff'): | 93 if GetOption('diff'): |
94 for line in difflib.unified_diff(intext.split('\n'), outtext.split('\n'), | 94 for line in difflib.unified_diff(intext.split('\n'), outtext.split('\n'), |
95 self.filename, 'NEW', n=1, lineterm=''): | 95 self.filename, 'NEW', n=1, lineterm=''): |
96 ErrOut.Log(line) | 96 ErrOut.Log(line) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 errors += TestFile(filename, stringlist, force=False, update=False) | 165 errors += TestFile(filename, stringlist, force=False, update=False) |
166 | 166 |
167 # Test conditionally writing the file updating | 167 # Test conditionally writing the file updating |
168 errors += TestFile(filename, stringlist + ['X'], force=False, update=True) | 168 errors += TestFile(filename, stringlist + ['X'], force=False, update=True) |
169 | 169 |
170 # Clean up file | 170 # Clean up file |
171 os.remove(filename) | 171 os.remove(filename) |
172 if not errors: InfoOut.Log('All tests pass.') | 172 if not errors: InfoOut.Log('All tests pass.') |
173 sys.exit(errors) | 173 sys.exit(errors) |
174 | 174 |
OLD | NEW |