Skip to content

Commit

Permalink
Refactored unittest.
Browse files Browse the repository at this point in the history
  • Loading branch information
KarsMulder committed Jan 1, 2022
1 parent 219e788 commit 89c67ba
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions unittest/reopen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import time

EVSIEVE_PROGRAM = ["target/debug/evsieve"]
SLEEP_TIME = 0.2

sp.run(["systemctl", "reset-failed"])
def run_with_args(args):
Expand Down Expand Up @@ -73,23 +74,23 @@ def test_send_events():
input_device.close()
for link in symlink_chain:
os.unlink(link)
time.sleep(0.1)
time.sleep(SLEEP_TIME)

input_device = evdev.UInput(capabilities)
create_links()
time.sleep(0.1)
time.sleep(SLEEP_TIME)

# Test whether evsieve has picked up the new device.
test_send_events()

# This time only destroy the last link in the chain.
input_device.close()
os.unlink(symlink_chain[0])
time.sleep(0.1)
time.sleep(SLEEP_TIME)

input_device = evdev.UInput(capabilities)
os.symlink(input_device.device, symlink_chain[0])
time.sleep(0.1)
time.sleep(SLEEP_TIME)

test_send_events()

Expand Down Expand Up @@ -147,17 +148,15 @@ def create_input_devices(capabilities):
"--input", input_device_2_path, "persist=none", "grab=force",
"--output", f"create-link={output_path}"
])

time.sleep(0.2)
assert(os.path.exists(output_path))

input_device_1.close()
time.sleep(0.2)
time.sleep(SLEEP_TIME)
assert(os.path.exists(output_path))

# Make sure evsieve exits when all input devices disappear.
input_device_2.close()
time.sleep(0.2)
time.sleep(SLEEP_TIME)
assert(not os.path.exists(output_path) and not os.path.islink(output_path))

print("Unittest part 2 successful.")
Expand All @@ -170,7 +169,7 @@ def create_input_devices(capabilities):
"--input", input_device_2_path, "persist=reopen", "grab=force",
"--output", f"create-link={output_path}"
])
time.sleep(0.1)
time.sleep(SLEEP_TIME)
output_device = evdev.InputDevice(output_path)
output_device.grab()

Expand Down Expand Up @@ -205,7 +204,7 @@ def test_events(input_device, output_device, events):
input_device_1 = evdev.UInput(capabilities_A)
link_to_device(input_device_1, input_device_1_path)

time.sleep(0.1)
time.sleep(SLEEP_TIME)
test_events(input_device_1, output_device,
[(e.EV_KEY, e.KEY_A, 1), (e.EV_SYN, 0, 0), (e.EV_KEY, e.KEY_A, 0), (e.EV_SYN, 0, 0)]
)
Expand All @@ -218,7 +217,7 @@ def test_events(input_device, output_device, events):
os.unlink(input_device_1_path)
input_device_1 = evdev.UInput(capabilities_C)
link_to_device(input_device_1, input_device_1_path)
time.sleep(0.1)
time.sleep(SLEEP_TIME)

output_device.close()
output_device = evdev.InputDevice(output_path)
Expand Down Expand Up @@ -278,11 +277,11 @@ def test_events(input_device, output_device, events):

os.unlink(input_path)
input_device.close()
time.sleep(0.1)
time.sleep(SLEEP_TIME)

input_device = evdev.UInput(capabilities_2)
os.symlink(input_device.device, input_path)
time.sleep(0.1)
time.sleep(SLEEP_TIME)

# Because capabilities_1 and capabilities_2 do only differ in the current value of the axes, this
# should not trigger recreation of the output devices.
Expand All @@ -292,11 +291,11 @@ def test_events(input_device, output_device, events):

os.unlink(input_path)
input_device.close()
time.sleep(0.1)
time.sleep(SLEEP_TIME)

input_device = evdev.UInput(capabilities_3)
os.symlink(input_device.device, input_path)
time.sleep(0.1)
time.sleep(SLEEP_TIME)

# Because capabilities_2 and capabilities_3 do differ in the range of the axes, this should trigger
# recreation of the output devices.
Expand Down

0 comments on commit 89c67ba

Please sign in to comment.