Commit 009190c5 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Keep dash in VN parsed strings

parent 268ab8ee
...@@ -137,19 +137,19 @@ VALUE_LIST.setParseAction(lambda s, l, t: [t.asList()]) ...@@ -137,19 +137,19 @@ VALUE_LIST.setParseAction(lambda s, l, t: [t.asList()])
def parseChoiceValue(s, l, t): def parseChoiceValue(s, l, t):
''' Parsing CHOICE ''' ''' Parsing CHOICE '''
choice = t[0].replace('-', '_') choice = t[0]
return {'Choice': choice, choice: t[2]} return {'Choice': choice, choice: t[2]}
choiceValue.setParseAction(parseChoiceValue) choiceValue.setParseAction(parseChoiceValue)
def parseValueReference(s, l, t): def parseValueReference(s, l, t):
''' Parsing ENUMERATED Id ''' ''' Parsing ENUMERATED Id '''
value = t[0]#.replace('-', '_') value = t[0]
return {'Enum': value} return {'Enum': value}
valuereference.setParseAction(parseValueReference) valuereference.setParseAction(parseValueReference)
namedValue.setParseAction(lambda s, l, t: {t[0].replace('-', '_'): t[1]}) namedValue.setParseAction(lambda s, l, t: {t[0]: t[1]})
FloatingPointLiteral.setParseAction(lambda s, l, t: float(t[0])) FloatingPointLiteral.setParseAction(lambda s, l, t: float(t[0]))
INT.setParseAction(lambda s, l, t: int(t[0])) INT.setParseAction(lambda s, l, t: int(t[0]))
TRUE.setParseAction(lambda s, l, t: True) TRUE.setParseAction(lambda s, l, t: True)
...@@ -181,17 +181,17 @@ def toASN1ValueNotation(val): ...@@ -181,17 +181,17 @@ def toASN1ValueNotation(val):
result = '' result = ''
if isinstance(val, dict): if isinstance(val, dict):
if 'Choice' in val: if 'Choice' in val:
result += val['Choice'].replace('_', '-').strip() + ':' result += val['Choice'].strip() + ':'
result += toASN1ValueNotation(val[val['Choice']]) result += toASN1ValueNotation(val[val['Choice']])
elif 'Enum' in val: elif 'Enum' in val:
result += unicode(val['Enum']).replace('_', '-').strip() result += unicode(val['Enum']).strip()
else: # SEQUENCE and SET else: # SEQUENCE and SET
result += ' { ' result += ' { '
needsComa = False needsComa = False
for seqElem in val: for seqElem in val:
if needsComa: if needsComa:
result += ', ' result += ', '
result += seqElem.replace('_', '-').strip() + ' ' result += seqElem.strip() + ' '
result += toASN1ValueNotation(val[seqElem]) result += toASN1ValueNotation(val[seqElem])
needsComa = True needsComa = True
result += ' }' result += ' }'
......
...@@ -78,7 +78,7 @@ def test_random_simpleseq(qtbot): ...@@ -78,7 +78,7 @@ def test_random_simpleseq(qtbot):
def test_random_simplechoice(qtbot): def test_random_simplechoice(qtbot):
''' Test CHOICE. ''' ''' Test CHOICE. '''
typeName = "Type-SingleChoice" typeName = "Type-SingleChoice"
for i in range(1000): for i in range(100):
result = compute_random_value(pool[typeName], pool) result = compute_random_value(pool[typeName], pool)
if 'choice-B' in result: if 'choice-B' in result:
assert 'TRUE' in result or 'FALSE' in result assert 'TRUE' in result or 'FALSE' in result
...@@ -93,7 +93,7 @@ def test_random_simplechoice(qtbot): ...@@ -93,7 +93,7 @@ def test_random_simplechoice(qtbot):
def test_random_simpleseqof(qtbot): def test_random_simpleseqof(qtbot):
''' Test SEQOF ''' ''' Test SEQOF '''
typeName = "Type-SingleSeqOf" typeName = "Type-SingleSeqOf"
for i in range(1000): for i in range(100):
result = compute_random_value(pool[typeName], pool) result = compute_random_value(pool[typeName], pool)
value = parse_gser('result', result)['result'] value = parse_gser('result', result)['result']
assert 0 <= len(value) <= 5 assert 0 <= len(value) <= 5
...@@ -104,7 +104,7 @@ def test_random_simpleseqof(qtbot): ...@@ -104,7 +104,7 @@ def test_random_simpleseqof(qtbot):
def test_random_mydata(qtbot): def test_random_mydata(qtbot):
''' Test more complex sequence ''' ''' Test more complex sequence '''
typeName = "MyData" typeName = "MyData"
for i in range(1000): for i in range(10):
result = compute_random_value(pool[typeName], pool) result = compute_random_value(pool[typeName], pool)
value = parse_gser('result', result)['result'] value = parse_gser('result', result)['result']
assert type(value) is list and 1 <= len(value) <= 10 assert type(value) is list and 1 <= len(value) <= 10
...@@ -118,7 +118,7 @@ def test_random_mydata(qtbot): ...@@ -118,7 +118,7 @@ def test_random_mydata(qtbot):
def test_random_seq2(qtbot): def test_random_seq2(qtbot):
''' Test more complex sequence ''' ''' Test more complex sequence '''
typeName = "Type-Seq" typeName = "Type-Seq"
for i in range(1000): for i in range(10):
result = compute_random_value(pool[typeName], pool) result = compute_random_value(pool[typeName], pool)
value = parse_gser('result', result)['result'] value = parse_gser('result', result)['result']
assert 'item-a' in value and 'item-b' in value and 'item-C' in value \ assert 'item-a' in value and 'item-b' in value and 'item-C' in value \
......
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