aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/client/session_list_devices_test.py
diff options
context:
space:
mode:
authorGravatar Skye Wanderman-Milne <skyewm@google.com>2018-03-30 14:56:08 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-03-30 14:58:45 -0700
commit97731cb122f53552bd15351e046a256f78cca444 (patch)
treedbec22e40bc41f690953b7aad5498516cf457908 /tensorflow/python/client/session_list_devices_test.py
parent15c10899c9c0e1717251b380330cc248b2c76c9c (diff)
Raise exception in SWIG on bad TF_Status from C API.
This change provides an alternative mechanism to tf.raise_exception_on_not_ok_status(), which is inefficient and error-prone (people often use the status multiple times in the with block, but it's only checked when the context manager exits). Instead, it uses SWIG to automatically raise an exception when a C API method fails. Note that this removes the status argument from affected methods. For now, I've only applied this typemap to C API methods. It would be good to expand this to all uses of raise_exception_on_not_ok_status. PiperOrigin-RevId: 191121016
Diffstat (limited to 'tensorflow/python/client/session_list_devices_test.py')
-rw-r--r--tensorflow/python/client/session_list_devices_test.py19
1 files changed, 5 insertions, 14 deletions
diff --git a/tensorflow/python/client/session_list_devices_test.py b/tensorflow/python/client/session_list_devices_test.py
index 5a7413c12e..38a3acb2dc 100644
--- a/tensorflow/python/client/session_list_devices_test.py
+++ b/tensorflow/python/client/session_list_devices_test.py
@@ -23,7 +23,6 @@ from tensorflow.core.protobuf import cluster_pb2
from tensorflow.core.protobuf import config_pb2
from tensorflow.python import pywrap_tensorflow as tf_session
from tensorflow.python.client import session
-from tensorflow.python.framework import c_api_util
from tensorflow.python.framework import errors
from tensorflow.python.framework import ops
from tensorflow.python.framework import test_util
@@ -42,21 +41,13 @@ class SessionListDevicesTestMethods(object):
def testInvalidDeviceNumber(self):
opts = tf_session.TF_NewSessionOptions()
- with errors.raise_exception_on_not_ok_status() as status:
- c_session = tf_session.TF_NewSession(
- ops.get_default_graph()._c_graph, opts, status)
- raw_device_list = tf_session.TF_SessionListDevices(
- c_session, status)
+ c_session = tf_session.TF_NewSession(ops.get_default_graph()._c_graph, opts)
+ raw_device_list = tf_session.TF_SessionListDevices(c_session)
size = tf_session.TF_DeviceListCount(raw_device_list)
- # Test that invalid device numbers return -1 rather than a Swig-wrapped
- # pointer.
- status_no_exception = c_api_util.ScopedTFStatus()
- memory = tf_session.TF_DeviceListMemoryBytes(
- raw_device_list, size, status_no_exception)
- self.assertEqual(memory, -1)
+ with self.assertRaises(errors.InvalidArgumentError):
+ tf_session.TF_DeviceListMemoryBytes(raw_device_list, size)
tf_session.TF_DeleteDeviceList(raw_device_list)
- with errors.raise_exception_on_not_ok_status() as status:
- tf_session.TF_CloseSession(c_session, status)
+ tf_session.TF_CloseSession(c_session)
def testListDevicesGrpcSession(self):
server = server_lib.Server.create_local_server()