diff options
author | Duncan McGreggor <duncan@canonical.com> | 2011-03-14 18:47:20 -0600 |
---|---|---|
committer | Duncan McGreggor <duncan@canonical.com> | 2011-03-14 18:47:20 -0600 |
commit | c6d0a6be797866dd048b1e114f5d7aece529d520 (patch) | |
tree | 0fb0b600ceab03547800c946ae5740730bb1baec | |
parent | ff5e8eb602ad6335f6d0de5c0318e5a4a4ab2591 (diff) |
* Added a mechanism to the device class for tracking the uinput file
descriptor.
* Cleaned up the commented out code in create_node.
* Divded the util test cases into different test case classes.
* Added more functions to the util module for breaking out the logic better
(more discretely).
* Added tasks to the TODO.
-rw-r--r-- | python/TODO | 28 | ||||
-rw-r--r-- | python/evemu/device.py | 16 | ||||
-rw-r--r-- | python/evemu/tests/test_util.py | 27 | ||||
-rw-r--r-- | python/evemu/tests/test_wrapper.py | 16 | ||||
-rw-r--r-- | python/evemu/util.py | 34 |
5 files changed, 84 insertions, 37 deletions
diff --git a/python/TODO b/python/TODO index d4d8b3c..890efec 100644 --- a/python/TODO +++ b/python/TODO @@ -35,14 +35,26 @@ The script does this: * writes the properties to the device file - MIND-STATE DUMP - =============== +TODO +==== + * passing a string in evemu_new is a vestage of some old C code + - since it's no longer used, let's not expose it in Python + - remove all references to deivce name + - pass a null strig to the c lib under the covers + * rename device_fd to device_pointer + * EvEmuWrapper creates a device in __init__ + - the create() method should check to see if there's a device already + created, and then abort if so... creating one only if it's necessary + + +MIND-STATE DUMP +=============== - * currently working on debuggin why devices aren't being deleted after each - test (instead, they are being deleted once all tests have finished) + * currently working on debugging why devices aren't being deleted after each + test (instead, they are being deleted once all tests have finished) - * tracing through the evemu-device program to identify any logic in the C - that's missing in the Python implementation + * tracing through the evemu-device program to identify any logic in the C + that's missing in the Python implementation - * the reason for the activity of the last bullet point: only the device nam,e - is being written to the devices, not the actual device data + * the reason for the activity of the last bullet point: only the device name + is being written to the devices, not the actual device data diff --git a/python/evemu/device.py b/python/evemu/device.py index 81194e3..cfd247c 100644 --- a/python/evemu/device.py +++ b/python/evemu/device.py @@ -17,12 +17,14 @@ class EvEmuDevice(base.EvEmuBase): self._device = device_new(device_name) self._node = "" self._device_file_stream = None + self._uinput_fd = None def __del__(self): self.get_lib().evemu_delete(self._device) + del(self._device_file_stream) + os.close(self._uinput_fd) if self.get_node_name() and os.path.exists(self.get_node_name()): os.unlink(self.get_node_name()) - del(self._device_file_stream) @property def _as_property_(self): @@ -52,15 +54,9 @@ class EvEmuDevice(base.EvEmuBase): # load device data from the device_file self.read(device_file) # create the node - input_fd = os.open(const.UINPUT_NODE, os.O_WRONLY) - self._call(self.get_lib().evemu_create, self.get_device_fd(), input_fd) - # write the device file to the new node - #source_file = open(device_file) - #dest_file = open(self.get_node_name(), "w") - #dest_file.write(source_file.read()) - #source_file.close() - #dest_file.close() - #os.close(input_fd) + self._input_fd = os.open(const.UINPUT_NODE, os.O_WRONLY) + self._call( + self.get_lib().evemu_create, self.get_device_fd(), self._input_fd) @property def version(self): diff --git a/python/evemu/tests/test_util.py b/python/evemu/tests/test_util.py index 887d7ce..a6c0005 100644 --- a/python/evemu/tests/test_util.py +++ b/python/evemu/tests/test_util.py @@ -4,7 +4,7 @@ from evemu import util from evemu.testing import Non26BaseTestCase -class UtilTestCase(Non26BaseTestCase): +class CommandsTestCase(Non26BaseTestCase): def test_lsinput(self): results = util.lsinput() @@ -14,17 +14,36 @@ class UtilTestCase(Non26BaseTestCase): self.assertIn("product", results) self.assertIn("version", results) + +class DirectoriesTestCase(Non26BaseTestCase): + + def test_get_top_directory(self): + result = util.get_top_directory() + self.assertEqual(result, "evemu") + def test_get_test_directory(self): result = util.get_test_directory() self.assertEqual(result, "evemu/tests") - def test_get_last_device_number(self): - self.assertTrue(isinstance(util.get_last_device_number(), int)) - def test_get_test_module(self): result = util.get_test_module() self.assertEqual(result, "evemu.tests") + +class DevicesTestCase(Non26BaseTestCase): + + def test_get_all_device_numbers(self): + result = util.get_all_device_numbers() + self.assertTrue(result != []) + + def test_get_all_device_names(self): + result = util.get_all_device_names() + print result + self.assertTrue(result != []) + + def test_get_last_device_number(self): + self.assertTrue(isinstance(util.get_last_device_number(), int)) + def test_get_last_device(self): result = util.get_last_device() self.assertIn("/dev/input/event", result) diff --git a/python/evemu/tests/test_wrapper.py b/python/evemu/tests/test_wrapper.py index 4e1abf8..3f7aed2 100644 --- a/python/evemu/tests/test_wrapper.py +++ b/python/evemu/tests/test_wrapper.py @@ -15,6 +15,16 @@ class EvEmuWrapperTestCase(BaseTestCase): self.assertTrue(self.wrapper.device is not None) self.assertTrue(self.wrapper.get_device() is not None) + def test_create_already_created(self): + pass + + def test_create(self): + result = self.wrapper.create(self.get_device_file()) + device_list = util.lsinput() + device_list2 = util.get_all_device_names() + import pdb;pdb.set_trace() + self.assertTrue("N-Trig-MultiTouch Virtual Device" in device_list) + @skip("Not ready yet") def test_read(self): # hrm... not sure if I should be reading from the device file or @@ -22,12 +32,6 @@ class EvEmuWrapperTestCase(BaseTestCase): result = self.wrapper.read(self.get_device_file()) # XXX need to do checks against the result - @skip("Problem with Python2.6") - def test_create(self): - result = self.wrapper.create(self.get_device_file()) - device_list = util.lsinput() - self.assertTrue(self.device_name in device_list) - @skip("Not ready yet") def test_extract(self): result = self.wrapper.extract(self.get_device_file()) diff --git a/python/evemu/util.py b/python/evemu/util.py index d5fab3c..3de2f9a 100644 --- a/python/evemu/util.py +++ b/python/evemu/util.py @@ -17,28 +17,44 @@ def lsinput(): return output -def get_test_directory(): - from evemu import tests - return tests.__path__[0] - - def get_top_directory(): import evemu return evemu.__path__[0] +def get_test_directory(): + from evemu import tests + return tests.__path__[0] + + def get_test_module(): return get_test_directory().replace("/", ".") +def get_all_device_numbers(): + numbers = [] + for index in xrange(const.MAX_EVENT_NODE): + path = const.DEVICE_PATH_TEMPLATE % index + if os.path.exists(path): + continue + numbers.append(index) + return numbers + + +def get_all_device_names(): + names = [] + for device_number in get_all_device_numbers(): + file_handle = open(const.DEVICE_NAME_PATH_TEMPLATE % device_number) + names.append({"name": file_handle.read(), "id": device_number}) + file_handle.close() + return names + + def get_last_device_number(): """ Get the last used device node number. """ - for index in xrange(const.MAX_EVENT_NODE): - path = const.DEVICE_PATH_TEMPLATE % index - if not os.path.exists(path): - return index-1 + return get_all_device_numbers()[0] def get_last_device(): |