From c05a6f283f215cd0865b2e5ddf8a66d3241a4a91 Mon Sep 17 00:00:00 2001 From: zermelo-wisen Date: Tue, 28 May 2024 13:22:30 +0300 Subject: [PATCH] fixup! fix: handle non json serializable types --- .../data/pytest/expected/pytest.appmap.json | 118 ++++++++++++------ _appmap/test/data/pytest/simple.py | 11 +- 2 files changed, 91 insertions(+), 38 deletions(-) diff --git a/_appmap/test/data/pytest/expected/pytest.appmap.json b/_appmap/test/data/pytest/expected/pytest.appmap.json index 5f047ad0..8723789a 100644 --- a/_appmap/test/data/pytest/expected/pytest.appmap.json +++ b/_appmap/test/data/pytest/expected/pytest.appmap.json @@ -8,95 +8,133 @@ "name": "appmap", "url": "https://github.com/applandinc/appmap-python" }, + "source_location": "test_simple.py:5", + "name": "hello world", + "feature": "Hello world", "app": "Simple", "recorder": { "name": "pytest", "type": "tests" }, - "source_location": "test_simple.py:5", - "name": "hello world", - "feature": "Hello world", "test_status": "succeeded" }, "events": [ { - "defined_class": "simple.Simple", - "method_id": "hello_world", - "path": "simple.py", - "lineno": 8, "static": false, "receiver": { - "class": "simple.Simple", "kind": "req", + "value": "", "name": "self", - "value": "" + "class": "simple.Simple" }, "parameters": [], "id": 1, "event": "call", - "thread_id": 1 + "thread_id": 1, + "defined_class": "simple.Simple", + "method_id": "hello_world", + "path": "simple.py", + "lineno": 16 }, { + "static": false, + "receiver": { + "kind": "req", + "value": "", + "name": "self", + "class": "simple.Simple" + }, + "parameters": [], + "id": 2, + "event": "call", + "thread_id": 1, "defined_class": "simple.Simple", - "method_id": "hello", + "method_id": "get_non_json_serializable", "path": "simple.py", - "lineno": 2, + "lineno": 13 + }, + { "static": false, "receiver": { - "class": "simple.Simple", "kind": "req", + "value": "", "name": "self", - "value": "" + "class": "simple.Simple" }, "parameters": [], - "id": 2, + "id": 3, "event": "call", - "thread_id": 1 + "thread_id": 1, + "defined_class": "simple.Simple", + "method_id": "hello", + "path": "simple.py", + "lineno": 7 }, { "return_value": { - "class": "builtins.str", - "value": "'Hello'" + "value": "'Hello'", + "class": "builtins.str" }, - "parent_id": 2, - "id": 3, + "parent_id": 3, + "id": 4, "event": "return", "thread_id": 1 }, { - "defined_class": "simple.Simple", - "method_id": "world", - "path": "simple.py", - "lineno": 5, "static": false, "receiver": { - "class": "simple.Simple", "kind": "req", + "value": "", "name": "self", - "value": "" + "class": "simple.Simple" }, "parameters": [], - "id": 4, + "id": 5, "event": "call", + "thread_id": 1, + "defined_class": "simple.Simple", + "method_id": "world", + "path": "simple.py", + "lineno": 10 + }, + { + "return_value": { + "value": "'world!'", + "class": "builtins.str" + }, + "parent_id": 5, + "id": 6, + "event": "return", "thread_id": 1 }, { "return_value": { - "class": "builtins.str", - "value": "'world!'" + "value": "{0: 'Hello', 1: 'world!'}", + "class": "builtins.dict", + "properties": [ + { + "name": "0", + "class": "builtins.str" + }, + { + "name": "1", + "class": "builtins.str" + } + ], + "size": 2 }, - "parent_id": 4, - "id": 5, + "parent_id": 2, + "id": 7, "event": "return", "thread_id": 1 }, { "return_value": { - "class": "builtins.str", - "value": "'Hello world!'" + "value": "'Hello world!'", + "class": "builtins.str" }, "parent_id": 1, - "id": 6, + "id": 8, "event": "return", "thread_id": 1 } @@ -110,22 +148,28 @@ "name": "Simple", "type": "class", "children": [ + { + "name": "get_non_json_serializable", + "type": "function", + "location": "simple.py:13", + "static": false + }, { "name": "hello", "type": "function", - "location": "simple.py:2", + "location": "simple.py:7", "static": false }, { "name": "hello_world", "type": "function", - "location": "simple.py:8", + "location": "simple.py:16", "static": false }, { "name": "world", "type": "function", - "location": "simple.py:5", + "location": "simple.py:10", "static": false } ] diff --git a/_appmap/test/data/pytest/simple.py b/_appmap/test/data/pytest/simple.py index eb824400..af0338eb 100644 --- a/_appmap/test/data/pytest/simple.py +++ b/_appmap/test/data/pytest/simple.py @@ -1,3 +1,8 @@ +import numpy + +zero = numpy.int64(0) +one = numpy.int64(1) + class Simple: def hello(self): return "Hello" @@ -5,5 +10,9 @@ def hello(self): def world(self): return "world!" + def get_non_json_serializable(self): + return { zero: self.hello(), one: self.world() } + def hello_world(self): - return "%s %s" % (self.hello(), self.world()) + result = self.get_non_json_serializable() + return "%s %s" % (result[zero], result[one])