Commit 63ea9a53 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Add function to format gser strings

parent 2cc2dc0c
...@@ -17,7 +17,10 @@ ...@@ -17,7 +17,10 @@
3) valueNotationToCTypes(gser, dest, sort, ASN1Mod, ASN1_AST, var=None) 3) valueNotationToCTypes(gser, dest, sort, ASN1Mod, ASN1_AST, var=None)
Parse a Value Notation string and fill a ctypes instance with the values Parse a Value Notation string and fill a ctypes instance with the values
Copyright (c) 2012-2015 European Space Agency 4) format(gser)
properly format a GSER string. useful for comparing them
Copyright (c) 2012-2016 European Space Agency
Designed and implemented by Maxime Perrotin Designed and implemented by Maxime Perrotin
...@@ -165,6 +168,12 @@ def fromValueNotationToPySide(varName, string): ...@@ -165,6 +168,12 @@ def fromValueNotationToPySide(varName, string):
raise raise
def format_gser(gser):
''' Reformat a GSER string '''
gser1 = ''.join(x.strip() for x in gser.split())
return ', '.join(gser1.split(',')).replace(':', ': ')
def toASN1ValueNotation(val): def toASN1ValueNotation(val):
''' Create a GSER reprentation of the Python variable ''' ''' Create a GSER reprentation of the Python variable '''
result = '' result = ''
......
...@@ -4,6 +4,7 @@ import sys ...@@ -4,6 +4,7 @@ import sys
sys.path.insert(0, '../..') sys.path.insert(0, '../..')
from asn1_value_editor import standalone_editor as editor from asn1_value_editor import standalone_editor as editor
from asn1_value_editor.vn import format_gser
editor.logger.setLevel(editor.logging.DEBUG) editor.logger.setLevel(editor.logging.DEBUG)
''' '''
...@@ -69,23 +70,23 @@ def test_string(qtbot): ...@@ -69,23 +70,23 @@ def test_string(qtbot):
def test_simpleseq(qtbot): def test_simpleseq(qtbot):
''' Test SEQUENCE ''' ''' Test SEQUENCE '''
typeName = "Type-SimpleSeq" typeName = "Type-SimpleSeq"
defValue = '{ item-a 42 , item-b TRUE , item-c enum-two , item-d "Hello world" }' defValue = '{item-a 42, item-b TRUE, item-c enum-two, item-d "Hello world"}'
result = common(typeName, defValue) result = common(typeName, defValue)
assert result == defValue assert format_gser(result) == format_gser(defValue)
def test_simplechoice(qtbot): def test_simplechoice(qtbot):
''' Test CHOICE ''' ''' Test CHOICE '''
typeName = "Type-SingleChoice" typeName = "Type-SingleChoice"
defValue = 'choice-b: TRUE' defValue = 'choice-b: TRUE'
result = common(typeName, defValue) result = common(typeName, defValue)
assert result == defValue assert format_gser(result) == format_gser(defValue)
def test_simpleseqof(qtbot): def test_simpleseqof(qtbot):
''' Test SEQOF ''' ''' Test SEQOF '''
typeName = "Type-SingleSeqOf" typeName = "Type-SingleSeqOf"
defValue = '{ 1 , 2 , 3 , 4 , 5 }' defValue = '{1, 2, 3, 4, 5}'
result = common(typeName, defValue) result = common(typeName, defValue)
assert result == defValue assert format_gser(result) == format_gser(defValue)
if __name__ == '__main__': if __name__ == '__main__':
print('You must run py.test-2.7 to execute this test script') print('You must run py.test-2.7 to execute this test script')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment