Browse Source

Fix an exception when no capabilities are read

The intended behavior for Sink.get_source_cap() when no
Source_Capabilities are read was to return an empty list.  This wasn't
done before, instead raising a ValueError when read_pdo() tried to parse
"No Source_Capabilities" as an UnknownPDO.  Now we're a bit more
cautious, and the bug is fixed.
Clara Hobbs 7 years ago
parent
commit
f715d5db9e
3 changed files with 9 additions and 2 deletions
  1. 5
    1
      pdbuddy/__init__.py
  2. 1
    1
      setup.py
  3. 3
    0
      test_pdbuddy/__init__.py

+ 5
- 1
pdbuddy/__init__.py View File

427
                 peak_i=peak_i,
427
                 peak_i=peak_i,
428
                 v=v,
428
                 v=v,
429
                 i=i)
429
                 i=i)
430
+    elif pdo_type == "No Source_Capabilities":
431
+        return None
430
     else:
432
     else:
431
         # Make an UnknownPDO
433
         # Make an UnknownPDO
432
         return UnknownPDO(value=int(pdo_type, 16))
434
         return UnknownPDO(value=int(pdo_type, 16))
445
     # Read the PDOs
447
     # Read the PDOs
446
     pdo_list = []
448
     pdo_list = []
447
     for start, end in zip(pdo_start_list[:-1], pdo_start_list[1:]):
449
     for start, end in zip(pdo_start_list[:-1], pdo_start_list[1:]):
448
-        pdo_list.append(read_pdo(text[start:end]))
450
+        pdo = read_pdo(text[start:end])
451
+        if pdo is not None:
452
+            pdo_list.append(pdo)
449
 
453
 
450
     return pdo_list
454
     return pdo_list

+ 1
- 1
setup.py View File

5
 
5
 
6
 setup(
6
 setup(
7
     name = "pd-buddy-python",
7
     name = "pd-buddy-python",
8
-    version = "0.3.0",
8
+    version = "0.3.1",
9
     author = "Clayton G. Hobbs",
9
     author = "Clayton G. Hobbs",
10
     author_email = "clay@lakeserv.net",
10
     author_email = "clay@lakeserv.net",
11
     description = ("Python library for configuring PD Buddy Sink devices"),
11
     description = ("Python library for configuring PD Buddy Sink devices"),

+ 3
- 0
test_pdbuddy/__init__.py View File

133
         except ValueError:
133
         except ValueError:
134
             self.skipTest("Unknown value returned by PD Buddy Sink")
134
             self.skipTest("Unknown value returned by PD Buddy Sink")
135
 
135
 
136
+    def test_get_source_cap(self):
137
+        self.assertIsInstance(self.pdbs.get_source_cap(), list)
138
+
136
     def test_send_command_invalid(self):
139
     def test_send_command_invalid(self):
137
         with self.assertRaises(KeyError):
140
         with self.assertRaises(KeyError):
138
             self.pdbs.send_command("foo bar")
141
             self.pdbs.send_command("foo bar")

Loading…
Cancel
Save