1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
from unittest import TestCase, mock
from xsdata.utils.hooks import load_entry_points
class HooksTests(TestCase):
@mock.patch("xsdata.utils.hooks.metadata.entry_points")
def test_load_entry_points_with_mapping_api(self, mock_entry_points):
first_ep = mock.Mock()
second_ep = mock.Mock()
third_ep = mock.Mock()
mock_entry_points.return_value = {
"foo": [first_ep, second_ep],
"bar": [third_ep],
}
load_entry_points("foo")
first_ep.load.assert_called_once_with()
second_ep.load.assert_called_once_with()
self.assertEqual(0, third_ep.load.call_count)
@mock.patch("xsdata.utils.hooks.metadata.entry_points")
def test_load_entry_points_with_select_api(self, mock_entry_points):
first_ep = mock.Mock()
second_ep = mock.Mock()
entry_points = mock.Mock()
entry_points.select.return_value = [first_ep, second_ep]
mock_entry_points.return_value = entry_points
load_entry_points("foo")
first_ep.load.assert_called_once_with()
second_ep.load.assert_called_once_with()
entry_points.select.assert_called_once_with(group="foo")
|