2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
7 from caching_rietveld_patcher
import (CachingRietveldPatcher
,
9 from datetime
import datetime
10 from object_store_creator
import ObjectStoreCreator
11 from test_patcher
import TestPatcher
13 _TEST_PATCH_VERSION
= '1'
14 _TEST_PATCH_FILES
= (['add.txt'], ['del.txt'], ['modify.txt'])
17 'modify.txt': 'modify',
20 class FakeDateTime(object):
21 def __init__(self
, time
=datetime
.now()):
27 class CachingRietveldPatcherTest(unittest
.TestCase
):
29 self
._datetime
= FakeDateTime()
30 self
._test
_patcher
= TestPatcher(_TEST_PATCH_VERSION
,
33 self
._patcher
= CachingRietveldPatcher(
35 ObjectStoreCreator(start_empty
=False),
38 def testGetVersion(self
):
40 self
._datetime
.time
+= _VERSION_CACHE_MAXAGE
42 self
._patcher
.GetVersion()
43 count
= self
._test
_patcher
.get_version_count
44 # Should read from cache.
45 self
._patcher
.GetVersion()
46 self
.assertEqual(count
, self
._test
_patcher
.get_version_count
)
48 self
._datetime
.time
+= _VERSION_CACHE_MAXAGE
49 # Should fetch version.
50 self
._patcher
.GetVersion()
51 self
.assertEqual(count
+ 1, self
._test
_patcher
.get_version_count
)
53 def testGetPatchedFiles(self
):
55 self
._patcher
.GetPatchedFiles()
56 count
= self
._test
_patcher
.get_patched_files_count
57 # Should read from cache.
58 self
._patcher
.GetPatchedFiles()
59 self
.assertEqual(count
, self
._test
_patcher
.get_patched_files_count
)
63 self
._patcher
.Apply(['add.txt'], None).Get()
64 count
= self
._test
_patcher
.apply_count
65 # Should read from cache even though it's reading another file.
66 self
._patcher
.Apply(['modify.txt'], None).Get()
67 self
.assertEqual(count
, self
._test
_patcher
.apply_count
)
69 if __name__
== '__main__':