Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
asn1-value-editor
Commits
24bfd011
Commit
24bfd011
authored
Jul 16, 2016
by
Maxime Perrotin
Browse files
First test case success!
parent
b57e42df
Changes
3
Hide whitespace changes
Inline
Side-by-side
asn1_value_editor/standalone_editor.py
View file @
24bfd011
...
...
@@ -61,7 +61,7 @@ except ImportError:
try
:
UI_FILE
=
':/singleEditor.ui'
from
asn1_value_editor
import
asn1Editor
from
vn
import
fromV
alueNotationTo
PySide
,
toASN1ValueNotation
from
vn
import
v
alueNotationTo
CTypes
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
...
...
asn1_value_editor/vn.py
View file @
24bfd011
...
...
@@ -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 type
name, 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
...
...
test/pytest/test_standalone.py
View file @
24bfd011
...
...
@@ -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
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment