Example #1
0
 def _traverse_dict_for_objs(obj):
     for k, v in obj.items():
         if Box.is_box(v):
             obj[k] = Box.from_obj(v)
         elif isinstance(v, Mapping):
             _traverse_dict_for_objs(v)
         elif isinstance(v, list):
             _traverse_list_for_objs(v)
Example #2
0
def JSONDecoder(dct):
    if '__HIT__' in dct:
        return HIT(dct)
    if '__Assignment__' in dct:
        return Assignment(dct)
    if '__Box__' in dct:
        return Box(dct)
    return dct
Example #3
0
def complex_function(event, context):
    print('testing log entry')
    box = Box.from_coords([3, 4, 5, 6])
    return make_lambda_result_json_safe({
        'functionResult': inner_function(),
        'innerList': INNER_LIST,
        'innerString': INNER_STRING,
        'box': box
    })
Example #4
0
        'functionResult': inner_function(),
        'innerList': INNER_LIST,
        'innerString': INNER_STRING,
        'box': box
    })


def inner_function():
    return INNER_DICT


INNER_DICT = {
    'a': {
        'key': 'value'
    },
    'box': Box.from_coords([3, 4, 5, 6]),
    'date': datetime.datetime.now()
}
INNER_LIST = ['a', 'b', 'c', '3', 'd', '2', 'e', '1']
INNER_STRING = 'foobar'


class S3Tests(unittest.TestCase):
    def test_generate(self):
        code = lry.lmbda.generate_code_from_function(simple_function)
        self.assertTrue('import json' in code)
        self.assertTrue("return 'Hello world'" in code)
        code = lry.lmbda.generate_code_from_function(complex_function)
        print(code)
        print(inspect.getsourcefile(complex_function))
Example #5
0
 def _traverse_list_for_objs(obj):
     for i, v in enumerate(obj):
         if Box.is_box(v):
             obj[i] = Box.from_obj(v)
         elif isinstance(value, Mapping):
             _traverse_dict_for_objs(v)