diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py index 280b70b11..2224d2e05 100644 --- a/jenkins_jobs/builder.py +++ b/jenkins_jobs/builder.py @@ -616,7 +616,7 @@ class CacheStorage(object): if flush or not os.path.isfile(self.cachefilename): self.data = {} else: - with file(self.cachefilename, 'r') as yfile: + with open(self.cachefilename, 'r') as yfile: self.data = yaml.load(yfile) logger.debug("Using cache: '{0}'".format(self.cachefilename)) diff --git a/tests/cachestorage/test_cachestorage.py b/tests/cachestorage/test_cachestorage.py index 773a90e1f..154976181 100644 --- a/tests/cachestorage/test_cachestorage.py +++ b/tests/cachestorage/test_cachestorage.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +import os import testtools import jenkins_jobs @@ -32,3 +33,14 @@ class TestCaseCacheStorage(testtools.TestCase): with mock.patch('os.path.isfile', return_value=False): jenkins_jobs.builder.CacheStorage("dummy") save_mock.assert_called_once_with() + + @mock.patch('jenkins_jobs.builder.CacheStorage.get_cache_dir', + lambda x: '/bad/file') + def test_cache_file(self): + """ + Test providing a cachefile. + """ + test_file = os.path.abspath(__file__) + with mock.patch('os.path.join', return_value=test_file): + with mock.patch('yaml.load'): + jenkins_jobs.builder.CacheStorage("dummy").data = None