Skip to content

Commit 4e9bb50

Browse files
committed
add __str__ method to Gather class
1 parent 78f20f2 commit 4e9bb50

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/core/bindings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ PYBIND11_MODULE(_gather, m) {
4242
.def_readwrite("id", &Gather::id)
4343
.def_readwrite("dt", &Gather::dt)
4444
.def_readwrite("nt", &Gather::nt)
45-
.def_readwrite("nx", &Gather::nx);
45+
.def_readwrite("nx", &Gather::nx)
46+
.def("__str__", &Gather::display);
4647
}

src/core/gather/gather.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44

55
#ifndef GATHER_H
66
#define GATHER_H
7+
#include <iostream>
8+
#include <vector>
79

810
class Gather {
911
public:
1012
int id;
1113
int nt;
1214
int nx;
1315
double dt;
16+
[[nodiscard]] std::string display() const {
17+
return "Gather id: " + std::to_string(id);
18+
}
1419
};
1520

1621
#endif // GATHER_H

tests/libseis/test_gather.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ def test_public_int_attributes(self, gather, attr):
2121
val = 42
2222
setattr(gather, attr, val)
2323
assert getattr(gather, attr) == val
24+
25+
def test_gather_has_str_method(self, gather, capfd):
26+
"""Test the Gather class __str__."""
27+
print(gather) # noqa: T201
28+
out, _ = capfd.readouterr()
29+
assert "Gather" in out

0 commit comments

Comments
 (0)