Skip to content

Commit e4576f6

Browse files
committed
Add some tests for QByteArray conversion.
1 parent a4338db commit e4576f6

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

tests/python/test_qt.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ PYBIND11_MODULE(qt, m)
3333
return QString::number(value);
3434
});
3535

36+
// QByteArray
37+
m.def("create_qbytearray_from_raw", [](const char* raw) {
38+
return QByteArray(raw);
39+
});
40+
m.def("get_qbytearray_length", [](const QByteArray& data) {
41+
return data.size();
42+
});
43+
3644
// QStringList
3745

3846
m.def("qstringlist_join", [](QStringList const& values, QString const& sep) {

tests/python/test_qt.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from PyQt6.QtCore import QDateTime, Qt
1+
import struct
2+
3+
from PyQt6.QtCore import QByteArray, QDateTime, Qt
24

35
import mobase_tests.qt as m
46

@@ -23,6 +25,12 @@ def test_qstring():
2325
assert m.consume_qstring_with_emoji("🌎") == 2
2426

2527

28+
def test_qbytearray():
29+
arr = m.create_qbytearray_from_raw("hello world!")
30+
assert isinstance(arr, QByteArray)
31+
assert m.get_qbytearray_length(arr) == 12
32+
33+
2634
def test_qstringlist():
2735
assert m.qstringlist_join([""], "--") == ""
2836
assert m.qstringlist_join(["a", "b"], "") == "ab"

typings/mobase_tests/qt.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ __all__ = [
1010
"SimpleEnum",
1111
"consume_qstring_with_emoji",
1212
"create_qstring_with_emoji",
13+
"create_qbytearray_from_raw",
14+
"get_qbytearray_length",
15+
"qbytearray_to_longlong",
1316
"datetime_from_string",
1417
"datetime_to_string",
1518
"int_to_qstring",
@@ -92,6 +95,9 @@ def qflags_explode(arg0: int) -> tuple[int, bool, bool, bool]: ...
9295
def qmap_to_length(arg0: dict[str, str]) -> dict[str, int]: ...
9396
def qstring_to_int(arg0: str) -> int: ...
9497
def qstring_to_stdstring(arg0: str) -> str: ...
98+
def create_qbytearray_from_raw(arg0: str | bytes) -> PyQt6.QtCore.QByteArray: ...
99+
def get_qbytearray_length(arg0: PyQt6.QtCore.QByteArray) -> int: ...
100+
def qbytearray_to_longlong(arg0: PyQt6.QtCore.QByteArray) -> int: ...
95101
def qstringlist_at(arg0: typing.Sequence[str], arg1: int) -> str: ...
96102
def qstringlist_join(arg0: typing.Sequence[str], arg1: str) -> str: ...
97103
def qvariant_bool() -> MoVariant: ...

0 commit comments

Comments
 (0)