From 312715845b7aa24cd11a68e16b7e947da751a8cf Mon Sep 17 00:00:00 2001 From: Ben Sartori <149951068+bensartori@users.noreply.github.com> Date: Fri, 28 Jun 2024 09:55:03 +0200 Subject: [PATCH] Minor fixes for Windows. To be backwards compatible, using Windows with hidapi is not forbidden. But now, you have to select it explicitly. --- lednamebadge.py | 12 +++++++----- tests/test_lednamebadge_select_method.py | 7 ++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lednamebadge.py b/lednamebadge.py index 93be065..345d069 100755 --- a/lednamebadge.py +++ b/lednamebadge.py @@ -903,11 +903,7 @@ class LedNameBadge: sys.exit(1) if method == hidapi.get_name(): - if sys.platform.startswith('win'): - print("For Windows, please use method '%s' or 'auto'." % (libusb.get_name(),)) - print("Or help us implementing support for Windows.") - sys.exit(1) - elif sys.version_info[0] < 3: + if sys.version_info[0] < 3: print("Please use method '%s' or 'auto' with python-2.x" % (libusb.get_name(),)) print("because of https://github.com/jnweiger/led-badge-ls32/issues/9") sys.exit(1) @@ -915,6 +911,12 @@ class LedNameBadge: LedNameBadge._print_hidapi_install_hints(hidapi.get_name()) sys.exit(1) + if sys.platform.startswith('win') and hidapi.is_ready(): + print("Method '%s' is not tested under Windows. If not working, please use '%s' or 'auto'" % ( + hidapi.get_name(), libusb.get_name())) + print("Or help us implementing support for Windows.") + # But it is not forbidden + first_method_found = None for m in auto_order_methods: if method == 'auto' or method == m.get_name(): diff --git a/tests/test_lednamebadge_select_method.py b/tests/test_lednamebadge_select_method.py index c9bfd1f..68cfce0 100644 --- a/tests/test_lednamebadge_select_method.py +++ b/tests/test_lednamebadge_select_method.py @@ -127,7 +127,12 @@ class Test(abstract_witre_method_test.AbstractWriteMethodTest): def test_windows_negative(self): method, output = self.call_find(True, False, True, 'hidapi', 'auto') self.assertNotIn('device initialized', output) - self.assertIn('please use method', output) + self.assertIn('is not possible to be used', output) + self.assertIsNone(method) + + method, output = self.call_find(True, True, False, 'hidapi', 'auto') + self.assertNotIn('device initialized', output) + self.assertIn('If not working, please use', output) self.assertIsNone(method) @patch('sys.platform', new='darwin')