Add some tests for QByteArray conversion.

This commit is contained in:
Mikaël Capelle
2024-08-10 10:16:25 +02:00
parent a4338db554
commit e4576f67a6
3 changed files with 23 additions and 1 deletions
+8
View File
@@ -33,6 +33,14 @@ PYBIND11_MODULE(qt, m)
return QString::number(value);
});
// QByteArray
m.def("create_qbytearray_from_raw", [](const char* raw) {
return QByteArray(raw);
});
m.def("get_qbytearray_length", [](const QByteArray& data) {
return data.size();
});
// QStringList
m.def("qstringlist_join", [](QStringList const& values, QString const& sep) {
+9 -1
View File
@@ -1,4 +1,6 @@
from PyQt6.QtCore import QDateTime, Qt
import struct
from PyQt6.QtCore import QByteArray, QDateTime, Qt
import mobase_tests.qt as m
@@ -23,6 +25,12 @@ def test_qstring():
assert m.consume_qstring_with_emoji("🌎") == 2
def test_qbytearray():
arr = m.create_qbytearray_from_raw("hello world!")
assert isinstance(arr, QByteArray)
assert m.get_qbytearray_length(arr) == 12
def test_qstringlist():
assert m.qstringlist_join([""], "--") == ""
assert m.qstringlist_join(["a", "b"], "") == "ab"
+6
View File
@@ -10,6 +10,9 @@ __all__ = [
"SimpleEnum",
"consume_qstring_with_emoji",
"create_qstring_with_emoji",
"create_qbytearray_from_raw",
"get_qbytearray_length",
"qbytearray_to_longlong",
"datetime_from_string",
"datetime_to_string",
"int_to_qstring",
@@ -92,6 +95,9 @@ def qflags_explode(arg0: int) -> tuple[int, bool, bool, bool]: ...
def qmap_to_length(arg0: dict[str, str]) -> dict[str, int]: ...
def qstring_to_int(arg0: str) -> int: ...
def qstring_to_stdstring(arg0: str) -> str: ...
def create_qbytearray_from_raw(arg0: str | bytes) -> PyQt6.QtCore.QByteArray: ...
def get_qbytearray_length(arg0: PyQt6.QtCore.QByteArray) -> int: ...
def qbytearray_to_longlong(arg0: PyQt6.QtCore.QByteArray) -> int: ...
def qstringlist_at(arg0: typing.Sequence[str], arg1: int) -> str: ...
def qstringlist_join(arg0: typing.Sequence[str], arg1: str) -> str: ...
def qvariant_bool() -> MoVariant: ...