Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 17
feat: Add APPMAP_DISPLAY_LABELED_PARAMS to capture params for labeled functions#384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -45,8 +45,16 @@ def __init__(self, env=None, cwd=None): | ||
| # them. | ||
| enabled = self._env.get("_APPMAP", None) | ||
| self._enabled = enabled is not None and enabled.lower() != "false" | ||
| display_params = self._env.get("_APPMAP_DISPLAY_PARAMS", None) | ||
| self._display_params = display_params is not None and display_params.lower() != "false" | ||
| display_params = self._env.get("_APPMAP_DISPLAY_PARAMS", "labeled").lower() | ||
| if display_params == "true": | ||
| self._display_params = True | ||
| self._display_labeled_params = True | ||
| elif display_params == "false": | ||
| self._display_params = False | ||
| self._display_labeled_params = False | ||
| else: # "labeled" or "auto" or anything else defaults to labeled | ||
| self._display_params = False | ||
| self._display_labeled_params = True | ||
Comment on lines
+48
to
+57
CopilotAI | ||
| logger = logging.getLogger(__name__) | ||
| # The user shouldn't set APPMAP_OUTPUT_DIR, but some tests depend on being able to use it. | ||
| @@ -134,6 +142,10 @@ def is_appmap_repo(self): | ||
| def display_params(self): | ||
| return self._display_params | ||
| @property | ||
| def display_labeled_params(self): | ||
| return self._display_labeled_params | ||
| def getLogger(self, name) -> trace_logger.TraceLogger: | ||
| return cast(trace_logger.TraceLogger, logging.getLogger(name)) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -52,6 +52,7 @@ def test_recursion_protection(self): | ||
| # is working | ||
| assert True | ||
| @pytest.mark.appmap_enabled(env={"APPMAP_DISPLAY_PARAMS": "true"}) | ||
| def test_when_str_raises(self, mocker): | ||
| r = appmap.Recording() | ||
| with r: | ||
| @@ -68,6 +69,7 @@ def test_when_str_raises(self, mocker): | ||
| actual_value = r.events[0].parameters[0]["value"] | ||
| assert expected_value == actual_value | ||
| @pytest.mark.appmap_enabled(env={"APPMAP_DISPLAY_PARAMS": "true"}) | ||
| def test_when_both_raise(self, mocker): | ||
| r = appmap.Recording() | ||
| with r: | ||
| @@ -117,6 +119,60 @@ def test_describe_return_value_recursion_protection(self): | ||
| "return_self" | ||
| ] | ||
| @pytest.mark.appmap_enabled(env={"APPMAP_DISPLAY_PARAMS": None}) | ||
| def test_labeled_params_displayed_by_default(self): | ||
| """When display_params is 'labeled' (default), | ||
dividedmind marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| labeled functions should still have their params displayed via repr().""" | ||
| r = appmap.Recording() | ||
| with r: | ||
| from example_class import ExampleClass # pylint: disable=import-outside-toplevel | ||
| result = ExampleClass().labeled_method_with_param("hello") | ||
| ExampleClass().instance_with_param("hello") | ||
| assert result == "hello" | ||
| call_event = r.events[0] | ||
| # Parameter value should be the repr, not the opaque object string | ||
| assert call_event.parameters[0]["value"] == "'hello'" | ||
| # Return value should also be displayed | ||
| return_event = r.events[1] | ||
| assert return_event.return_value["value"] == "'hello'" | ||
| # Unlabeled method should not have its params displayed, even in the same recording | ||
| call_event_unlabeled = r.events[2] | ||
| assert "object at" in call_event_unlabeled.parameters[0]["value"] | ||
| @pytest.mark.appmap_enabled( | ||
| env={ | ||
| "APPMAP_DISPLAY_PARAMS": "false", | ||
| } | ||
| ) | ||
| def test_labeled_params_not_displayed_when_disabled(self): | ||
| """When display_params is off, labeled functions should NOT have their params displayed.""" | ||
| r = appmap.Recording() | ||
| with r: | ||
| from example_class import ExampleClass # pylint: disable=import-outside-toplevel | ||
| ExampleClass().labeled_method_with_param("hello") | ||
| call_event = r.events[0] | ||
| # Parameter value should be the opaque object string | ||
| assert "object at" in call_event.parameters[0]["value"] | ||
| @pytest.mark.appmap_enabled(env={"APPMAP_DISPLAY_PARAMS": "labeled"}) | ||
| def test_unlabeled_params_not_displayed(self): | ||
| """When display_params is 'labeled', unlabeled functions should NOT | ||
| have their params displayed.""" | ||
| r = appmap.Recording() | ||
| with r: | ||
| from example_class import ExampleClass # pylint: disable=import-outside-toplevel | ||
| ExampleClass().instance_with_param("hello") | ||
| call_event = r.events[0] | ||
| # Parameter value should be the opaque object string | ||
| assert "object at" in call_event.parameters[0]["value"] | ||
| # There should be an exception return event generated even when the raised exception is a | ||
| # BaseException. | ||
| def test_exception_event_with_base_exception(self): | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.