@@ -91,60 +91,74 @@ def test_open_for_write(self):
9191 def test_get_cache_filename (self ):
9292 self .fs .create_dir ('/abspath' )
9393 os .chdir ('/abspath' )
94+ dummy_hash = utils .calculate_hash ("some_tool" , [])
9495 with mock .patch ('os.path.expanduser' , return_value = '/home/user' ):
9596 self .assertEqual (
96- '/home/user/.git-lint/cache/linter1/abspath/bar/file.txt' ,
97- utils ._get_cache_filename ('linter1' , 'bar/file.txt' ))
97+ '/home/user/.git-lint/cache/linter1.%s/abspath/bar/file.txt' %
98+ dummy_hash ,
99+ utils ._get_cache_filename ('linter1' , dummy_hash ,
100+ 'bar/file.txt' ))
98101
99102 self .assertEqual (
100- '/home/user/.git-lint/cache/linter2/abspath/file.txt' ,
101- utils ._get_cache_filename ('linter2' , 'file.txt' ))
103+ '/home/user/.git-lint/cache/linter2.%s/abspath/file.txt' %
104+ dummy_hash ,
105+ utils ._get_cache_filename ('linter2' , dummy_hash , 'file.txt' ))
102106
103107 self .assertEqual (
104- '/home/user/.git-lint/cache/linter3/bar/file.txt' ,
105- utils ._get_cache_filename ('linter3' , '/bar/file.txt' ))
108+ '/home/user/.git-lint/cache/linter3.%s/bar/file.txt' %
109+ dummy_hash ,
110+ utils ._get_cache_filename ('linter3' , dummy_hash ,
111+ '/bar/file.txt' ))
106112
107113 @unittest .skipUnless (sys .version_info >= (3 , 5 ),
108114 'pyfakefs does not support pathlib2. See'
109115 'https://github.com/jmcgeheeiv/pyfakefs/issues/408' )
110116 def test_save_output_in_cache (self ):
117+ dummy_hash = utils .calculate_hash ("some_tool" , [])
111118 output = 'Some content'
112119 with mock .patch (
113120 'gitlint.utils._get_cache_filename' ,
114- return_value = '/cache/filename.txt' ):
115- utils .save_output_in_cache ('linter' , 'filename' , output )
121+ return_value = '/cache/linter.%s/filename.txt' % dummy_hash ):
122+ utils .save_output_in_cache ('linter' , dummy_hash , 'filename' ,
123+ output )
116124
117- with open (utils ._get_cache_filename ('linter' , 'filename' )) as f :
125+ with open (
126+ utils ._get_cache_filename ('linter' , dummy_hash ,
127+ 'filename' )) as f :
118128 self .assertEqual (output , f .read ())
119129
120130 def test_get_output_from_cache_no_cache (self ):
121- cache_filename = '/cache/filename.txt'
131+ dummy_hash = utils .calculate_hash ("some_tool" , [])
132+ cache_filename = '/cache/linter.%s/filename.txt' % dummy_hash
122133 with mock .patch (
123134 'gitlint.utils._get_cache_filename' ,
124135 return_value = cache_filename ):
125136 self .assertIsNone (
126- utils .get_output_from_cache ('linter' , 'filename' ))
137+ utils .get_output_from_cache ('linter' , dummy_hash , 'filename' ))
127138
128139 def test_get_output_from_cache_cache_is_expired (self ):
129- cache_filename = '/cache/filename.txt'
140+ dummy_hash = utils .calculate_hash ("some_tool" , [])
141+ cache_filename = '/cache/linter.%s/filename.txt' % dummy_hash
130142 self .fs .create_file (cache_filename )
131143 self .fs .create_file ('filename' )
132144 with mock .patch (
133145 'gitlint.utils._get_cache_filename' ,
134146 return_value = cache_filename ):
135147 self .assertIsNone (
136- utils .get_output_from_cache ('linter' , 'filename' ))
148+ utils .get_output_from_cache ('linter' , dummy_hash , 'filename' ))
137149
138150 def test_get_output_from_cache_cache_is_valid (self ):
139- cache_filename = '/cache/filename.txt'
151+ dummy_hash = utils .calculate_hash ("some_tool" , [])
152+ cache_filename = '/cache/linter.%s/filename.txt' % dummy_hash
140153 content = 'some_content'
141154 self .fs .create_file ('filename' )
142155 self .fs .create_file (cache_filename , contents = content )
143156 with mock .patch (
144157 'gitlint.utils._get_cache_filename' ,
145158 return_value = cache_filename ):
146- self .assertEqual (content ,
147- utils .get_output_from_cache ('linter' , 'filename' ))
159+ self .assertEqual (
160+ content ,
161+ utils .get_output_from_cache ('linter' , dummy_hash , 'filename' ))
148162
149163 def test_which_absolute_path (self ):
150164 filename = '/foo/bar.sh'
0 commit comments