Replace file with open, which is Python 3 compatible
Change-Id: I471ae9b372f88a508d4654b1a18c6da90397a828
This commit is contained in:
@@ -431,7 +431,7 @@ class OpenStackImagesShell(object):
|
||||
force_auth=True)
|
||||
schema = client.schemas.get("image")
|
||||
|
||||
with file(schema_file_path, 'w') as f:
|
||||
with open(schema_file_path, 'w') as f:
|
||||
f.write(json.dumps(schema.raw()))
|
||||
except Exception as e:
|
||||
#NOTE(esheffield) do nothing here, we'll get a message later
|
||||
|
||||
@@ -29,7 +29,7 @@ def get_image_schema():
|
||||
if IMAGE_SCHEMA is None:
|
||||
schema_path = expanduser("~/.glanceclient/image_schema.json")
|
||||
if os.path.exists(schema_path) and os.path.isfile(schema_path):
|
||||
with file(schema_path, "r") as f:
|
||||
with open(schema_path, "r") as f:
|
||||
schema_raw = f.read()
|
||||
IMAGE_SCHEMA = json.loads(schema_raw)
|
||||
return IMAGE_SCHEMA
|
||||
|
||||
@@ -137,7 +137,7 @@ class ShellCacheSchemaTest(utils.TestCase):
|
||||
|
||||
return Args(args)
|
||||
|
||||
@mock.patch('__builtin__.file', new=mock.mock_open(), create=True)
|
||||
@mock.patch('__builtin__.open', new=mock.mock_open(), create=True)
|
||||
def test_cache_schema_gets_when_not_exists(self):
|
||||
mocked_path_exists_result_lst = [True, False]
|
||||
os.path.exists.side_effect = \
|
||||
@@ -150,12 +150,12 @@ class ShellCacheSchemaTest(utils.TestCase):
|
||||
self.shell._cache_schema(self._make_args(options),
|
||||
home_dir=self.cache_dir)
|
||||
|
||||
self.assertEqual(4, file.mock_calls.__len__())
|
||||
self.assertEqual(mock.call(self.cache_file, 'w'), file.mock_calls[0])
|
||||
self.assertEqual(4, open.mock_calls.__len__())
|
||||
self.assertEqual(mock.call(self.cache_file, 'w'), open.mock_calls[0])
|
||||
self.assertEqual(mock.call().write(json.dumps(self.schema_dict)),
|
||||
file.mock_calls[2])
|
||||
open.mock_calls[2])
|
||||
|
||||
@mock.patch('__builtin__.file', new=mock.mock_open(), create=True)
|
||||
@mock.patch('__builtin__.open', new=mock.mock_open(), create=True)
|
||||
def test_cache_schema_gets_when_forced(self):
|
||||
os.path.exists.return_value = True
|
||||
|
||||
@@ -166,12 +166,12 @@ class ShellCacheSchemaTest(utils.TestCase):
|
||||
self.shell._cache_schema(self._make_args(options),
|
||||
home_dir=self.cache_dir)
|
||||
|
||||
self.assertEqual(4, file.mock_calls.__len__())
|
||||
self.assertEqual(mock.call(self.cache_file, 'w'), file.mock_calls[0])
|
||||
self.assertEqual(4, open.mock_calls.__len__())
|
||||
self.assertEqual(mock.call(self.cache_file, 'w'), open.mock_calls[0])
|
||||
self.assertEqual(mock.call().write(json.dumps(self.schema_dict)),
|
||||
file.mock_calls[2])
|
||||
open.mock_calls[2])
|
||||
|
||||
@mock.patch('__builtin__.file', new=mock.mock_open(), create=True)
|
||||
@mock.patch('__builtin__.open', new=mock.mock_open(), create=True)
|
||||
def test_cache_schema_leaves_when_present_not_forced(self):
|
||||
os.path.exists.return_value = True
|
||||
|
||||
@@ -185,4 +185,4 @@ class ShellCacheSchemaTest(utils.TestCase):
|
||||
os.path.exists.assert_any_call(self.cache_dir)
|
||||
os.path.exists.assert_any_call(self.cache_file)
|
||||
self.assertEqual(2, os.path.exists.call_count)
|
||||
self.assertEqual(0, file.mock_calls.__len__())
|
||||
self.assertEqual(0, open.mock_calls.__len__())
|
||||
|
||||
@@ -120,7 +120,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
|
||||
"""
|
||||
cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
|
||||
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
|
||||
file(cert_file).read())
|
||||
open(cert_file).read())
|
||||
# The expected cert should have CN=0.0.0.0
|
||||
self.assertEqual(cert.get_subject().commonName, '0.0.0.0')
|
||||
try:
|
||||
@@ -135,7 +135,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
|
||||
"""
|
||||
cert_file = os.path.join(TEST_VAR_DIR, 'wildcard-certificate.crt')
|
||||
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
|
||||
file(cert_file).read())
|
||||
open(cert_file).read())
|
||||
# The expected cert should have CN=*.pong.example.com
|
||||
self.assertEqual(cert.get_subject().commonName, '*.pong.example.com')
|
||||
try:
|
||||
@@ -150,7 +150,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
|
||||
"""
|
||||
cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
|
||||
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
|
||||
file(cert_file).read())
|
||||
open(cert_file).read())
|
||||
# The expected cert should have CN=0.0.0.0
|
||||
self.assertEqual(cert.get_subject().commonName, '0.0.0.0')
|
||||
try:
|
||||
@@ -171,7 +171,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
|
||||
"""
|
||||
cert_file = os.path.join(TEST_VAR_DIR, 'wildcard-san-certificate.crt')
|
||||
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
|
||||
file(cert_file).read())
|
||||
open(cert_file).read())
|
||||
# The expected cert should have CN=0.0.0.0
|
||||
self.assertEqual(cert.get_subject().commonName, '0.0.0.0')
|
||||
try:
|
||||
@@ -199,7 +199,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
|
||||
"""
|
||||
cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
|
||||
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
|
||||
file(cert_file).read())
|
||||
open(cert_file).read())
|
||||
# The expected cert should have CN=0.0.0.0
|
||||
self.assertEqual(cert.get_subject().commonName, '0.0.0.0')
|
||||
try:
|
||||
@@ -216,7 +216,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
|
||||
"""
|
||||
cert_file = os.path.join(TEST_VAR_DIR, 'expired-cert.crt')
|
||||
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
|
||||
file(cert_file).read())
|
||||
open(cert_file).read())
|
||||
# The expected expired cert has CN=openstack.example.com
|
||||
self.assertEqual(cert.get_subject().commonName,
|
||||
'openstack.example.com')
|
||||
|
||||
Reference in New Issue
Block a user