Python library for working with the PD Buddy Sink Serial Console Configuration Interface
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. """Unit tests for the top-level pdbuddy classes"""
  2. import unittest
  3. import pdbuddy
  4. class SinkTestCase(unittest.TestCase):
  5. def setUp(self):
  6. # Get devices
  7. pdbs_devices = list(pdbuddy.Sink.get_devices())
  8. # If there are no devices, skip the test
  9. if len(pdbs_devices) == 0:
  10. self.skipTest("No PD Buddy Sink devices found")
  11. # Open the first device
  12. self.pdbs = pdbuddy.Sink(pdbs_devices[0])
  13. self.obj_valid = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
  14. flags=pdbuddy.SinkFlags.NONE, v=15000, vmin=None, vmax=None,
  15. i=3000)
  16. self.obj_valid_gb = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
  17. flags=pdbuddy.SinkFlags.GIVEBACK, v=15000, vmin=None,
  18. vmax=None, i=3000)
  19. self.obj_huge_v = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
  20. flags=pdbuddy.SinkFlags.NONE, v=65536, vmin=None, vmax=None,
  21. i=1000)
  22. self.obj_big_v = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
  23. flags=pdbuddy.SinkFlags.NONE, v=21001, vmin=None, vmax=None,
  24. i=1000)
  25. self.obj_neg_v = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
  26. flags=pdbuddy.SinkFlags.NONE, v=-1, vmin=None, vmax=None,
  27. i=1000)
  28. self.obj_huge_i = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
  29. flags=pdbuddy.SinkFlags.NONE, v=5000, vmin=None, vmax=None,
  30. i=65536)
  31. self.obj_big_i = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
  32. flags=pdbuddy.SinkFlags.NONE, v=5000, vmin=None, vmax=None,
  33. i=5001)
  34. self.obj_neg_i = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
  35. flags=pdbuddy.SinkFlags.NONE, v=5000, vmin=None, vmax=None,
  36. i=-1)
  37. def tearDown(self):
  38. # Close the connection to the PD Buddy Sink
  39. self.pdbs.close()
  40. def test_identify(self):
  41. self.pdbs.identify()
  42. def test_help(self):
  43. help_text = self.pdbs.help()
  44. self.assertTrue(len(help_text) > 0)
  45. self.assertTrue(len(help_text[0]) > 0)
  46. def test_license(self):
  47. license_text = self.pdbs.license()
  48. self.assertTrue(len(license_text) > 0)
  49. self.assertTrue(len(license_text[0]) > 0)
  50. def test_set_tmpcfg_valid(self):
  51. self.pdbs.set_tmpcfg(self.obj_valid)
  52. self.assertEqual(self.pdbs.get_tmpcfg(), self.obj_valid)
  53. def test_set_tmpcfg_valid_gb(self):
  54. self.pdbs.set_tmpcfg(self.obj_valid_gb)
  55. self.assertEqual(self.pdbs.get_tmpcfg(), self.obj_valid_gb)
  56. def test_set_tmpcfg_huge_v(self):
  57. with self.assertRaises(ValueError):
  58. self.pdbs.set_tmpcfg(self.obj_huge_v)
  59. def test_set_tmpcfg_big_v(self):
  60. with self.assertRaises(ValueError):
  61. self.pdbs.set_tmpcfg(self.obj_big_v)
  62. def test_set_tmpcfg_neg_v(self):
  63. with self.assertRaises(ValueError):
  64. self.pdbs.set_tmpcfg(self.obj_neg_v)
  65. def test_set_tmpcfg_huge_i(self):
  66. with self.assertRaises(ValueError):
  67. self.pdbs.set_tmpcfg(self.obj_huge_i)
  68. def test_set_tmpcfg_big_i(self):
  69. with self.assertRaises(ValueError):
  70. self.pdbs.set_tmpcfg(self.obj_big_i)
  71. def test_set_tmpcfg_neg_i(self):
  72. with self.assertRaises(ValueError):
  73. self.pdbs.set_tmpcfg(self.obj_neg_i)
  74. def test_write(self):
  75. self.test_set_tmpcfg_valid()
  76. self.pdbs.write()
  77. self.assertEqual(self.pdbs.get_cfg(), self.obj_valid)
  78. def test_get_cfg_index(self):
  79. self.assertIsInstance(self.pdbs.get_cfg(0), pdbuddy.SinkConfig)
  80. def test_get_cfg_index_bad(self):
  81. with self.assertRaises(IndexError):
  82. self.pdbs.get_cfg(-1)
  83. def test_load(self):
  84. # Write obj_valid to flash
  85. self.test_write()
  86. # Write obj_valid_gb to tmpcfg
  87. self.test_set_tmpcfg_valid_gb()
  88. self.assertNotEqual(self.pdbs.get_cfg(), self.pdbs.get_tmpcfg())
  89. # Load flash to tmpcfg
  90. self.pdbs.load()
  91. self.assertEqual(self.pdbs.get_cfg(), self.pdbs.get_tmpcfg())
  92. def test_erase(self):
  93. self.pdbs.erase()
  94. with self.assertRaises(KeyError):
  95. self.pdbs.load()
  96. def test_context_manager(self):
  97. self.pdbs.close()
  98. with pdbuddy.Sink(list(pdbuddy.Sink.get_devices())[0]) as pdbs:
  99. # Test something with the conext manager. For example, this is
  100. # essentially test_get_cfg_index.
  101. self.assertIsInstance(pdbs.get_cfg(0), pdbuddy.SinkConfig)
  102. def test_output(self):
  103. try:
  104. self.pdbs.output = False
  105. self.assertFalse(self.pdbs.output)
  106. self.pdbs.output = True
  107. self.assertTrue(self.pdbs.output)
  108. except KeyError:
  109. self.skipTest("Command output not supported")
  110. except ValueError:
  111. self.skipTest("Unknown value returned by PD Buddy Sink")
  112. def test_get_source_cap(self):
  113. self.assertIsInstance(self.pdbs.get_source_cap(), list)
  114. def test_send_command_invalid(self):
  115. with self.assertRaises(KeyError):
  116. self.pdbs.send_command("foo bar")
  117. class SinkConfigTestCase(unittest.TestCase):
  118. def setUp(self):
  119. self.obj_none = pdbuddy.SinkConfig(status=None, flags=None, v=None,
  120. vmin=None, vmax=None, i=None)
  121. self.obj_empty = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.EMPTY,
  122. flags=None, v=None, vmin=None, vmax=None, i=None)
  123. self.obj_valid = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
  124. flags=pdbuddy.SinkFlags.NONE, v=15000, vmin=None, vmax=None,
  125. i=3000)
  126. self.obj_invalid = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.INVALID,
  127. flags=pdbuddy.SinkFlags.NONE, v=15000, vmin=None, vmax=None,
  128. i=3000)
  129. self.obj_valid_gb = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
  130. flags=pdbuddy.SinkFlags.GIVEBACK, v=15000, vmin=None,
  131. vmax=None, i=3000)
  132. self.obj_valid_5v = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
  133. flags=pdbuddy.SinkFlags.NONE, v=5000, vmin=None, vmax=None,
  134. i=3000)
  135. self.obj_valid_1a = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
  136. flags=pdbuddy.SinkFlags.NONE, v=15000, vmin=None, vmax=None,
  137. i=1000)
  138. self.obj_valid_range = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
  139. flags=pdbuddy.SinkFlags.NONE, v=15000, vmin=12000, vmax=16000,
  140. i=1000)
  141. self.obj_valid_hv = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
  142. flags=pdbuddy.SinkFlags.HV_PREFERRED, v=15000, vmin=12000,
  143. vmax=16000, i=1000)
  144. def test_str_none(self):
  145. self.assertEqual(str(self.obj_none), "No configuration")
  146. def test_str_empty(self):
  147. self.assertEqual(str(self.obj_empty), "status: empty")
  148. def test_str_valid(self):
  149. self.assertEqual(str(self.obj_valid),
  150. "status: valid\nflags: (none)\nv: 15.000 V\ni: 3.00 A")
  151. def test_str_invalid(self):
  152. self.assertEqual(str(self.obj_invalid),
  153. "status: invalid\nflags: (none)\nv: 15.000 V\ni: 3.00 A")
  154. def test_str_valid_gb(self):
  155. self.assertEqual(str(self.obj_valid_gb),
  156. "status: valid\nflags: GiveBack\nv: 15.000 V\ni: 3.00 A")
  157. def test_str_valid_5v(self):
  158. self.assertEqual(str(self.obj_valid_5v),
  159. "status: valid\nflags: (none)\nv: 5.000 V\ni: 3.00 A")
  160. def test_str_valid_1a(self):
  161. self.assertEqual(str(self.obj_valid_1a),
  162. "status: valid\nflags: (none)\nv: 15.000 V\ni: 1.00 A")
  163. def test_str_valid_range(self):
  164. self.assertEqual(str(self.obj_valid_range),
  165. "status: valid\nflags: (none)\nv: 15.000 V\nvmin: 12.000 V\n"
  166. "vmax: 16.000 V\ni: 1.00 A")
  167. def test_str_valid_hv(self):
  168. self.assertEqual(str(self.obj_valid_hv),
  169. "status: valid\nflags: HV_Preferred\nv: 15.000 V\n"
  170. "vmin: 12.000 V\nvmax: 16.000 V\ni: 1.00 A")
  171. def test_from_text_none(self):
  172. ft_none = pdbuddy.SinkConfig.from_text([])
  173. self.assertEqual(ft_none, self.obj_none)
  174. def test_from_text_empty(self):
  175. ft_empty = pdbuddy.SinkConfig.from_text([b"status: empty"])
  176. self.assertEqual(ft_empty, self.obj_empty)
  177. def test_from_text_valid(self):
  178. ft_valid = pdbuddy.SinkConfig.from_text([b"status: valid",
  179. b"flags: (none)",
  180. b"v: 15.000 V",
  181. b"i: 3.00 A"])
  182. self.assertEqual(ft_valid, self.obj_valid)
  183. def test_from_text_invalid(self):
  184. ft_invalid = pdbuddy.SinkConfig.from_text([b"status: invalid",
  185. b"flags: (none)",
  186. b"v: 15.000 V",
  187. b"i: 3.00 A"])
  188. self.assertEqual(ft_invalid, self.obj_invalid)
  189. def test_from_text_valid_gb(self):
  190. ft_valid_gb = pdbuddy.SinkConfig.from_text([b"status: valid",
  191. b"flags: GiveBack",
  192. b"v: 15.000 V",
  193. b"i: 3.00 A"])
  194. self.assertEqual(ft_valid_gb, self.obj_valid_gb)
  195. def test_from_text_valid_5v(self):
  196. ft_valid_5v = pdbuddy.SinkConfig.from_text([b"status: valid",
  197. b"flags: (none)",
  198. b"v: 5.000 V",
  199. b"i: 3.00 A"])
  200. self.assertEqual(ft_valid_5v, self.obj_valid_5v)
  201. def test_from_text_valid_1a(self):
  202. ft_valid_1a = pdbuddy.SinkConfig.from_text([b"status: valid",
  203. b"flags: (none)",
  204. b"v: 15.000 V",
  205. b"i: 1.00 A"])
  206. self.assertEqual(ft_valid_1a, self.obj_valid_1a)
  207. def test_from_text_valid_range(self):
  208. ft_valid_range = pdbuddy.SinkConfig.from_text([b"status: valid",
  209. b"flags: (none)",
  210. b"v: 15.000 V",
  211. b"vmin: 12.000 V",
  212. b"vmax: 16.000 V",
  213. b"i: 1.00 A"])
  214. self.assertEqual(ft_valid_range, self.obj_valid_range)
  215. def test_from_text_valid_hv(self):
  216. ft_valid_hv = pdbuddy.SinkConfig.from_text([b"status: valid",
  217. b"flags: HV_Preferred",
  218. b"v: 15.000 V",
  219. b"vmin: 12.000 V",
  220. b"vmax: 16.000 V",
  221. b"i: 1.00 A"])
  222. self.assertEqual(ft_valid_hv, self.obj_valid_hv)
  223. def test_from_text_invalid_index(self):
  224. with self.assertRaises(IndexError):
  225. pdbuddy.SinkConfig.from_text([b"Invalid index"])
  226. def test_from_text_no_configuration(self):
  227. ft_no_config = pdbuddy.SinkConfig.from_text([b"No configuration"])
  228. self.assertEqual(ft_no_config, self.obj_none)
  229. def test_from_text_valid_extra(self):
  230. ft_valid = pdbuddy.SinkConfig.from_text([b"status: valid",
  231. b"flags: (none)",
  232. b"This is an extra line, which shouldn't hurt anything.",
  233. b"v: 15.000 V",
  234. b"i: 3.00 A"])
  235. self.assertEqual(ft_valid, self.obj_valid)
  236. class UnknownPDOTestCase(unittest.TestCase):
  237. def setUp(self):
  238. self.obj_zero = pdbuddy.UnknownPDO(value=0x00000000)
  239. self.obj_notzero = pdbuddy.UnknownPDO(value=0xFFFFFFFF)
  240. def test_str_zero(self):
  241. self.assertEqual(str(self.obj_zero), "00000000")
  242. def test_str_notzero(self):
  243. self.assertEqual(str(self.obj_notzero), "FFFFFFFF")
  244. class SrcFixedPDOTestCase(unittest.TestCase):
  245. def setUp(self):
  246. self.obj_everything = pdbuddy.SrcFixedPDO(True, True, True, True, True,
  247. True, 3, 20000, 5000)
  248. self.obj_minimal = pdbuddy.SrcFixedPDO(False, False, False, False,
  249. False, False, 0, 5000, 1500)
  250. def test_str_everything(self):
  251. self.assertEqual(str(self.obj_everything),
  252. "fixed\n\tdual_role_pwr: 1\n\tusb_suspend: 1\n"
  253. "\tunconstrained_pwr: 1\n\tusb_comms: 1\n\tdual_role_data: 1\n"
  254. "\tunchunked_ext_msg: 1\n\tpeak_i: 3\n\tv: 20.00 V\n"
  255. "\ti: 5.00 A")
  256. def test_str_minimal(self):
  257. self.assertEqual(str(self.obj_minimal),
  258. "fixed\n\tv: 5.00 V\n\ti: 1.50 A")
  259. class TypeCVirtualPDOTestCase(unittest.TestCase):
  260. def setUp(self):
  261. self.obj_1p5a = pdbuddy.TypeCVirtualPDO(1500)
  262. def test_str_1p5a(self):
  263. self.assertEqual(str(self.obj_1p5a), "typec_virtual\n\ti: 1.50 A")
  264. class ReadPDOTestCase(unittest.TestCase):
  265. def setUp(self):
  266. self.src_fixed_everything = pdbuddy.SrcFixedPDO(True, True, True, True,
  267. True, True, 3, 20000, 5000)
  268. self.src_fixed_minimal = pdbuddy.SrcFixedPDO(False, False, False,
  269. False, False, False, 0, 5000, 1500)
  270. self.unknown_zero = pdbuddy.UnknownPDO(value=0x00000000)
  271. self.unknown_notzero = pdbuddy.UnknownPDO(value=0xFFFFFFFF)
  272. self.typec_virtual = pdbuddy.TypeCVirtualPDO(1500)
  273. def test_read_src_fixed_everything(self):
  274. rp_src_fixed_everything = pdbuddy.read_pdo([b"PDO 1: fixed",
  275. b"\tdual_role_pwr: 1",
  276. b"\tusb_suspend: 1",
  277. b"\tunconstrained_pwr: 1",
  278. b"\tusb_comms: 1",
  279. b"\tdual_role_data: 1",
  280. b"\tunchunked_ext_msg: 1",
  281. b"\tpeak_i: 3",
  282. b"\tv: 20.00 V",
  283. b"\ti: 5.00 A"])
  284. self.assertEqual(self.src_fixed_everything, rp_src_fixed_everything)
  285. def test_read_src_fixed_minimal(self):
  286. rp_src_fixed_minimal = pdbuddy.read_pdo([b"PDO 1: fixed",
  287. b"\tv: 5.00 V",
  288. b"\ti: 1.50 A"])
  289. self.assertEqual(self.src_fixed_minimal, rp_src_fixed_minimal)
  290. def test_read_src_fixed_minimal_no_index(self):
  291. rp_src_fixed_minimal = pdbuddy.read_pdo([b"fixed",
  292. b"\tv: 5.00 V",
  293. b"\ti: 1.50 A"])
  294. self.assertEqual(self.src_fixed_minimal, rp_src_fixed_minimal)
  295. def test_read_unknown_zero(self):
  296. rp_unknown_zero = pdbuddy.read_pdo([b"PDO 1: 00000000"])
  297. self.assertEqual(self.unknown_zero, rp_unknown_zero)
  298. def test_read_unknown_notzero(self):
  299. rp_unknown_notzero = pdbuddy.read_pdo([b"PDO 1: FFFFFFFF"])
  300. self.assertEqual(self.unknown_notzero, rp_unknown_notzero)
  301. def test_read_typec_virtual(self):
  302. rp_typec_virtual = pdbuddy.read_pdo([b"PDO 5: typec_virtual",
  303. b"\ti: 1.50 A"])
  304. self.assertEqual(self.typec_virtual, rp_typec_virtual)
  305. def test_read_none(self):
  306. none_pdo = pdbuddy.read_pdo([b"No Source_Capabilities"])
  307. self.assertEqual(none_pdo, None)
  308. class ReadPDOListTestCase(unittest.TestCase):
  309. def setUp(self):
  310. self.src_fixed_everything = pdbuddy.SrcFixedPDO(True, True, True, True,
  311. True, True, 3, 20000, 5000)
  312. self.src_fixed_minimal = pdbuddy.SrcFixedPDO(False, False, False,
  313. False, False, False, 0, 5000, 1500)
  314. self.unknown_zero = pdbuddy.UnknownPDO(value=0x00000000)
  315. self.unknown_notzero = pdbuddy.UnknownPDO(value=0xFFFFFFFF)
  316. self.typec_virtual = pdbuddy.TypeCVirtualPDO(1500)
  317. def test_read_pdo_list(self):
  318. # It's not a legal list for USB Power Delivery, but it works fine for
  319. # testing this code
  320. text = [b"PDO 1: fixed",
  321. b"\tdual_role_pwr: 1",
  322. b"\tusb_suspend: 1",
  323. b"\tunconstrained_pwr: 1",
  324. b"\tusb_comms: 1",
  325. b"\tdual_role_data: 1",
  326. b"\tunchunked_ext_msg: 1",
  327. b"\tpeak_i: 3",
  328. b"\tv: 20.00 V",
  329. b"\ti: 5.00 A",
  330. b"PDO 2: fixed",
  331. b"\tv: 5.00 V",
  332. b"\ti: 1.50 A",
  333. b"PDO 3: 00000000",
  334. b"PDO 4: FFFFFFFF",
  335. b"PDO 5: typec_virtual",
  336. b"\ti: 1.50 A"]
  337. pdo_list = pdbuddy.read_pdo_list(text)
  338. self.assertEqual(pdo_list[0], self.src_fixed_everything)
  339. self.assertEqual(pdo_list[1], self.src_fixed_minimal)
  340. self.assertEqual(pdo_list[2], self.unknown_zero)
  341. self.assertEqual(pdo_list[3], self.unknown_notzero)
  342. self.assertEqual(pdo_list[4], self.typec_virtual)
  343. class PDOListCalculationsTestCase(unittest.TestCase):
  344. def setUp(self):
  345. self.src_fixed_5v_1p5a = pdbuddy.SrcFixedPDO(False, False, True,
  346. False, False, False, 0, 5000, 1500)
  347. self.src_fixed_5v_3a = pdbuddy.SrcFixedPDO(False, False, True, False,
  348. False, False, 0, 5000, 3000)
  349. self.src_fixed_9v_1p6a = pdbuddy.SrcFixedPDO(False, False, False,
  350. False, False, False, 0, 9000, 1600)
  351. self.src_fixed_9v_3a = pdbuddy.SrcFixedPDO(False, False, False, False,
  352. False, False, 0, 9000, 3000)
  353. self.src_fixed_10v_1p5a = pdbuddy.SrcFixedPDO(False, False, False,
  354. False, False, False, 0, 10000, 1500)
  355. self.src_fixed_12v_5a = pdbuddy.SrcFixedPDO(False, False, False, False,
  356. False, False, 0, 12000, 5000)
  357. self.src_fixed_15v_1p8a = pdbuddy.SrcFixedPDO(False, False, False,
  358. False, False, False, 0, 15000, 1800)
  359. self.src_fixed_15v_3a = pdbuddy.SrcFixedPDO(False, False, False, False,
  360. False, False, 0, 15000, 3000)
  361. self.src_fixed_20v_2p25a = pdbuddy.SrcFixedPDO(False, False, False,
  362. False, False, False, 0, 20000, 2250)
  363. self.src_fixed_20v_5a = pdbuddy.SrcFixedPDO(False, False, False, False,
  364. False, False, 0, 20000, 5000)
  365. self.typec_virtual_1p5a = pdbuddy.TypeCVirtualPDO(1500)
  366. def test_calculate_pdp_typec_virtual(self):
  367. self.assertEqual(pdbuddy.calculate_pdp([self.typec_virtual_1p5a]), 7.5)
  368. def test_calculate_pdp_15w(self):
  369. self.assertEqual(pdbuddy.calculate_pdp([self.src_fixed_5v_3a]), 15)
  370. self.assertEqual(pdbuddy.calculate_pdp([self.src_fixed_5v_3a,
  371. self.src_fixed_9v_1p6a]), 15)
  372. def test_calculate_pdp_27w(self):
  373. self.assertEqual(pdbuddy.calculate_pdp([self.src_fixed_5v_3a,
  374. self.src_fixed_9v_3a]), 27)
  375. self.assertEqual(pdbuddy.calculate_pdp([self.src_fixed_5v_3a,
  376. self.src_fixed_9v_3a, self.src_fixed_15v_1p8a]), 27)
  377. def test_calculate_pdp_45w(self):
  378. self.assertEqual(pdbuddy.calculate_pdp([self.src_fixed_5v_3a,
  379. self.src_fixed_9v_3a, self.src_fixed_15v_3a]), 45)
  380. self.assertEqual(pdbuddy.calculate_pdp([self.src_fixed_5v_3a,
  381. self.src_fixed_9v_3a, self.src_fixed_15v_3a,
  382. self.src_fixed_20v_2p25a]), 45)
  383. def test_calculate_pdp_100w(self):
  384. self.assertEqual(pdbuddy.calculate_pdp([self.src_fixed_5v_3a,
  385. self.src_fixed_9v_3a, self.src_fixed_15v_3a,
  386. self.src_fixed_20v_5a]), 100)
  387. self.assertEqual(pdbuddy.calculate_pdp([self.src_fixed_5v_1p5a,
  388. self.src_fixed_12v_5a, self.src_fixed_20v_5a]), 100)
  389. def test_follows_power_rules_true(self):
  390. # <= 15 W
  391. self.assertTrue(pdbuddy.follows_power_rules([]))
  392. self.assertTrue(pdbuddy.follows_power_rules([self.typec_virtual_1p5a]))
  393. self.assertTrue(pdbuddy.follows_power_rules([self.src_fixed_5v_1p5a]))
  394. self.assertTrue(pdbuddy.follows_power_rules([self.src_fixed_5v_3a]))
  395. self.assertTrue(pdbuddy.follows_power_rules([self.src_fixed_5v_3a,
  396. self.src_fixed_9v_1p6a]))
  397. # <= 27 W
  398. self.assertTrue(pdbuddy.follows_power_rules([self.src_fixed_5v_3a,
  399. self.src_fixed_9v_3a]))
  400. self.assertTrue(pdbuddy.follows_power_rules([self.src_fixed_5v_3a,
  401. self.src_fixed_9v_3a, self.src_fixed_15v_1p8a]))
  402. # <= 45 W
  403. self.assertTrue(pdbuddy.follows_power_rules([self.src_fixed_5v_3a,
  404. self.src_fixed_9v_3a, self.src_fixed_15v_3a]))
  405. self.assertTrue(pdbuddy.follows_power_rules([self.src_fixed_5v_3a,
  406. self.src_fixed_9v_3a, self.src_fixed_15v_3a,
  407. self.src_fixed_20v_2p25a]))
  408. # <= 100 W
  409. self.assertTrue(pdbuddy.follows_power_rules([self.src_fixed_5v_3a,
  410. self.src_fixed_9v_3a, self.src_fixed_15v_3a,
  411. self.src_fixed_20v_5a]))
  412. self.assertTrue(pdbuddy.follows_power_rules([self.src_fixed_5v_3a,
  413. self.src_fixed_9v_3a, self.src_fixed_10v_1p5a,
  414. self.src_fixed_12v_5a, self.src_fixed_15v_3a,
  415. self.src_fixed_20v_5a]))
  416. def test_follows_power_rules_false(self):
  417. # <= 15 W
  418. self.assertFalse(pdbuddy.follows_power_rules([self.src_fixed_10v_1p5a]))
  419. self.assertFalse(pdbuddy.follows_power_rules([self.src_fixed_5v_1p5a,
  420. self.src_fixed_10v_1p5a]))
  421. # <= 27 W
  422. self.assertFalse(pdbuddy.follows_power_rules([self.src_fixed_9v_3a]))
  423. self.assertFalse(pdbuddy.follows_power_rules([self.src_fixed_5v_1p5a,
  424. self.src_fixed_9v_3a]))
  425. self.assertFalse(pdbuddy.follows_power_rules([self.src_fixed_5v_3a,
  426. self.src_fixed_9v_1p6a, self.src_fixed_15v_1p8a]))
  427. # <= 45 W
  428. self.assertFalse(pdbuddy.follows_power_rules([self.src_fixed_20v_2p25a]))
  429. self.assertFalse(pdbuddy.follows_power_rules([self.src_fixed_5v_1p5a,
  430. self.src_fixed_9v_3a, self.src_fixed_15v_3a]))
  431. self.assertFalse(pdbuddy.follows_power_rules([self.src_fixed_5v_3a,
  432. self.src_fixed_9v_1p6a, self.src_fixed_15v_3a]))
  433. self.assertFalse(pdbuddy.follows_power_rules([self.src_fixed_5v_3a,
  434. self.src_fixed_9v_3a, self.src_fixed_15v_1p8a,
  435. self.src_fixed_20v_2p25a]))
  436. # <= 100 W
  437. self.assertFalse(pdbuddy.follows_power_rules([self.src_fixed_20v_5a]))
  438. self.assertFalse(pdbuddy.follows_power_rules([self.src_fixed_5v_1p5a,
  439. self.src_fixed_9v_3a, self.src_fixed_15v_3a,
  440. self.src_fixed_20v_5a]))
  441. self.assertFalse(pdbuddy.follows_power_rules([self.src_fixed_5v_3a,
  442. self.src_fixed_9v_1p6a, self.src_fixed_15v_3a,
  443. self.src_fixed_20v_5a]))
  444. self.assertFalse(pdbuddy.follows_power_rules([self.src_fixed_5v_3a,
  445. self.src_fixed_9v_3a, self.src_fixed_15v_1p8a,
  446. self.src_fixed_20v_5a]))
  447. self.assertFalse(pdbuddy.follows_power_rules([self.src_fixed_5v_3a,
  448. self.src_fixed_9v_3a, self.src_fixed_12v_5a,
  449. self.src_fixed_15v_3a, self.src_fixed_20v_2p25a]))