Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(760)

Side by Side Diff: build/android/gyp/util/md5_check_test.py

Issue 14254005: [Android] Make gyp/apk_install.py resilient to user actions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/android/gyp/util/md5_check.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 4
5 import tempfile 5 import tempfile
6 import unittest 6 import unittest
7 7
8 import md5_check 8 import md5_check
9 9
10 10
11 class TestMd5Check(unittest.TestCase): 11 class TestMd5Check(unittest.TestCase):
12 def testCallAndRecordIfStale(self): 12 def testCallAndRecordIfStale(self):
13 input_strings = ['string1', 'string2'] 13 input_strings = ['string1', 'string2']
14 input_file1 = tempfile.NamedTemporaryFile() 14 input_file1 = tempfile.NamedTemporaryFile()
15 input_file2 = tempfile.NamedTemporaryFile() 15 input_file2 = tempfile.NamedTemporaryFile()
16 file1_contents = 'input file 1' 16 file1_contents = 'input file 1'
17 file2_contents = 'input file 2' 17 file2_contents = 'input file 2'
18 input_file1.write(file1_contents) 18 input_file1.write(file1_contents)
19 input_file1.flush() 19 input_file1.flush()
20 input_file2.write(file2_contents) 20 input_file2.write(file2_contents)
21 input_file2.flush() 21 input_file2.flush()
22 input_files = [input_file1.name, input_file2.name] 22 input_files = [input_file1.name, input_file2.name]
23 23
24 record_path = tempfile.NamedTemporaryFile(suffix='.stamp') 24 record_path = tempfile.NamedTemporaryFile(suffix='.stamp')
25 25
26 def CheckCallAndRecord(should_call, message): 26 def CheckCallAndRecord(should_call, message, force=False):
27 self.called = False 27 self.called = False
28 def MarkCalled(): 28 def MarkCalled():
29 self.called = True 29 self.called = True
30 md5_check.CallAndRecordIfStale( 30 md5_check.CallAndRecordIfStale(
31 MarkCalled, 31 MarkCalled,
32 record_path=record_path.name, 32 record_path=record_path.name,
33 input_paths=input_files, 33 input_paths=input_files,
34 input_strings=input_strings) 34 input_strings=input_strings,
35 force=force)
35 self.failUnlessEqual(should_call, self.called, message) 36 self.failUnlessEqual(should_call, self.called, message)
36 37
37 CheckCallAndRecord(True, 'should call when record doesn\'t exist') 38 CheckCallAndRecord(True, 'should call when record doesn\'t exist')
38 CheckCallAndRecord(False, 'should not call when nothing changed') 39 CheckCallAndRecord(False, 'should not call when nothing changed')
40 CheckCallAndRecord(True, force=True, message='should call when forced')
39 41
40 input_file1.write('some more input') 42 input_file1.write('some more input')
41 input_file1.flush() 43 input_file1.flush()
42 CheckCallAndRecord(True, 'changed input file should trigger call') 44 CheckCallAndRecord(True, 'changed input file should trigger call')
43 45
44 input_files = input_files[::-1] 46 input_files = input_files[::-1]
45 CheckCallAndRecord(False, 'reordering of inputs shouldn\'t trigger call') 47 CheckCallAndRecord(False, 'reordering of inputs shouldn\'t trigger call')
46 48
47 input_files = input_files[:1] 49 input_files = input_files[:1]
48 CheckCallAndRecord(True, 'removing file should trigger call') 50 CheckCallAndRecord(True, 'removing file should trigger call')
49 51
50 input_files.append(input_file2.name) 52 input_files.append(input_file2.name)
51 CheckCallAndRecord(True, 'added input file should trigger call') 53 CheckCallAndRecord(True, 'added input file should trigger call')
52 54
53 input_strings[0] = input_strings[0] + ' a bit longer' 55 input_strings[0] = input_strings[0] + ' a bit longer'
54 CheckCallAndRecord(True, 'changed input string should trigger call') 56 CheckCallAndRecord(True, 'changed input string should trigger call')
55 57
56 input_strings = input_strings[::-1] 58 input_strings = input_strings[::-1]
57 CheckCallAndRecord(True, 'reordering of string inputs should trigger call') 59 CheckCallAndRecord(True, 'reordering of string inputs should trigger call')
58 60
59 input_strings = input_strings[:1] 61 input_strings = input_strings[:1]
60 CheckCallAndRecord(True, 'removing a string should trigger call') 62 CheckCallAndRecord(True, 'removing a string should trigger call')
61 63
62 input_strings.append('a brand new string') 64 input_strings.append('a brand new string')
63 CheckCallAndRecord(True, 'added input string should trigger call') 65 CheckCallAndRecord(True, 'added input string should trigger call')
64 66
65 67
66 if __name__ == '__main__': 68 if __name__ == '__main__':
67 unittest.main() 69 unittest.main()
OLDNEW
« no previous file with comments | « build/android/gyp/util/md5_check.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698