2021-10-21 17:25:39 +00:00
|
|
|
"""Unit-test parts of the CONNECTIVITY_DATA Python API."""
|
|
|
|
|
2023-05-06 00:13:08 +00:00
|
|
|
import pytest
|
2021-10-21 17:25:39 +00:00
|
|
|
import pcbnew
|
|
|
|
|
|
|
|
|
2023-05-06 00:13:08 +00:00
|
|
|
class TestConnectivity:
|
2021-10-21 17:25:39 +00:00
|
|
|
"""Test that calls on BOARD.Connectivity() are functional."""
|
2023-05-06 00:13:08 +00:00
|
|
|
pcb : pcbnew.BOARD = None
|
2021-10-21 17:25:39 +00:00
|
|
|
|
2023-05-06 00:13:08 +00:00
|
|
|
def setup_method(self):
|
2021-10-21 17:25:39 +00:00
|
|
|
"""Setup shared attributes."""
|
2023-04-25 12:29:47 +00:00
|
|
|
self.pcb = pcbnew.LoadBoard("../data/pcbnew/complex_hierarchy.kicad_pcb")
|
2021-10-21 17:25:39 +00:00
|
|
|
self.connectivity = self.pcb.GetConnectivity()
|
|
|
|
|
|
|
|
def test_get_connectivity_returns_connectivity_data_object(self):
|
|
|
|
"""Verify: GetConnectivity() returns a CONNECTIVITY_DATA object."""
|
|
|
|
connectivity = self.pcb.GetConnectivity()
|
2023-05-06 00:13:08 +00:00
|
|
|
assert type(connectivity).__name__ == "CONNECTIVITY_DATA"
|
2021-10-21 17:25:39 +00:00
|
|
|
|
|
|
|
def test_get_connected_pads_on_track_returns_iterable_of_pads(self):
|
|
|
|
"""Verify: GetConnectedPads(track) returns an iterable of pads."""
|
2023-07-20 22:51:17 +00:00
|
|
|
tracks = list(self.pcb.TracksInNet(self.pcb.GetNetcodeFromNetname("/12Vext")))
|
2021-10-21 17:25:39 +00:00
|
|
|
track_with_pad = tracks[1]
|
2023-07-20 22:51:17 +00:00
|
|
|
"""Note that this returns just the elements directly connected, not everything in the net"""
|
2021-10-21 17:25:39 +00:00
|
|
|
pads = self.connectivity.GetConnectedPads(track_with_pad)
|
2023-05-06 00:13:08 +00:00
|
|
|
assert len(pads) > 0
|
|
|
|
assert all(pad.GetClass() == "PAD" for pad in pads)
|
2021-10-21 17:25:39 +00:00
|
|
|
|
|
|
|
def test_get_connected_tracks_returns_iterable_of_tracks(self):
|
|
|
|
"""Verify: GetConnectedTracks(track) returns an iterable of tracks."""
|
2023-07-20 22:51:17 +00:00
|
|
|
net_tracks = self.pcb.TracksInNet(self.pcb.GetNetcodeFromNetname("/12Vext"))
|
2021-10-21 17:25:39 +00:00
|
|
|
net_track = list(net_tracks)[0]
|
2023-07-20 22:51:17 +00:00
|
|
|
"""Note that this returns just the elements directly connected, not everything in the net"""
|
2021-10-21 17:25:39 +00:00
|
|
|
connected_tracks = self.connectivity.GetConnectedTracks(net_track)
|
2023-05-06 00:13:08 +00:00
|
|
|
assert len(connected_tracks) > 1
|
|
|
|
assert all(track.GetClass() == "PCB_TRACK" for track in connected_tracks)
|