@@ -91,60 +91,65 @@ def test_open_for_write(self):
91
91
def test_get_cache_filename (self ):
92
92
self .fs .create_dir ('/abspath' )
93
93
os .chdir ('/abspath' )
94
+ dummy_hash = utils .calculate_hash ("some_tool" , [])
94
95
with mock .patch ('os.path.expanduser' , return_value = '/home/user' ):
95
96
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' % dummy_hash ,
98
+ utils ._get_cache_filename ('linter1' , dummy_hash , 'bar/file.txt' ))
98
99
99
100
self .assertEqual (
100
- '/home/user/.git-lint/cache/linter2/abspath/file.txt' ,
101
- utils ._get_cache_filename ('linter2' , 'file.txt' ))
101
+ '/home/user/.git-lint/cache/linter2.%s /abspath/file.txt' % dummy_hash ,
102
+ utils ._get_cache_filename ('linter2' , dummy_hash , 'file.txt' ))
102
103
103
104
self .assertEqual (
104
- '/home/user/.git-lint/cache/linter3/bar/file.txt' ,
105
- utils ._get_cache_filename ('linter3' , '/bar/file.txt' ))
105
+ '/home/user/.git-lint/cache/linter3.%s /bar/file.txt' % dummy_hash ,
106
+ utils ._get_cache_filename ('linter3' , dummy_hash , '/bar/file.txt' ))
106
107
107
108
@unittest .skipUnless (sys .version_info >= (3 , 5 ),
108
109
'pyfakefs does not support pathlib2. See'
109
110
'https://github.com/jmcgeheeiv/pyfakefs/issues/408' )
110
111
def test_save_output_in_cache (self ):
112
+ dummy_hash = utils .calculate_hash ("some_tool" , [])
111
113
output = 'Some content'
112
114
with mock .patch (
113
115
'gitlint.utils._get_cache_filename' ,
114
- return_value = '/cache/filename.txt' ):
115
- utils .save_output_in_cache ('linter' , 'filename' , output )
116
+ return_value = '/cache/linter.%s/ filename.txt' % dummy_hash ):
117
+ utils .save_output_in_cache ('linter' , dummy_hash , 'filename' , output )
116
118
117
- with open (utils ._get_cache_filename ('linter' , 'filename' )) as f :
119
+ with open (utils ._get_cache_filename ('linter' , dummy_hash , 'filename' )) as f :
118
120
self .assertEqual (output , f .read ())
119
121
120
122
def test_get_output_from_cache_no_cache (self ):
121
- cache_filename = '/cache/filename.txt'
123
+ dummy_hash = utils .calculate_hash ("some_tool" , [])
124
+ cache_filename = '/cache/linter.%s/filename.txt' % dummy_hash
122
125
with mock .patch (
123
126
'gitlint.utils._get_cache_filename' ,
124
127
return_value = cache_filename ):
125
128
self .assertIsNone (
126
- utils .get_output_from_cache ('linter' , 'filename' ))
129
+ utils .get_output_from_cache ('linter' , dummy_hash , 'filename' ))
127
130
128
131
def test_get_output_from_cache_cache_is_expired (self ):
129
- cache_filename = '/cache/filename.txt'
132
+ dummy_hash = utils .calculate_hash ("some_tool" , [])
133
+ cache_filename = '/cache/linter.%s/filename.txt' % dummy_hash
130
134
self .fs .create_file (cache_filename )
131
135
self .fs .create_file ('filename' )
132
136
with mock .patch (
133
137
'gitlint.utils._get_cache_filename' ,
134
138
return_value = cache_filename ):
135
139
self .assertIsNone (
136
- utils .get_output_from_cache ('linter' , 'filename' ))
140
+ utils .get_output_from_cache ('linter' , dummy_hash , 'filename' ))
137
141
138
142
def test_get_output_from_cache_cache_is_valid (self ):
139
- cache_filename = '/cache/filename.txt'
143
+ dummy_hash = utils .calculate_hash ("some_tool" , [])
144
+ cache_filename = '/cache/linter.%s/filename.txt' % dummy_hash
140
145
content = 'some_content'
141
146
self .fs .create_file ('filename' )
142
147
self .fs .create_file (cache_filename , contents = content )
143
148
with mock .patch (
144
149
'gitlint.utils._get_cache_filename' ,
145
150
return_value = cache_filename ):
146
151
self .assertEqual (content ,
147
- utils .get_output_from_cache ('linter' , 'filename' ))
152
+ utils .get_output_from_cache ('linter' , dummy_hash , 'filename' ))
148
153
149
154
def test_which_absolute_path (self ):
150
155
filename = '/foo/bar.sh'
0 commit comments