Add object inspection tests for int

This commit is contained in:
Pavel Minaev 2024-05-02 12:56:55 -07:00 committed by Pavel Minaev
parent 278ed2fe2a
commit de1e456aa2
3 changed files with 51 additions and 0 deletions

View file

@ -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:

View file

@ -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"""

View file

@ -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),
]