def testRunCommandWithDebuggerEnabled(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) x = np.array([[1], [2]]) x_notused = np.zeros((6, 3)) input_path = os.path.join(test.get_temp_dir(), 'testRunCommandNewOutdir_inputs.npz') output_dir = os.path.join(test.get_temp_dir(), 'new_dir') if os.path.isdir(output_dir): shutil.rmtree(output_dir) np.savez(input_path, x0=x, x1=x_notused) args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'serving_default', '--inputs', 'x=' + input_path + '[x0]', '--outdir', output_dir, '--tf_debug' ]) def fake_wrapper_session(sess): return sess with test.mock.patch.object(local_cli_wrapper, 'LocalCLIDebugWrapperSession', side_effect=fake_wrapper_session, autospec=True) as fake: saved_model_cli.run(args) fake.assert_called_with(test.mock.ANY) y_actual = np.load(os.path.join(output_dir, 'y.npy')) y_expected = np.array([[2.5], [3.0]]) self.assertAllClose(y_expected, y_actual)
def testRunCommandWithDebuggerEnabled(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) x = np.array([[1], [2]]) x_notused = np.zeros((6, 3)) input_path = os.path.join(test.get_temp_dir(), 'testRunCommandNewOutdir_inputs.npz') output_dir = os.path.join(test.get_temp_dir(), 'new_dir') if os.path.isdir(output_dir): shutil.rmtree(output_dir) np.savez(input_path, x0=x, x1=x_notused) args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'serving_default', '--inputs', 'x=' + input_path + '[x0]', '--outdir', output_dir, '--tf_debug' ]) def fake_wrapper_session(sess): return sess with test.mock.patch.object( local_cli_wrapper, 'LocalCLIDebugWrapperSession', side_effect=fake_wrapper_session, autospec=True) as fake: saved_model_cli.run(args) fake.assert_called_with(test.mock.ANY) y_actual = np.load(os.path.join(output_dir, 'y.npy')) y_expected = np.array([[2.5], [3.0]]) self.assertAllClose(y_expected, y_actual)
def testRunCommandInputNotGivenError(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'serving_default' ]) with self.assertRaises(AttributeError): saved_model_cli.run(args)
def testRunCommandInvalidInputKeyError(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'regress_x2_to_y3', '--input_exprs', 'x2=np.ones((3,1))' ]) with self.assertRaises(ValueError): saved_model_cli.run(args)
def testRunCommandInputNotGivenError(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'serving_default' ]) with self.assertRaises(AttributeError): saved_model_cli.run(args)
def testRunCommandInvalidInputKeyError(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'regress_x2_to_y3', '--input_exprs', 'x2=np.ones((3,1))' ]) with self.assertRaises(ValueError): saved_model_cli.run(args)
def testRunCommandInvalidSignature(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'INVALID_SIGNATURE', '--input_exprs', 'x2=np.ones((3,1))' ]) with self.assertRaisesRegex(ValueError, 'Could not find signature "INVALID_SIGNATURE"'): saved_model_cli.run(args)
def testRunCommandInputExamplesFeatureValueNotListError(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) output_dir = os.path.join(test.get_temp_dir(), 'new_dir') args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'regress_x_to_y', '--input_examples', 'inputs=[{"x":8.0,"x2":5.0}]', '--outdir', output_dir ]) with self.assertRaisesRegex(ValueError, 'feature value must be a list'): saved_model_cli.run(args)
def testRunCommandInputExamplesFeatureBadType(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) output_dir = os.path.join(test.get_temp_dir(), 'new_dir') args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'regress_x_to_y', '--input_examples', 'inputs=[{"x":[[1],[2]]}]', '--outdir', output_dir ]) with self.assertRaisesRegexp(ValueError, 'is not supported'): saved_model_cli.run(args)
def testRunCommandInputExamplesFeatureValueNotListError(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) output_dir = os.path.join(test.get_temp_dir(), 'new_dir') args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'regress_x_to_y', '--input_examples', 'inputs=[{"x":8.0,"x2":5.0}]', '--outdir', output_dir ]) with self.assertRaisesRegexp(ValueError, 'feature value must be a list'): saved_model_cli.run(args)
def testRunCommandInputExamplesFeatureBadType(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) output_dir = os.path.join(test.get_temp_dir(), 'new_dir') args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'regress_x_to_y', '--input_examples', 'inputs=[{"x":[[1],[2]]}]', '--outdir', output_dir ]) with self.assertRaisesRegex(ValueError, 'is not supported'): saved_model_cli.run(args)
def testRunCommandInputExamples(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) output_dir = os.path.join(test.get_temp_dir(), 'new_dir') args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'regress_x_to_y', '--input_examples', 'inputs=[{"x":[8.0],"x2":[5.0]}, {"x":[4.0],"x2":[3.0]}]', '--outdir', output_dir ]) saved_model_cli.run(args) y_actual = np.load(os.path.join(output_dir, 'outputs.npy')) y_expected = np.array([[6.0], [4.0]]) self.assertAllEqual(y_expected, y_actual)
def testRunCommandInputExamples(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) output_dir = os.path.join(test.get_temp_dir(), 'new_dir') args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'regress_x_to_y', '--input_examples', 'inputs=[{"x":[8.0],"x2":[5.0]}, {"x":[4.0],"x2":[3.0]}]', '--outdir', output_dir ]) saved_model_cli.run(args) y_actual = np.load(os.path.join(output_dir, 'outputs.npy')) y_expected = np.array([[6.0], [4.0]]) self.assertAllEqual(y_expected, y_actual)
def testRunCommandOutputFileExistError(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) x = np.array([[1], [2]]) x_notused = np.zeros((6, 3)) input_path = os.path.join(test.get_temp_dir(), 'testRunCommandOutOverwrite_inputs.npz') np.savez(input_path, x0=x, x1=x_notused) output_file = os.path.join(test.get_temp_dir(), 'y.npy') open(output_file, 'a').close() args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'serving_default', '--inputs', 'x=' + input_path + '[x0]', '--outdir', test.get_temp_dir() ]) with self.assertRaises(RuntimeError): saved_model_cli.run(args)
def testRunCommandOutputFileExistError(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) x = np.array([[1], [2]]) x_notused = np.zeros((6, 3)) input_path = os.path.join(test.get_temp_dir(), 'testRunCommandOutOverwrite_inputs.npz') np.savez(input_path, x0=x, x1=x_notused) output_file = os.path.join(test.get_temp_dir(), 'y.npy') open(output_file, 'a').close() args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'serving_default', '--inputs', 'x=' + input_path + '[x0]', '--outdir', test.get_temp_dir() ]) with self.assertRaises(RuntimeError): saved_model_cli.run(args)
def testRunCommandOutOverwrite(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) x = np.array([[1], [2]]) x_notused = np.zeros((6, 3)) input_path = os.path.join(test.get_temp_dir(), 'testRunCommandOutOverwrite_inputs.npz') np.savez(input_path, x0=x, x1=x_notused) output_file = os.path.join(test.get_temp_dir(), 'y.npy') open(output_file, 'a').close() args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'serving_default', '--inputs', 'x=' + input_path + '[x0]', '--outdir', test.get_temp_dir(), '--overwrite' ]) saved_model_cli.run(args) y_actual = np.load(output_file) y_expected = np.array([[2.5], [3.0]]) self.assertAllClose(y_expected, y_actual)
def testRunCommandOutOverwrite(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) x = np.array([[1], [2]]) x_notused = np.zeros((6, 3)) input_path = os.path.join(test.get_temp_dir(), 'testRunCommandOutOverwrite_inputs.npz') np.savez(input_path, x0=x, x1=x_notused) output_file = os.path.join(test.get_temp_dir(), 'y.npy') open(output_file, 'a').close() args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'serving_default', '--inputs', 'x=' + input_path + '[x0]', '--outdir', test.get_temp_dir(), '--overwrite' ]) saved_model_cli.run(args) y_actual = np.load(output_file) y_expected = np.array([[2.5], [3.0]]) self.assertAllClose(y_expected, y_actual)
def testRunCommandNewOutdir(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) x = np.array([[1], [2]]) x_notused = np.zeros((6, 3)) input_path = os.path.join(test.get_temp_dir(), 'testRunCommandNewOutdir_inputs.npz') output_dir = os.path.join(test.get_temp_dir(), 'new_dir') if os.path.isdir(output_dir): shutil.rmtree(output_dir) np.savez(input_path, x0=x, x1=x_notused) args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'serving_default', '--inputs', 'x=' + input_path + '[x0]', '--outdir', output_dir ]) saved_model_cli.run(args) y_actual = np.load(os.path.join(output_dir, 'y.npy')) y_expected = np.array([[2.5], [3.0]]) self.assertAllClose(y_expected, y_actual)
def testRunCommandExistingOutdir(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) x = np.array([[1], [2]]) x_notused = np.zeros((6, 3)) input_path = os.path.join(test.get_temp_dir(), 'testRunCommand_inputs.npz') np.savez(input_path, x0=x, x1=x_notused) output_file = os.path.join(test.get_temp_dir(), 'outputs.npy') if os.path.exists(output_file): os.remove(output_file) args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'regress_x2_to_y3', '--inputs', 'inputs=' + input_path + '[x0]', '--outdir', test.get_temp_dir() ]) saved_model_cli.run(args) y_actual = np.load(output_file) y_expected = np.array([[3.5], [4.0]]) self.assertAllClose(y_expected, y_actual)
def testRunCommandExistingOutdir(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) x = np.array([[1], [2]]) x_notused = np.zeros((6, 3)) input_path = os.path.join(test.get_temp_dir(), 'testRunCommand_inputs.npz') np.savez(input_path, x0=x, x1=x_notused) output_file = os.path.join(test.get_temp_dir(), 'outputs.npy') if os.path.exists(output_file): os.remove(output_file) args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'regress_x2_to_y3', '--inputs', 'inputs=' + input_path + '[x0]', '--outdir', test.get_temp_dir() ]) saved_model_cli.run(args) y_actual = np.load(output_file) y_expected = np.array([[3.5], [4.0]]) self.assertAllClose(y_expected, y_actual)
def testRunCommandNewOutdir(self): self.parser = saved_model_cli.create_parser() base_path = test.test_src_dir_path(SAVED_MODEL_PATH) x = np.array([[1], [2]]) x_notused = np.zeros((6, 3)) input_path = os.path.join(test.get_temp_dir(), 'testRunCommandNewOutdir_inputs.npz') output_dir = os.path.join(test.get_temp_dir(), 'new_dir') if os.path.isdir(output_dir): shutil.rmtree(output_dir) np.savez(input_path, x0=x, x1=x_notused) args = self.parser.parse_args([ 'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def', 'serving_default', '--inputs', 'x=' + input_path + '[x0]', '--outdir', output_dir ]) saved_model_cli.run(args) y_actual = np.load(os.path.join(output_dir, 'y.npy')) y_expected = np.array([[2.5], [3.0]]) self.assertAllClose(y_expected, y_actual)