Make it possible to overwrite python binary via env

This makes it possible to overwrite the python binary to use via the
environment variable PYTHON.

That's usefull when testing the code with different python binaries,
i.e.:
    PYTHON=/usr/bin/python2.7 ./configure
or
    make PYTHON=/usr/bin/python3.3 check

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
py: Replace print statement with function call

In Python 3 backward compatibility for the print statement has been
removed. Replace it with the function call.

Additionally, add
    from __future__ import print_function
to make sure the statement is disabled and the function is used for
Python versions <3.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
py: Don't use find_library for libevemu.so

The current mechanism to find libevemu.so prefered a system wide
installed version and if found it ignored the in tree build one.
That's bad for running the tests as they should be performed on the in
tree build library.

So, don't use find_library for libevemu.so and let CDLL do its job. It
even takes LD_LIBRARY_PATH into account, which find_library doesn't.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
tests: Replace tab with spaces

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
py: Raise statement takes one argument

Before Python 3 the exception message could've been passed as a second
argument to the raise statement. This is no longer the case and the
message has to be an argument on the exception. Adjust for that
incompatible change.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
py: Fix file opening

The device node is the only file that needs to be opened in binary mode
and we've to open other "device" files (like prop files) in text mode.
Otherwise lots of conversions from bytes objects to str will be
necessary as Python 3 handles them differently.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
py: Fix file object detection

Python 3 uses different classes for opened text and binary files.
Therefore a test on __name__ would need to cover more (i.e.
BufferedReader and TextIOWrapper). But, we just want to read from the
file objects and a test for the attribute "read" is sufficient and even
more generic.

Additionally, just check if the type of an object is str and not if its
__name__ is "str".

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
tests: Open temporary device file in text mode

Open the temporary device file in text mode. Otherwise, conversions from
bytes to str objects will be necessary before passing the data to
strip_comments().
It even gets opened in read-only mode as this side just reads from the
file. It gets opened somewhere else for writing.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
tests: Fix tests with fixed lists

Comparing a fixed list of values with a list of values which have been
computed out of an _unordered_ dictionary is a bad idea. A simple fix
would've been to use an OrderedDict.

Instead, replace the fixed lists of values with descriptive dictionaries
and use those dictionaries to generate the expected values in tests for
the comparisions.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>

Renamed get_expected_ev_abs into get_expected_absbits
Renamed get_expected_ev_key into get_expected_keybits
Renamed get_expected_prop into get_expected_propbits

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
py: Change has_prop() and has_event() to return bool

Change has_prop() and has_event() to return a bool instead of an int
coming from the library call.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
py: Remove unused constants from const.py

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
py: Generate complete dicts in event_names.py

Before, the generated dictionaries in event_names.py just had the bits
to name mapping and a loop to add the name to bits mapping using items()
afterwards. As of Python 3 items() returns a view, not a copy, resulting
in an error as the dictionary was modified in place.

Now, generate both the bits to name and name to bits mapping when
creating event_names.py and make the loop obsolete.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
py: Cleanup imports, make attr usage more obvious

Remove unused imports and sort the remaining ones. Additionally, replace
nearly all "from ... import ..." with simple imports, making it more
obvious where attributes came from, i.e.:
    find_library() vs. ctypes.util.find_library() or
    exception.ExecutionError() vs. evemu.exception.ExecutionError().

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>

fix conflict due to removal of one patch in the series

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
tests: Compare vendor id with int not str

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Make evemu_play_one() return negative value on error

Bring evemu_play_one() in line with other functions and return a
negative value on error rather then a positive.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>