Use open() instead of file()
The later isn't supported in Python3 Change-Id: I44e9e7d21d59a82648a5a78a0ebcae8f0317bb6f
This commit is contained in:
parent
7447292b57
commit
b43eb4ee35
@ -616,7 +616,7 @@ class CacheStorage(object):
|
|||||||
if flush or not os.path.isfile(self.cachefilename):
|
if flush or not os.path.isfile(self.cachefilename):
|
||||||
self.data = {}
|
self.data = {}
|
||||||
else:
|
else:
|
||||||
with file(self.cachefilename, 'r') as yfile:
|
with open(self.cachefilename, 'r') as yfile:
|
||||||
self.data = yaml.load(yfile)
|
self.data = yaml.load(yfile)
|
||||||
logger.debug("Using cache: '{0}'".format(self.cachefilename))
|
logger.debug("Using cache: '{0}'".format(self.cachefilename))
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import os
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
import jenkins_jobs
|
import jenkins_jobs
|
||||||
@ -32,3 +33,14 @@ class TestCaseCacheStorage(testtools.TestCase):
|
|||||||
with mock.patch('os.path.isfile', return_value=False):
|
with mock.patch('os.path.isfile', return_value=False):
|
||||||
jenkins_jobs.builder.CacheStorage("dummy")
|
jenkins_jobs.builder.CacheStorage("dummy")
|
||||||
save_mock.assert_called_once_with()
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user