Commit 24bfd011 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

First test case success!

parent b57e42df
......@@ -61,7 +61,7 @@ except ImportError:
try:
UI_FILE = ':/singleEditor.ui'
from asn1_value_editor import asn1Editor
from vn import fromValueNotationToPySide, toASN1ValueNotation
from vn import valueNotationToCTypes
except ImportError:
logger.error('ASN1 Value Editor import error')
sys.exit(1)
......@@ -174,6 +174,7 @@ class SingleValueEditor(QObject):
dataView = asn1scc.parse_asn1([asnFile],
ast_version=asn1scc.ASN1.UniqueEnumeratedNames,
flags=[asn1scc.ASN1.AstOnly])
self.ASN1_AST = dataView.types
except (ImportError, NameError, TypeError) as err:
logger.error('Error loading ASN.1 model')
logger.debug(str(err))
......@@ -261,12 +262,15 @@ class SingleValueEditor(QObject):
widget = self.widgets[param]
# Create a ctypes instance of the variable and set it to the editor
widget['editor'].asn1Instance = getattr(self.asn1ctypes,
asnType.replace('-', '_'))()
instance = getattr(self.asn1ctypes, asnType.replace('-', '_'))()
widget['editor'].asn1Instance = instance
if defValue:
pythonVar = fromValueNotationToPySide(param, defValue)
widget['editor'].updateVariable(pythonVar)
valueNotationToCTypes(gser=defValue,
dest=instance,
sort=self.ASN1_AST[asnType].type,
ASN1Mod=self.asn1ctypes,
ASN1_AST=self.ASN1_AST)
widget['editor'].updateVariable()
return widget
def editValue(self, param, defValue=None):
......@@ -278,8 +282,7 @@ class SingleValueEditor(QObject):
response = widget['widget'].exec_()
if response:
data = widget['editor'].getVariable(dest=widget['editor'].asn1Instance)
value = toASN1ValueNotation(data[param.replace('_', '-')])
return value
return widget['editor'].asn1Instance.GSER()
else:
return None
......
......@@ -216,8 +216,8 @@ def valueNotationToCTypes(gser, dest, sort, ASN1Mod, ASN1_AST, var=None):
gser : input GSER string
dest : output ctypes instance to be filled
ASN1Mod : python module containing ctypes DV access
sort: ASN1 typename, with dashes, no underscores
ASN1_AST : AST generated by ASN1SCC
sort: ASN1 type from ASN1_AST
ASN1_AST : AST generated by ASN1SCC (python.stg)
var : optional already pyside-converted GSER string
Outputs:
none - "dest" is modified by this function
......
......@@ -7,17 +7,20 @@ from asn1_value_editor import standalone_editor as editor
editor.logger.setLevel(editor.logging.DEBUG)
'''
Use py.test2.7 to run these tests, and make sure you have installed pytest-qt
Use py.test-2.7 to run these tests, and make sure you have installed pytest-qt
pip install --user pytest-qt
'''
def test_1(qtbot):
''' Test with a single boolean type '''
expected = 'TRUE'
s = editor.SingleValueEditor('data/dv2.asn',
paramsAndTypes={'param': 'Ahah'})
widget = s.setupEdit('Ahah')
print widget['editor'].getVariable(dest=widget['editor'].asn1Instance)
assert s is not None
widget = s.setupEdit('Ahah', defValue=expected)['editor']
widget.getVariable(dest=widget.asn1Instance)
result = widget.asn1Instance.GSER()
print result
assert result == expected
def test_2():
......@@ -25,8 +28,6 @@ def test_2():
assert True
if __name__ == '__main__':
for name, value in dict(globals()).viewitems():
if name.startswith('test_'):
print('---- Executing {} ----'.format(name))
value()
print('---- Done - {} ----\n'.format(name))
print('You must run py.test-2.7 to execute this test script')
print('Make sure you have pytest-qt (pip install --user pytest-qt)')
sys.exit(1)
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