test_standalone.py 1.41 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
17
def common(asn1File, typeName, defValue):
    ''' Set up test case: create asn1 editor and fill with default value '''
    s = editor.SingleValueEditor(asn1File, paramsAndTypes={'param': typeName})
    widget = s.setupEdit(typeName, defValue=defValue)['editor']
18
    widget.getVariable(dest=widget.asn1Instance)
Maxime Perrotin's avatar
Maxime Perrotin committed
19
20
21
22
23
24
25
26
    return widget.asn1Instance.GSER()

def test_true(qtbot):
    ''' Most basic test: single boolean type '''
    typeName = "Ahah"
    defValue = 'TRUE'
    result = common('data/dv2.asn', typeName, defValue)
    assert result == defValue
27
28
29

def test_false(qtbot):
    ''' Test with a single boolean type '''
Maxime Perrotin's avatar
Maxime Perrotin committed
30
31
32
33
34
35
36
37
38
39
40
    typeName = "Ahah"
    defValue = 'FALSE'
    result = common('data/dv2.asn', typeName, defValue)
    assert result == defValue

def test_alltypes(qtbot):
    ''' More complete test with various types/editors '''
    typeName = "Type-SingleInt"
    defValue = '42'
    result = common('data/dv1.asn', typeName, defValue)
    assert result == defValue
Maxime Perrotin's avatar
Maxime Perrotin committed
41
42
43


if __name__ == '__main__':
Maxime Perrotin's avatar
Maxime Perrotin committed
44
45
46
    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)