def test_EncodeDecodeTupleToJSON(self): a = Bar(do=1, re='foo', mi=[1, 2, 3], fa={'hello': 'there'}) b = json_utils.EncodeToJSON(a)[0] c = json_utils.DecodeFromJSON(b) self.assertTrue(isinstance(c, Bar)) self.assertEqual(c.do, 1) self.assertEqual(c.re, 'foo') self.assertEqual(c.mi, [1, 2, 3]) self.assertEqual(c.fa, {'hello': 'there'})
def test_EncodeDecodeObjectToJSON(self): a = Foo(1) b = json_utils.EncodeToJSON(a)[0] c = json_utils.DecodeFromJSON(b) self.assertTrue(isinstance(c, Foo)) self.assertEqual(c.a, 1) self.assertEqual(c.b, 'foo') self.assertEqual(c.c, [1, 2, 3]) self.assertEqual(c.d, {'blah': 'boo'})
def main(): args = registry_helpers.ParseRespireCommandLineArgs() # If running directly from the command line, we will parse and decode an # input parameters file before calling Run(). with open(args.params_file, 'r') as f: params = json_utils.DecodeFromJSON(f.read()) if Run(args.out_dir, args.build_file, args.function, params): return 0 else: return 1
def test_EncodeDecodeNestedObjectToJSON(self): a = Foo(1) b = Foo(a) c = json_utils.EncodeToJSON(b)[0] d = json_utils.DecodeFromJSON(c) self.assertTrue(isinstance(d, Foo)) self.assertTrue(isinstance(d.a, Foo)) self.assertEqual(d.a.a, 1) self.assertEqual(d.a.b, 'foo') self.assertEqual(d.a.c, [1, 2, 3]) self.assertEqual(d.a.d, {'blah': 'boo'}) self.assertEqual(d.b, 'foo') self.assertEqual(d.c, [1, 2, 3]) self.assertEqual(d.d, {'blah': 'boo'})
def main(): args = _ParsedPythonFunctionRunnerCommandLineParameters() # Make sure that the path has the target script's directory in it first thing. sys.path.insert(0, path.dirname(args.module_filepath)) # Make sure that all modules have access to the respire standard build # library. sys.path.insert(0, path.join(path.dirname(__file__), 'buildlib')) # Load in the module containing the function to execute. function_module = respire_python_wrapper_helpers.LoadSourceModule( 'python_function_module', args.module_filepath) # Get a reference to the target function within the module. if not hasattr(function_module, args.function_name): raise Exception( 'Requested respire function, "%s", not found in build file: %s.' % (args.function_name, args.module_filepath)) function = getattr(function_module, args.function_name) # Read the parameters for the function. with open(args.params_filepath, 'r') as f: params_content = f.read() params = json_utils.DecodeFromJSON(params_content) # Execute the function. exit_code = function(**params) # Discover and write out the deps files for this Python script. deps_file_content = '\n'.join( respire_python_wrapper_helpers .GetCurrentNonBuiltInImportDependencySources()) respire_python_wrapper_helpers.WriteToFileIfContentsDiffer( args.deps_filepath, deps_file_content) # Return the functions exit code. return exit_code