Add TextType to ease gui generation

TextType is intended for formatted text (multiple lines),
whereas StringType is intended for a single line of text (without '\n')

Change-Id: Ibce29ae6b4e426bd8685f2cf7ff6966d81b0c6aa
Reviewed-on: https://forge.frm2.tum.de/review/20951
Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de>
Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
This commit is contained in:
Enrico Faulhaber
2019-07-24 14:02:00 +02:00
parent 95d50fb51e
commit c7c9403d1f
3 changed files with 57 additions and 4 deletions

View File

@ -28,7 +28,7 @@ import pytest
from secop.datatypes import ArrayOf, BLOBType, BoolType, \
DataType, EnumType, FloatRange, IntRange, ProgrammingError, \
ScaledInteger, StringType, StructOf, TupleOf, get_datatype, CommandType
ScaledInteger, StringType, TextType, StructOf, TupleOf, get_datatype, CommandType
def copytest(dt):
@ -261,6 +261,27 @@ def test_StringType():
assert dt.format_value(u'abcd') == u"u'abcd'"
def test_TextType():
# test constructor catching illegal arguments
dt = TextType(12)
assert dt.export_datatype() == [u'string', {u'min':0, u'max':12}]
with pytest.raises(ValueError):
dt(9)
with pytest.raises(ValueError):
dt(u'abcdefghijklmno')
with pytest.raises(ValueError):
dt('abcdefg\0')
assert dt('ab\n\ncd\n') == b'ab\n\ncd\n'
assert dt(b'ab\n\ncd\n') == b'ab\n\ncd\n'
assert dt(u'ab\n\ncd\n') == b'ab\n\ncd\n'
assert dt.export_value('abcd') == b'abcd'
assert dt.export_value(b'abcd') == b'abcd'
assert dt.export_value(u'abcd') == b'abcd'
assert dt.import_value(u'abcd') == u'abcd'
def test_BoolType():
# test constructor catching illegal arguments
dt = BoolType()