Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
description = 'ASN.1 code generator for Python and C',
scripts = ['scripts/tinyber_gen', 'scripts/dax'],
package_data = {
'tinyber': ['data/*.[ch]', 'tinyber/codec.py'],
'tests': ['*.asn1'],
'tinyber': ['data/*.[ch]', 'tinyber/codec.py',],
'tests': ['*.asn1', 'coverage/t0_wrap.pyx'],
},
ext_modules = exts,
test_suite = "tests",
Expand Down
47 changes: 0 additions & 47 deletions test/run_tests.py

This file was deleted.

14 changes: 0 additions & 14 deletions test/setup.py

This file was deleted.

34 changes: 0 additions & 34 deletions test/t0.py

This file was deleted.

40 changes: 0 additions & 40 deletions test/t0_c_test.py

This file was deleted.

2 changes: 2 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- Mode: Python -*-

File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions tests/coverage/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# build t0_wrap.pyx before doing any of the other tests.

from tests.utils import generate_c, generate_py, test_reload

print 'building from __init__ script...'
generate_c ('tests/coverage/t0.asn', 't0', 'tests/coverage')
from distutils.core import run_setup
run_setup ('tests/coverage/setup.py', ['build_ext', '--inplace'])

generate_py ('tests/coverage/t0.asn', 't0', 'tests/coverage')
File renamed without changes.
39 changes: 39 additions & 0 deletions tests/coverage/old/t0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- Mode: Python; indent-tabs-mode: nil -*-

def test():

from t0_ber import *

def HD(s):
return s.decode ('hex')

data = HD('300602016302016e')
p = Pair()
p.decode (data)
print p.encode().encode('hex')

tests = [
HD('6110300e020203e90101ff30003003020101'),
HD('611230100204400000000101ff30003003020101'),
HD('6110300e020203e901010030003003020101'),
HD('61133011020203e901010030003006020101020102'),
HD('61133011020203e901010030030101ff3003020101'),
HD('61163014020203e901010030060101ff0101003003020101'),
HD('603c303a040361626302013202022711020417bc927a3020300602010a020165300602010a020165300602010a020165300602010a0201650101000a0100'),
HD('603c303a040361626302013302022711020417bc927a3020300602010a020165300602010a020165300602010a020165300602010a0201650101000a0100'),
HD('603c303a040361626302013402022711020417bc927a3020300602010a020165300602010a020165300602010a020165300602010a0201650101ff0a0100'),
HD('603c303a040361626302013202022711020417bc927a3020300602010a020165300602010a020165300602010a020165300602010a0201650101000a0101'),
HD('603c303a040361626302013302022711020417bc927a3020300602010a020165300602010a020165300602010a020165300602010a0201650101000a0101'),
HD('603c303a040361626302013402022711020417bc927a3020300602010a020165300602010a020165300602010a020165300602010a0201650101ff0a0101'),
HD('603c303a040361626302013202022711020417bc927a3020300602010a020165300602010a020165300602010a020165300602010a0201650101000a0102'),
HD('603c303a040361626302013302022711020417bc927a3020300602010a020165300602010a020165300602010a020165300602010a0201650101000a0102'),
HD('603c303a040361626302013402022711020417bc927a3020300602010a020165300602010a020165300602010a020165300602010a0201650101ff0a0102'),
]

for data in tests:
m = ThingMsg()
m.decode (data)
print m.value

if __name__ == '__main__':
test()
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from coro.asn1.ber import *
from t0_ber import ThingMsg
from t0_gen_test import gen_thingmsg
from t0_gen_cases import gen_thingmsg

def try_decode (val):
try:
Expand Down
File renamed without changes.
27 changes: 27 additions & 0 deletions tests/coverage/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize

exts = [
Extension ("t0_wrap", ['t0_wrap.pyx', 't0.c', 'tinyber.c'])
]

# this is a complete hack to try to get unittest to work with this
# generated module, and avoid trying to compile it more than once (in
# the wrong place).

import os
if 't0_wrap.so' in os.listdir ('tests/coverage'):
pass
else:
import os
here = os.getcwd()
src, _ = os.path.split (__file__)
os.chdir (src)
try:
setup (
ext_modules = cythonize (exts),
)
finally:
os.chdir (here)

12 changes: 9 additions & 3 deletions test/t0.asn → tests/coverage/t0.asn
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
-- -*- Mode: asn1; indent-tabs-mode: nil -*-

-- test module meant to exercise all supported features of tinyber_gen.py
-- test module meant to exercise all supported features of tinyber's code generators.

ThingModule DEFINITIONS ::= BEGIN

StringThing ::= OCTET STRING SIZE (5)

ThingMsg ::= CHOICE {
msg-a [0] MsgA,
msg-b [1] MsgB,
msg-c [50] MsgC
msg-b [1] MsgB,
msg-c [50] MsgC,
msg-d [2] MsgD
}

Pair ::= SEQUENCE {
Expand Down Expand Up @@ -46,5 +47,10 @@ ThingModule DEFINITIONS ::= BEGIN
tbool BOOLEAN
}

MsgD ::= SEQUENCE {
-- test negative ranges --
x INTEGER (-10..10),
y INTEGER (-10..-5)
}

END
38 changes: 38 additions & 0 deletions tests/coverage/t0_c_driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- Mode: Python -*-

# run the auto-generated tests on the C codec.

import unittest

from tests.coverage.t0_gen_cases import gen_thingmsg
from tests.utils import test_reload, generate_c

class ExpectedGood (Exception):
pass
class ExpectedBad (Exception):
pass
class BadEncoding (Exception):
pass

class TestBasic(unittest.TestCase):

def test_c_coverage (self):
# this is disgusting, but "from tests.coverage.t0_wrap" does not work here.
test_reload()
import sys
sys.path.append ('tests/coverage')
from t0_wrap import try_decode
for tval, good in gen_thingmsg():
#print tval.encode ('hex'), good
r = try_decode (tval)
if not good:
# it should have been bad, but wasn't.
self.assertEqual (r, -1)
else:
self.assertNotEqual (r, -1, msg=tval)
self.assertEqual (r, tval)

if __name__ == '__main__':
unittest.main()


Loading