[PATCH evemu 10/16] python: drop evemu.const usages for device bits
Peter Hutterer
peter.hutterer at who-t.net
Wed Aug 13 16:40:13 PDT 2014
On Tue, Aug 12, 2014 at 01:48:27PM -0400, Benjamin Tissoires wrote:
> On Mon, Aug 11, 2014 at 9:34 PM, Peter Hutterer
> <peter.hutterer at who-t.net> wrote:
> > 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.
> >
> > This concidentally also fixes test_has_prop() to work as intended.
> >
> > Note that in test_device.py the check against event names is now dropped.
> > Since we're using the same source data now in the test device and the test
> > comparison, there is no point having these extra tests.
>
> git complained about a lot of whitespace damages in this patch. And I
> have to agree.
huh, odd. that all got automatically removed on rebasing but it was still
there in the patch. not sure what happened here, sorry about that.
>
> More comments inlined.
>
> >
> > Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> > ---
> > python/evemu/testing/testcase.py | 33 ++++++++++++--------
> > python/evemu/tests/test_base.py | 1 -
> > python/evemu/tests/test_device.py | 66 +++++++++++----------------------------
> > 3 files changed, 38 insertions(+), 62 deletions(-)
> >
> > diff --git a/python/evemu/testing/testcase.py b/python/evemu/testing/testcase.py
> > index 4cf5310..c83a854 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,59 @@ 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)
> > + propmax = input_prop_get_value("INPUT_PROP_MAX")
> > + keys = range(0, propmax + 1)
> > + return dict.fromkeys(keys, False)
>
> this part has to be squashed in the previous commit
as said in the other email, I just swapped them around to avoid test
breakage. there is an explicit comment that we don't have properties, so we
just return an unset list here.
>
> > 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 3c16871..5ac00fd 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"))
> > -
>
> It took me a while to figure out why this has been removed and why
> this was here in the first place.
> Could you just amend the commit message saying that we do not need to
> test both the event name and the event code because they are
> guaranteed somewhere else?
that's what paragraph 3 in the commit message was supposed to convey, but
I'll reword it.
Cheers,
Peter
> > - 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"))
> > -
>
> ditto
>
> > 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"))
> > -
>
> ditto
>
> > 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"))
> > -
>
> ditto
>
> > 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"))
> > -
> > -
>
> ditto, but this should be squashed into the previous commit.
>
> > 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())
> > -
>
> ditto
>
> > 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)
>
> ditto
>
>
> sigh...
>
> Cheers,
> Benjamin
>
> > + 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