Basic structure of unit tests

This commit is contained in:
slush 2012-11-15 20:05:57 +00:00
parent 05a15eaf7d
commit b6106fa681
4 changed files with 55 additions and 6 deletions

10
tests/config.py Normal file
View File

@ -0,0 +1,10 @@
import sys
sys.path = ['../',] + sys.path
from bitkeylib.transport_pipe import PipeTransport
TRANSPORT = PipeTransport
TRANSPORT_ARGS = ('../../bitkey-python/device.socket', False)
DEBUG_TRANSPORT = PipeTransport
DEBUG_TRANSPORT_ARGS = ('../../bitkey-python/device.socket.debug', False)

3
tests/run.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
python -m unittest discover

View File

@ -1,20 +1,37 @@
#!/usr/bin/python
'''
import sys
sys.path = ['../',] + sys.path
import time
ENABLE_DEBUG_LINK = True
from bitkeylib.transport_pipe import PipeTransport
from bitkeylib.transport_serial import SerialTransport
import bitkeylib.bitkey_pb2 as proto
from bitkeylib.transport_fake import FakeTransport
from bitkeylib import proto
from bitkeylib.client import BitkeyClient
from bitkeylib.debuglink import DebugLink
bitkey = BitkeyClient('../../bitkey-python/device.socket', debug=True)
bitkey.open()
bitkey.call(proto.Ping(message='ahoj!'))
bitkey.call(proto.SetMaxFeeKb(maxfee_kb=200000))
bitkey.close()
transport = PipeTransport('../../bitkey-python/device.socket', is_device=False)
if ENABLE_DEBUG_LINK:
debug_transport = PipeTransport('../../bitkey-python/device.socket.debug', is_device=False)
debuglink = DebugLink(debug_transport)
else:
debuglink = None
bitkey = BitkeyClient(transport, debuglink)
print bitkey.call(proto.Initialize())
#bitkey.call(proto.Ping(message='ahoj!'))
#bitkey.call(proto.GetUUID())
print bitkey.call(proto.GetEntropy(size=10), button=True)
bitkey.call(proto.SetMaxFeeKb(maxfee_kb=100000), button=True, pin_correct=False)
'''
'''
d = PipeTransport('../bitkey-python/device.socket', is_device=False)

19
tests/test_basic.py Normal file
View File

@ -0,0 +1,19 @@
import unittest
import config
from bitkeylib.client import BitkeyClient
from bitkeylib import proto
class TestBasic(unittest.TestCase):
def setUp(self):
self.debuglink = config.DEBUG_TRANSPORT(*config.DEBUG_TRANSPORT_ARGS)
self.transport = config.TRANSPORT(*config.TRANSPORT_ARGS)
self.bitkey = BitkeyClient(self.transport, self.debuglink)
def tearDown(self):
self.debuglink.close()
self.transport.close()
def test_basic(self):
self.assertEqual(self.bitkey.call(proto.Ping(message='ahoj!')), proto.Success(message='ahoj!'))