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
3 # found in the LICENSE file.
8 import md5_check
# pylint: disable=W0403
11 class TestMd5Check(unittest
.TestCase
):
15 def testCallAndRecordIfStale(self
):
16 input_strings
= ['string1', 'string2']
17 input_file1
= tempfile
.NamedTemporaryFile()
18 input_file2
= tempfile
.NamedTemporaryFile()
19 file1_contents
= 'input file 1'
20 file2_contents
= 'input file 2'
21 input_file1
.write(file1_contents
)
23 input_file2
.write(file2_contents
)
25 input_files
= [input_file1
.name
, input_file2
.name
]
27 record_path
= tempfile
.NamedTemporaryFile(suffix
='.stamp')
29 def CheckCallAndRecord(should_call
, message
, force
=False):
33 md5_check
.CallAndRecordIfStale(
35 record_path
=record_path
.name
,
36 input_paths
=input_files
,
37 input_strings
=input_strings
,
39 self
.failUnlessEqual(should_call
, self
.called
, message
)
41 CheckCallAndRecord(True, 'should call when record doesn\'t exist')
42 CheckCallAndRecord(False, 'should not call when nothing changed')
43 CheckCallAndRecord(True, force
=True, message
='should call when forced')
45 input_file1
.write('some more input')
47 CheckCallAndRecord(True, 'changed input file should trigger call')
49 input_files
= input_files
[::-1]
50 CheckCallAndRecord(False, 'reordering of inputs shouldn\'t trigger call')
52 input_files
= input_files
[:1]
53 CheckCallAndRecord(True, 'removing file should trigger call')
55 input_files
.append(input_file2
.name
)
56 CheckCallAndRecord(True, 'added input file should trigger call')
58 input_strings
[0] = input_strings
[0] + ' a bit longer'
59 CheckCallAndRecord(True, 'changed input string should trigger call')
61 input_strings
= input_strings
[::-1]
62 CheckCallAndRecord(True, 'reordering of string inputs should trigger call')
64 input_strings
= input_strings
[:1]
65 CheckCallAndRecord(True, 'removing a string should trigger call')
67 input_strings
.append('a brand new string')
68 CheckCallAndRecord(True, 'added input string should trigger call')
71 if __name__
== '__main__':