summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorDuncan McGreggor <duncan@ubuntu.com>2011-03-15 08:18:30 -0600
committerDuncan McGreggor <duncan@ubuntu.com>2011-03-15 08:18:30 -0600
commit22e77707560711102873dfc030e109d8ee700958 (patch)
treecba57864d6ca6b8d225366277af47a4d70524bcd /python
parent20922b0473a33e31d55d452e7226e13f5be81c62 (diff)
* Moved testing device creation out of setUp method for easier checking of
device counts. * Filled in unit test for test_create_node. * Added some debugging to tearDown. * Removed some old debugging.
Diffstat (limited to 'python')
-rw-r--r--python/evemu/device.py16
-rw-r--r--python/evemu/tests/test_device.py22
2 files changed, 25 insertions, 13 deletions
diff --git a/python/evemu/device.py b/python/evemu/device.py
index f22446f..4fb0c52 100644
--- a/python/evemu/device.py
+++ b/python/evemu/device.py
@@ -24,7 +24,7 @@ class EvEmuDevice(base.EvEmuBase):
self._new()
except exception.EvEmuError:
self.delete()
- # re-raise the exception with a message
+ # XXX re-raise the exception with a message
def __del__(self):
self.delete()
@@ -35,7 +35,7 @@ class EvEmuDevice(base.EvEmuBase):
os.unlink(self.get_node_name())
def _new(self):
- device_new = self._lib.evemu_new
+ device_new = self.get_lib().evemu_new
device_new.restype = ctypes.c_void_p
# The C API expects a device name to be passed, however, it doesn't do
# anything with it, so we're not going to provide it as an option in
@@ -102,7 +102,7 @@ class EvEmuDevice(base.EvEmuBase):
self.get_c_lib().fopen, device_file, "r")
except exception.EvEmuError:
self.delete()
- # re-raise the exception with a message
+ # XXX re-raise the exception with a message
self._call(
self.get_lib().evemu_read,
self.get_device_pointer(),
@@ -117,22 +117,16 @@ class EvEmuDevice(base.EvEmuBase):
self._uinput_fd = os.open(const.UINPUT_NODE, os.O_WRONLY)
except exception.EvEmuError:
self.delete()
- # re-raise the exception with a message
+ # XXX re-raise the exception with a message
# populate the new node with data from the device pointer
try:
- #import pdb;pdb.set_trace()
self._call(
self.get_lib().evemu_create,
self.get_device_pointer(),
self._uinput_fd)
- # XXX debugging: the attempt below causes a serious memory
- # error... and dump to stdout/stderr when running the tests
- # from the command line
- #ctypes.byref(ctypes.c_long(self._uinput_fd)))
except exception.EvEmuError, e:
- #import pdb;pdb.set_trace()
self.close()
- # re-raise the exception with a message
+ # XXX re-raise the exception with a message
@property
def version(self):
diff --git a/python/evemu/tests/test_device.py b/python/evemu/tests/test_device.py
index eb49b25..0778ec7 100644
--- a/python/evemu/tests/test_device.py
+++ b/python/evemu/tests/test_device.py
@@ -1,6 +1,7 @@
import ctypes
import unittest
+from evemu import util
from evemu.device import EvEmuDevice
from evemu.testing import skip, BaseTestCase
@@ -9,12 +10,26 @@ class EvEmuDeviceTestCase(BaseTestCase):
def setUp(self):
super(EvEmuDeviceTestCase, self).setUp()
+ self.device = None
+
+ def create_testing_device(self):
+ """
+ This is a conveneince test function for tests that need a device. Have
+ this method be called in each test (as opposed to once in the setUp
+ method) also allows for use to check device counts before and after
+ device creation.
+ """
self.device = EvEmuDevice(self.library)
self.device.create_node(self.get_device_file())
def tearDown(self):
- del(self.device)
+ print "preparing to tear down..."
+ if self.device:
+ # XXX this is where the bomb happens...
+ self.device.destroy()
+ print "preparing to upcall tearDown..."
super(EvEmuDeviceTestCase, self).tearDown()
+ print "finished tear-down."
def test_new(self):
pass
@@ -37,7 +52,10 @@ class EvEmuDeviceTestCase(BaseTestCase):
pass
def test_create_node(self):
- pass
+ device_count_before = len(util.get_all_device_numbers())
+ self.create_testing_device()
+ device_count_after = len(util.get_all_device_numbers())
+ self.assertEqual(device_count_before + 1, device_count_after)
@skip("Not ready yet")
def test_version(self):