|
1 | 1 | # encoding: utf-8 |
2 | 2 |
|
3 | 3 | from select import select |
4 | | -from pytest import raises |
| 4 | +from pytest import raises, fixture |
5 | 5 |
|
6 | 6 | from evdev import uinput, ecodes, events, device, util |
7 | 7 |
|
8 | 8 |
|
| 9 | +#----------------------------------------------------------------------------- |
9 | 10 | uinput_options = { |
10 | 11 | 'name' : 'test-py-evdev-uinput', |
11 | 12 | 'bustype' : ecodes.BUS_USB, |
|
14 | 15 | 'version' : 0x3300, |
15 | 16 | } |
16 | 17 |
|
17 | | - |
18 | | -def pytest_funcarg__c(request): |
| 18 | +@fixture |
| 19 | +def c(): |
19 | 20 | return uinput_options.copy() |
20 | 21 |
|
21 | | - |
22 | 22 | def device_exists(bustype, vendor, product, version): |
23 | | - match = 'I: Bus=%04hx Vendor=%04hx Product=%04hx Version=%04hx' % \ |
24 | | - (bustype, vendor, product, version) |
| 23 | + match = 'I: Bus=%04hx Vendor=%04hx Product=%04hx Version=%04hx' |
| 24 | + match = match % (bustype, vendor, product, version) |
25 | 25 |
|
26 | 26 | for line in open('/proc/bus/input/devices'): |
27 | | - if line.strip() == match: return True |
| 27 | + if line.strip() == match: |
| 28 | + return True |
28 | 29 |
|
29 | 30 | return False |
30 | 31 |
|
31 | | - |
| 32 | +#----------------------------------------------------------------------------- |
32 | 33 | def test_open(c): |
33 | 34 | ui = uinput.UInput(**c) |
34 | 35 | args = (c['bustype'], c['vendor'], c['product'], c['version']) |
@@ -59,15 +60,16 @@ def test_enable_events(c): |
59 | 60 | def test_abs_values(c): |
60 | 61 | e = ecodes |
61 | 62 | c['events'] = { |
62 | | - e.EV_KEY : [e.KEY_A, e.KEY_B], |
63 | | - e.EV_ABS : [(e.ABS_X, (0, 255, 0, 0)), |
64 | | - (e.ABS_Y, device.AbsInfo(0, 255, 5, 10, 0, 0))], |
| 63 | + e.EV_KEY: [e.KEY_A, e.KEY_B], |
| 64 | + e.EV_ABS: [(e.ABS_X, (0, 255, 0, 0)), |
| 65 | + (e.ABS_Y, device.AbsInfo(0, 255, 5, 10, 0, 0))], |
65 | 66 | } |
66 | 67 |
|
67 | 68 | with uinput.UInput(**c) as ui: |
68 | 69 | c = ui.capabilities() |
69 | 70 | abs = device.AbsInfo(value=0, min=0, max=255, fuzz=0, flat=0, resolution=0) |
70 | 71 | assert c[e.EV_ABS][0] == (0, abs) |
| 72 | + |
71 | 73 | abs = device.AbsInfo(value=0, min=0, max=255, fuzz=5, flat=10, resolution=0) |
72 | 74 | assert c[e.EV_ABS][1] == (1, abs) |
73 | 75 |
|
|
0 commit comments