Use open() instead of file()

The later isn't supported in Python3

Change-Id: I44e9e7d21d59a82648a5a78a0ebcae8f0317bb6f
This commit is contained in:
Guido Günther 2015-02-05 21:15:45 +01:00
parent 7447292b57
commit b43eb4ee35
2 changed files with 13 additions and 1 deletions

View File

@ -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))

View File

@ -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