Eliminate use of Mock objects as specs for Mocks.
PiperOrigin-RevId: 330941100 Change-Id: I9025428ef3a393b3886f3e9109ea7de1c3daa6f2
This commit is contained in:
parent
c7be4e0be2
commit
28c8ecf51e
@ -151,7 +151,7 @@ class EvaluatorTest(test_util.TensorFlowTestCase):
|
||||
return [np.array([[1.0, 2.0, 3.0]])]
|
||||
|
||||
with test.mock.patch.object(
|
||||
dump, "get_tensors", side_effect=fake_get_tensors, autospec=True):
|
||||
dump, "get_tensors", side_effect=fake_get_tensors):
|
||||
ev = evaluator.ExpressionEvaluator(dump)
|
||||
self.assertEqual(3, ev.evaluate("np.size(`a:0`)"))
|
||||
|
||||
@ -168,7 +168,7 @@ class EvaluatorTest(test_util.TensorFlowTestCase):
|
||||
return [np.array([[-1.0], [1.0]])]
|
||||
|
||||
with test.mock.patch.object(
|
||||
dump, "get_tensors", side_effect=fake_get_tensors, autospec=True):
|
||||
dump, "get_tensors", side_effect=fake_get_tensors):
|
||||
ev = evaluator.ExpressionEvaluator(dump)
|
||||
self.assertAllClose([[-3.0], [1.0]],
|
||||
ev.evaluate("np.matmul(`a:0`, `b:0`)"))
|
||||
@ -182,7 +182,7 @@ class EvaluatorTest(test_util.TensorFlowTestCase):
|
||||
raise debug_data.WatchKeyDoesNotExistInDebugDumpDirError()
|
||||
|
||||
with test.mock.patch.object(
|
||||
dump, "get_tensors", side_effect=fake_get_tensors, autospec=True):
|
||||
dump, "get_tensors", side_effect=fake_get_tensors):
|
||||
ev = evaluator.ExpressionEvaluator(dump)
|
||||
with self.assertRaisesRegex(
|
||||
ValueError, "Eval failed due to the value of .* being unavailable"):
|
||||
@ -204,7 +204,7 @@ class EvaluatorTest(test_util.TensorFlowTestCase):
|
||||
return [np.array(20.0)]
|
||||
|
||||
with test.mock.patch.object(
|
||||
dump, "get_tensors", side_effect=fake_get_tensors, autospec=True):
|
||||
dump, "get_tensors", side_effect=fake_get_tensors):
|
||||
ev = evaluator.ExpressionEvaluator(dump)
|
||||
with self.assertRaisesRegex(ValueError, r"multiple \(2\) devices"):
|
||||
ev.evaluate("`a:0` + `a:0`")
|
||||
@ -224,7 +224,7 @@ class EvaluatorTest(test_util.TensorFlowTestCase):
|
||||
return [np.array([[-2.0, 2.0]])]
|
||||
|
||||
with test.mock.patch.object(
|
||||
dump, "get_tensors", side_effect=fake_get_tensors, autospec=True):
|
||||
dump, "get_tensors", side_effect=fake_get_tensors):
|
||||
ev = evaluator.ExpressionEvaluator(dump)
|
||||
self.assertAllClose(
|
||||
[[4.0]],
|
||||
@ -238,7 +238,7 @@ class EvaluatorTest(test_util.TensorFlowTestCase):
|
||||
return [np.array([[-1.0], [1.0]]), np.array([[-2.0], [2.0]])]
|
||||
|
||||
with test.mock.patch.object(
|
||||
dump, "get_tensors", side_effect=fake_get_tensors, autospec=True):
|
||||
dump, "get_tensors", side_effect=fake_get_tensors):
|
||||
ev = evaluator.ExpressionEvaluator(dump)
|
||||
self.assertAllClose(
|
||||
[[4.0]], ev.evaluate("np.matmul(`a:0[1]`.T, `a:0[0]`)"))
|
||||
|
@ -87,6 +87,7 @@ class CloudTpuClientTest(test.TestCase):
|
||||
if 'TPU_NAME' in os.environ:
|
||||
del os.environ['TPU_NAME']
|
||||
self._time_now = 0
|
||||
self.addCleanup(mock.patch.stopall)
|
||||
|
||||
def _mock_time(self, *args, **kwargs):
|
||||
return self._time_now
|
||||
|
Loading…
x
Reference in New Issue
Block a user