MCPcopy Create free account
hub / github.com/tiny-pilot/tinypilot / GetNetworkInterfacesTest

Class GetNetworkInterfacesTest

app/network_test.py:131–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129
130
131class GetNetworkInterfacesTest(unittest.TestCase):
132
133 def test_returns_empty_list_when_path_is_not_a_directory(self):
134 with tempfile.NamedTemporaryFile() as mock_file:
135 with mock.patch.object(network, '_INTERFACES_DIR', mock_file.name):
136 self.assertEqual([], network.get_network_interfaces())
137
138 def test_returns_empty_list_when_path_does_not_exist(self):
139 with tempfile.TemporaryDirectory() as mock_dir:
140 with mock.patch.object(network, '_INTERFACES_DIR',
141 f'{mock_dir}/path/does/not/exist'):
142 self.assertEqual([], network.get_network_interfaces())
143
144 def test_returns_empty_list_when_directory_has_no_interfaces(self):
145 with tempfile.TemporaryDirectory() as mock_dir:
146 with mock.patch.object(network, '_INTERFACES_DIR', mock_dir):
147 self.assertEqual([], network.get_network_interfaces())
148
149 def test_excludes_loopback_and_virtual_interfaces(self):
150 with tempfile.TemporaryDirectory() as mock_dir:
151 mock_net_interfaces_dir = Path(mock_dir)
152 # Physical interfaces (with 'device').
153 (mock_net_interfaces_dir / 'eth0' / 'device').mkdir(parents=True)
154 (mock_net_interfaces_dir / 'wlan0' / 'device').mkdir(parents=True)
155 # Loopback (no 'device' in the path).
156 (mock_net_interfaces_dir / 'lo').mkdir()
157 # Some virtual interface (no 'device' in the path).
158 (mock_net_interfaces_dir / 'veth0').mkdir()
159 with mock.patch.object(network, '_INTERFACES_DIR', mock_dir):
160 self.assertEqual(['eth0', 'wlan0'],
161 network.get_network_interfaces())
162
163 def test_returns_sorted_interface_names(self):
164 with tempfile.TemporaryDirectory() as mock_dir:
165 mock_net_interfaces_dir = Path(mock_dir)
166 # Create in unsorted order.
167 (mock_net_interfaces_dir / 'wlan0' / 'device').mkdir(parents=True)
168 (mock_net_interfaces_dir / 'eth0' / 'device').mkdir(parents=True)
169 with mock.patch.object(network, '_INTERFACES_DIR', mock_dir):
170 self.assertEqual(['eth0', 'wlan0'],
171 network.get_network_interfaces())

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected