Skip to content

Commit e4c5e6f

Browse files
committed
Fix error when the device class dir doesn't exist
1 parent bb76ce3 commit e4c5e6f

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

ev3dev/core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757

5858
# -----------------------------------------------------------------------------
5959
def list_device_names(class_path, name_pattern, **kwargs):
60+
61+
if not os.path.isdir(class_path):
62+
return
63+
6064
"""
6165
This is a generator function that lists names of all devices matching the
6266
provided parameters.

tests/api_tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def test_device(self):
3636
d = ev3.Device('lego-sensor', 'sensor*')
3737
self.assertTrue(d.connected)
3838

39+
d = ev3.Device('this-does-not-exist')
40+
self.assertFalse(d.connected)
41+
3942
def test_medium_motor(self):
4043
def dummy(self):
4144
pass

0 commit comments

Comments
 (0)