test_standalone.py 2.82 KB
Newer Older
Maxime Perrotin's avatar
Maxime Perrotin committed
1
2
3
4
5
6
#!/usr/bin/env python

import sys

sys.path.insert(0, '../..')
from asn1_value_editor import standalone_editor as editor
7
from asn1_value_editor.vn import format_gser
Maxime Perrotin's avatar
Maxime Perrotin committed
8
9
editor.logger.setLevel(editor.logging.DEBUG)

10
'''
Maxime Perrotin's avatar
Maxime Perrotin committed
11
Use py.test-2.7 to run these tests, and make sure you have installed pytest-qt
12
13
14
pip install --user pytest-qt
'''

Maxime Perrotin's avatar
Maxime Perrotin committed
15
16
17
TEST = editor.SingleValueEditor('data/dv1.asn')

def common(typeName, defValue):
Maxime Perrotin's avatar
Maxime Perrotin committed
18
    ''' Set up test case: create asn1 editor and fill with default value '''
Maxime Perrotin's avatar
Maxime Perrotin committed
19
    widget = TEST.setupEdit(typeName, defValue=defValue)['editor']
Maxime Perrotin's avatar
Maxime Perrotin committed
20
21
22
23
24
25
    # Create a new type instance to put the result, so that we make sure
    # that the result value is really taken from the ASN.1 editor
    dest_instance = getattr(TEST.asn1ctypes, typeName.replace('-', '_'))()
    widget.getVariable(dest=dest_instance)
    assert widget.asn1Instance.GSER() == dest_instance.GSER()
    return dest_instance.GSER()
Maxime Perrotin's avatar
Maxime Perrotin committed
26

Maxime Perrotin's avatar
Maxime Perrotin committed
27
28
def test_bool(qtbot):
    ''' Test boolean values '''
29
    typeName = "Type-SingleBool"
Maxime Perrotin's avatar
Maxime Perrotin committed
30
    defValue = 'TRUE'
Maxime Perrotin's avatar
Maxime Perrotin committed
31
    result = common(typeName, defValue)
Maxime Perrotin's avatar
Maxime Perrotin committed
32
    assert result == defValue
33

Maxime Perrotin's avatar
Maxime Perrotin committed
34
    defValue = 'FALSE'
Maxime Perrotin's avatar
Maxime Perrotin committed
35
    result = common(typeName, defValue)
Maxime Perrotin's avatar
Maxime Perrotin committed
36
37
    assert result == defValue

Maxime Perrotin's avatar
Maxime Perrotin committed
38
39
def test_int(qtbot):
    ''' Test integer value '''
Maxime Perrotin's avatar
Maxime Perrotin committed
40
41
    typeName = "Type-SingleInt"
    defValue = '42'
Maxime Perrotin's avatar
Maxime Perrotin committed
42
    result = common(typeName, defValue)
Maxime Perrotin's avatar
Maxime Perrotin committed
43
    assert result == defValue
Maxime Perrotin's avatar
Maxime Perrotin committed
44

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def test_real(qtbot):
    ''' Test float value '''
    typeName = "Type-SingleReal"
    defValue = '1.25'
    result = common(typeName, defValue)
    assert result == defValue

def test_enum(qtbot):
    ''' Test enumerated value '''
    typeName = "Type-SingleEnum"
    defValue = 'enum-one'
    result = common(typeName, defValue)
    assert result == defValue

    defValue = 'enum-two'
    result = common(typeName, defValue)
    assert result == defValue

def test_string(qtbot):
    ''' Test octet string value '''
    typeName = "Type-SingleString"
    defValue = '"Hello, world"'
    result = common(typeName, defValue)
    assert result == defValue

Maxime Perrotin's avatar
Maxime Perrotin committed
70
def test_simpleseq(qtbot):
Maxime Perrotin's avatar
Maxime Perrotin committed
71
72
    ''' Test SEQUENCE '''
    typeName = "Type-SimpleSeq"
73
    defValue = '{item-a 42, item-b TRUE, item-c enum-two, item-d "Hello world"}'
Maxime Perrotin's avatar
Maxime Perrotin committed
74
    result = common(typeName, defValue)
75
    assert format_gser(result) == format_gser(defValue)
Maxime Perrotin's avatar
Maxime Perrotin committed
76

Maxime Perrotin's avatar
Maxime Perrotin committed
77
78
79
def test_simplechoice(qtbot):
    ''' Test CHOICE '''
    typeName = "Type-SingleChoice"
80
    defValue = 'choice-b: TRUE'
Maxime Perrotin's avatar
Maxime Perrotin committed
81
    result = common(typeName, defValue)
82
    assert format_gser(result) == format_gser(defValue)
Maxime Perrotin's avatar
Maxime Perrotin committed
83
84
85
86

def test_simpleseqof(qtbot):
    ''' Test SEQOF '''
    typeName = "Type-SingleSeqOf"
87
    defValue = '{1, 2, 3, 4, 5}'
Maxime Perrotin's avatar
Maxime Perrotin committed
88
    result = common(typeName, defValue)
89
    assert format_gser(result) == format_gser(defValue)
Maxime Perrotin's avatar
Maxime Perrotin committed
90

Maxime Perrotin's avatar
Maxime Perrotin committed
91
if __name__ == '__main__':
Maxime Perrotin's avatar
Maxime Perrotin committed
92
93
94
    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)