diff --git a/src/debugpy/server/inspect/children.py b/src/debugpy/server/inspect/children.py index cc5d68fa..09a9f62f 100644 --- a/src/debugpy/server/inspect/children.py +++ b/src/debugpy/server/inspect/children.py @@ -60,6 +60,11 @@ class NamedChildObject(ChildObject): def expr(self, parent_expr: str) -> str: accessor = self.accessor(ValueFormat()) return f"({parent_expr}).{accessor}" + + def __eq__(self, other): + if not isinstance(other, NamedChildObject): + return False + return (self.name, self.value) == (other.name, other.value) class LenChildObject(NamedChildObject): @@ -94,6 +99,11 @@ class IndexedChildObject(ChildObject): def expr(self, parent_expr: str) -> str: accessor = self.accessor(ValueFormat()) return f"({parent_expr}){accessor}" + + def __eq__(self, other): + if not isinstance(other, IndexedChildObject): + return False + return (self.key, self.value) == (other.key, other.value) class ObjectInspector: diff --git a/tests/debugpy/server/inspect/__init__.py b/tests/debugpy/server/inspect/__init__.py new file mode 100644 index 00000000..9ff2c2b7 --- /dev/null +++ b/tests/debugpy/server/inspect/__init__.py @@ -0,0 +1,5 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +"""Tests for debugpy.server.inspect""" diff --git a/tests/debugpy/server/inspect/test_numeric.py b/tests/debugpy/server/inspect/test_numeric.py new file mode 100644 index 00000000..9d68e532 --- /dev/null +++ b/tests/debugpy/server/inspect/test_numeric.py @@ -0,0 +1,36 @@ +import pytest +from debugpy.server.inspect import ValueFormat +from debugpy.server.inspect.children import NamedChildObject, inspect_children +from debugpy.server.inspect.repr import formatted_repr + + +@pytest.mark.parametrize("base", ["dec", "hex"]) +@pytest.mark.parametrize("value", [0, 42, -42, 1_234_567_890_123, -1_234_567_890_123]) +def test_int_repr(value, base): + format = ValueFormat(hex=(base == "hex")) + expected_repr = (hex if base == "hex" else repr)(value) + assert formatted_repr(value, format) == expected_repr + + +def test_int_repr_derived(): + class CustomInt(int): + def __repr__(self): + return f"CustomInt({int(self)})" + + value = CustomInt(42) + assert formatted_repr(value, ValueFormat()) == repr(value) + + +def test_int_children(): + inspector = inspect_children(42) + + assert inspector.indexed_children_count() == 0 + assert list(inspector.indexed_children()) == [] + + assert inspector.named_children_count() == 4 + assert list(inspector.named_children()) == [ + NamedChildObject("denominator", 1), + NamedChildObject("imag", 0), + NamedChildObject("numerator", 42), + NamedChildObject("real", 42), + ]