[PATCH v2 evemu 10/16] python: drop evemu.const usages for device bits

Peter Hutterer peter.hutterer at who-t.net
Wed Aug 13 16:45:26 PDT 2014


We have make-event-names.py that generates the required mappings, there is no
need for having a hand-updated file around that provides some of these
constants.

Previously we compared the event names as well as the event values in
test_case.py. That was useful when we were using two different sources
(event_names.py and the hand-maintained const.py). Now we generate the dicts
from the same source. We have separate tests for evemu.event_get_(value|name)
so we don't need the this extra comparison against the names in test_get_abs_*
and friends anymore.

Special note on get_expected_propbits(): we previously returned a dict with
the absolute axes as keys. This is fixed here, we now return a dict with the
actual property bits as keys. Since all values were always False and both
absbits and propbits are just numbers this never got noticed before.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
Changes to v1:
- de-whitespace-error-ified
- reworded commit message
- expanded the comment for the empty proplist

Patch should be applied before 09/16:
    python: fix evemu.Device.has_prop() for string arguments

 python/evemu/testing/testcase.py  | 36 ++++++++++++---------
 python/evemu/tests/test_base.py   |  1 -
 python/evemu/tests/test_device.py | 66 +++++++++++----------------------------
 3 files changed, 40 insertions(+), 63 deletions(-)

diff --git a/python/evemu/testing/testcase.py b/python/evemu/testing/testcase.py
index 4cf5310..ae77e61 100644
--- a/python/evemu/testing/testcase.py
+++ b/python/evemu/testing/testcase.py
@@ -1,8 +1,8 @@
 import os
 import unittest
 
-import evemu.const
 import evemu.exception
+from evemu import event_get_name, event_get_value, input_prop_get_value, input_prop_get_name
 
 def get_top_directory():
     import evemu
@@ -61,52 +61,60 @@ class BaseTestCase(unittest.TestCase):
 
     _expected_abs_ntrig_dell_xt2 = {
             # A: 00 0 9600 75 0 0
-            evemu.const.absolute_axes["ABS_X"]:
+            evemu.event_get_value("EV_ABS", "ABS_X"):
                 {"min": 0, "max": 9600, "fuzz": 75, "flat": 0, "res": 0},
             # A: 01 0 7200 78 0 0
-            evemu.const.absolute_axes["ABS_Y"]:
+            evemu.event_get_value("EV_ABS", "ABS_Y"):
                 {"min": 0, "max": 7200, "fuzz": 78, "flat": 0, "res": 0},
             # A: 30 0 9600 200 0 0
-            evemu.const.absolute_axes["ABS_MT_TOUCH_MAJOR"]:
+            evemu.event_get_value("EV_ABS", "ABS_MT_TOUCH_MAJOR"):
                 {"min": 0, "max": 9600, "fuzz": 200, "flat": 0, "res": 0},
             # A: 31 0 7200 150 0 0
-            evemu.const.absolute_axes["ABS_MT_TOUCH_MINOR"]:
+            evemu.event_get_value("EV_ABS", "ABS_MT_TOUCH_MINOR"):
                 {"min": 0, "max": 7200, "fuzz": 150, "flat": 0, "res": 0},
             # A: 34 0 1 0 0 0
-            evemu.const.absolute_axes["ABS_MT_ORIENTATION"]:
+            evemu.event_get_value("EV_ABS", "ABS_MT_ORIENTATION"):
                 {"min": 0, "max": 1, "fuzz": 0, "flat": 0, "res": 0},
             # A: 35 0 9600 75 0 0
-            evemu.const.absolute_axes["ABS_MT_POSITION_X"]:
+            evemu.event_get_value("EV_ABS", "ABS_MT_POSITION_X"):
                 {"min": 0, "max": 9600, "fuzz": 75, "flat": 0, "res": 0},
             # A: 36 0 7200 78 0 0
-            evemu.const.absolute_axes["ABS_MT_POSITION_Y"]:
+            evemu.event_get_value("EV_ABS", "ABS_MT_POSITION_Y"):
                 {"min": 0, "max": 7200, "fuzz": 78,  "flat": 0, "res": 0}
             }
     _expected_key_ntrig_dell_xt2 = {
-            evemu.const.buttons["BTN_TOUCH"]: True
+            evemu.event_get_value("EV_KEY", "BTN_TOUCH"): True
             }
 
     def get_expected_abs(self, sub_key):
         expected_items = self._expected_abs_ntrig_dell_xt2.items()
-        expected = dict.fromkeys(evemu.const.absolute_axes.values(), 0)
+
+        absmax = event_get_value("EV_ABS", "ABS_MAX")
+        expected = dict.fromkeys(range(0, absmax + 1), 0)
         expected.update((k, v[sub_key]) for (k, v) in expected_items)
 
         return expected
 
     def get_expected_absbits(self):
         expected_keys = self._expected_abs_ntrig_dell_xt2.keys()
-        expected = dict.fromkeys(evemu.const.absolute_axes.values(), False)
+
+        absmax = event_get_value("EV_ABS", "ABS_MAX")
+        expected = dict.fromkeys(range(0, absmax + 1), False)
         expected.update((k, True) for k in expected_keys)
 
         return expected
 
     def get_expected_keybits(self):
         expected_keys = self._expected_key_ntrig_dell_xt2.keys()
-        expected = dict.fromkeys(evemu.const.buttons.values(), False)
+        keymax = event_get_value("EV_KEY", "KEY_MAX")
+        expected = dict.fromkeys(range(0, keymax + 1), False)
         expected.update((k, True) for k in expected_keys)
 
         return expected
 
     def get_expected_propbits(self):
-        # no props for N-Trig-MultiTouch-Virtual-Device
-        return dict.fromkeys(evemu.const.absolute_axes.values(), False)
+        # no props for N-Trig-MultiTouch-Virtual-Device, so we
+        # return a dict with all keys on False
+        propmax = input_prop_get_value("INPUT_PROP_MAX")
+        keys = range(0, propmax + 1)
+        return dict.fromkeys(keys, False)
diff --git a/python/evemu/tests/test_base.py b/python/evemu/tests/test_base.py
index bc35c73..78ac6be 100644
--- a/python/evemu/tests/test_base.py
+++ b/python/evemu/tests/test_base.py
@@ -1,7 +1,6 @@
 import unittest
 
 import evemu.base
-import evemu.const
 import evemu.testing.testcase
 
 
diff --git a/python/evemu/tests/test_device.py b/python/evemu/tests/test_device.py
index cb99044..ed8011d 100644
--- a/python/evemu/tests/test_device.py
+++ b/python/evemu/tests/test_device.py
@@ -178,88 +178,58 @@ class DevicePropertiesTestCase(evemu.testing.testcase.BaseTestCase):
         self.assertEqual(self._device.id_version, 272)
 
     def test_get_abs_minimum(self):
-        keys = evemu.const.absolute_axes.values()
+        absmax = evemu.event_get_value("EV_ABS", "ABS_MAX")
+        keys = range(0, absmax + 1)
         results = dict((x, self._device.get_abs_minimum(x)) for x in keys)
 
         self.assertEqual(results, self.get_expected_abs("min"))
 
-        keys = evemu.const.absolute_axes.keys()
-        results = dict((evemu.event_get_value("EV_ABS", x), self._device.get_abs_minimum(x)) for x in keys)
-
-        self.assertEqual(results, self.get_expected_abs("min"))
-
     def test_get_abs_maximum(self):
-        keys = evemu.const.absolute_axes.values()
+        absmax = evemu.event_get_value("EV_ABS", "ABS_MAX")
+        keys = range(0, absmax + 1)
         results = dict((x, self._device.get_abs_maximum(x)) for x in keys)
 
         self.assertEqual(results, self.get_expected_abs("max"))
 
-        keys = evemu.const.absolute_axes.keys()
-        results = dict((evemu.event_get_value("EV_ABS", x), self._device.get_abs_maximum(x)) for x in keys)
-
-        self.assertEqual(results, self.get_expected_abs("max"))
-
     def test_get_abs_fuzz(self):
-        keys = evemu.const.absolute_axes.values()
+        absmax = evemu.event_get_value("EV_ABS", "ABS_MAX")
+        keys = range(0, absmax + 1)
         results = dict((x, self._device.get_abs_fuzz(x)) for x in keys)
 
         self.assertEqual(results, self.get_expected_abs("fuzz"))
 
-        keys = evemu.const.absolute_axes.keys()
-        results = dict((evemu.event_get_value("EV_ABS", x), self._device.get_abs_fuzz(x)) for x in keys)
-
-        self.assertEqual(results, self.get_expected_abs("fuzz"))
-
     def test_get_abs_flat(self):
-        keys = evemu.const.absolute_axes.values()
+        absmax = evemu.event_get_value("EV_ABS", "ABS_MAX")
+        keys = range(0, absmax + 1)
         results = dict((x, self._device.get_abs_flat(x)) for x in keys)
 
         self.assertEqual(results, self.get_expected_abs("flat"))
 
-        keys = evemu.const.absolute_axes.keys()
-        results = dict((evemu.event_get_value("EV_ABS", x), self._device.get_abs_flat(x)) for x in keys)
-
-        self.assertEqual(results, self.get_expected_abs("flat"))
-
     def test_get_abs_resolution(self):
-        keys = evemu.const.absolute_axes.values()
+        absmax = evemu.event_get_value("EV_ABS", "ABS_MAX")
+        keys = range(0, absmax + 1)
         results = dict((x, self._device.get_abs_resolution(x)) for x in keys)
 
         self.assertEqual(results, self.get_expected_abs("res"))
 
-        keys = evemu.const.absolute_axes.keys()
-        results = dict((evemu.event_get_value("EV_ABS", x), self._device.get_abs_resolution(x)) for x in keys)
-
-        self.assertEqual(results, self.get_expected_abs("res"))
-
-
     def test_has_prop(self):
-        keys = evemu.const.absolute_axes.values()
+        propmax = evemu.input_prop_get_value("INPUT_PROP_MAX")
+        keys = range(0, propmax + 1)
         results = dict((x, self._device.has_prop(x)) for x in keys)
 
         self.assertEqual(results, self.get_expected_propbits())
 
-        keys = evemu.const.absolute_axes.keys()
-        results = dict((evemu.event_get_value("EV_ABS", x), self._device.has_prop(x)) for x in keys)
-
-        self.assertEqual(results, self.get_expected_propbits())
-
     def test_has_event_ev_abs(self):
-        ev_abs = evemu.const.event_types["EV_ABS"]
-        keys = evemu.const.absolute_axes.values()
-        results = dict((x, self._device.has_event(ev_abs, x)) for x in keys)
+        absmax = evemu.event_get_value("EV_ABS", "ABS_MAX")
+        keys = range(0, absmax + 1)
+        results = dict((x, self._device.has_event("EV_ABS", x)) for x in keys)
 
         self.assertEqual(results, self.get_expected_absbits())
 
     def test_has_event_ev_key(self):
-        ev_key = evemu.const.event_types["EV_KEY"]
-        keys = evemu.const.buttons.values()
-        results = dict((x, self._device.has_event(ev_key, x)) for x in keys)
-
-        self.assertEqual(results, self.get_expected_keybits())
-
-        keys = evemu.const.buttons.keys()
-        results = dict((evemu.event_get_value("EV_KEY", x), self._device.has_event("EV_KEY", x)) for x in keys)
+        keymax = evemu.event_get_value("EV_KEY", "KEY_MAX")
+        keys = range(0, keymax + 1)
+        results = dict((x, self._device.has_event("EV_KEY", x)) for x in keys)
 
         self.assertEqual(results, self.get_expected_keybits())
 
-- 
1.9.3



More information about the Input-tools mailing list