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 23KB

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