Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions subprojects/pyntcore/gen/NetworkTableEntry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,7 @@ classes:
GetTopic:
operator==:
operator!=:
inline_code: |
.def("__repr__", [](NetworkTableEntry self) {
return py::str("<NetworkTableEntry {!r}>").format(self.GetName());
})
18 changes: 18 additions & 0 deletions subprojects/pyntcore/gen/Topic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ classes:
std::string_view, const PubSubOptions&:
operator==:
operator!=:
inline_code: |
.def("__repr__", [](py::handle self) {
py::object type_name = self.get_type().attr("__qualname__");
std::string name = self.cast<Topic>().GetName();
return py::str("<{} {!r}>").format(type_name, name);
})
Subscriber:
attributes:
m_subHandle:
Expand All @@ -59,6 +65,12 @@ classes:
ignore: true
NT_Subscriber:
ignore: true
inline_code: |
.def("__repr__", [](py::handle self) {
py::object type_name = self.get_type().attr("__qualname__");
auto topic = self.cast<const Subscriber&>().GetTopic();
return py::str("<{} {!r}>").format(type_name, topic.GetName());
})
Publisher:
attributes:
m_pubHandle:
Expand All @@ -72,3 +84,9 @@ classes:
ignore: true
NT_Publisher:
ignore: true
inline_code: |
.def("__repr__", [](py::handle self) {
py::object type_name = self.get_type().attr("__qualname__");
auto topic = self.cast<const Publisher&>().GetTopic();
return py::str("<{} {!r}>").format(type_name, topic.GetName());
})
19 changes: 19 additions & 0 deletions subprojects/pyntcore/tests/test_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
#


def test_entry_repr(nt):
e = nt.getEntry("/k1")
assert repr(e) == "<NetworkTableEntry '/k1'>"


def test_topic_repr(nt):
topic = nt.getIntegerTopic("/int")
assert repr(topic) == "<IntegerTopic '/int'>"

pub = topic.publish()
assert repr(pub) == "<IntegerPublisher '/int'>"

entry = topic.getEntry(0)
assert repr(entry) == "<IntegerEntry '/int'>"

generic_entry = topic.getGenericEntry()
assert repr(generic_entry) == "<GenericEntry '/int'>"


def test_entry_string(nt):
e = nt.getEntry("/k1")
assert e.getString(None) is None
Expand Down
Loading