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

import sys

sys.path.insert(0, '../..')
from asn1_value_editor import standalone_editor as editor
editor.logger.setLevel(editor.logging.DEBUG)

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

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

def common(typeName, defValue):
Maxime Perrotin's avatar
Maxime Perrotin committed
17
    ''' Set up test case: create asn1 editor and fill with default value '''
Maxime Perrotin's avatar
Maxime Perrotin committed
18
    widget = TEST.setupEdit(typeName, defValue=defValue)['editor']
19
    widget.getVariable(dest=widget.asn1Instance)
Maxime Perrotin's avatar
Maxime Perrotin committed
20
21
    return widget.asn1Instance.GSER()

Maxime Perrotin's avatar
Maxime Perrotin committed
22
23
def test_bool(qtbot):
    ''' Test boolean values '''
24
    typeName = "Type-SingleBool"
Maxime Perrotin's avatar
Maxime Perrotin committed
25
    defValue = 'TRUE'
Maxime Perrotin's avatar
Maxime Perrotin committed
26
    result = common(typeName, defValue)
Maxime Perrotin's avatar
Maxime Perrotin committed
27
    assert result == defValue
28

Maxime Perrotin's avatar
Maxime Perrotin committed
29
    defValue = 'FALSE'
Maxime Perrotin's avatar
Maxime Perrotin committed
30
    result = common(typeName, defValue)
Maxime Perrotin's avatar
Maxime Perrotin committed
31
32
    assert result == defValue

Maxime Perrotin's avatar
Maxime Perrotin committed
33
34
def test_int(qtbot):
    ''' Test integer value '''
Maxime Perrotin's avatar
Maxime Perrotin committed
35
36
    typeName = "Type-SingleInt"
    defValue = '42'
Maxime Perrotin's avatar
Maxime Perrotin committed
37
    result = common(typeName, defValue)
Maxime Perrotin's avatar
Maxime Perrotin committed
38
    assert result == defValue
Maxime Perrotin's avatar
Maxime Perrotin committed
39

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
65
66
67
68
69
70
71
def test_seq(qtbot):
    ''' Test SEQUENCE '''
    typeName = "Type-SimpleSeq"
    defValue = '{ item-a   42 ,  item-b   TRUE ,  item-c   enum-two ,  item-d   "Hello world" }'
    result = common(typeName, defValue)
    assert result == defValue

Maxime Perrotin's avatar
Maxime Perrotin committed
72
if __name__ == '__main__':
Maxime Perrotin's avatar
Maxime Perrotin committed
73
74
75
    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)