File: test_hooks.py

package info (click to toggle)
python-xsdata 24.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,936 kB
  • sloc: python: 29,257; xml: 404; makefile: 27; sh: 6
file content (35 lines) | stat: -rw-r--r-- 1,204 bytes parent folder | download
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")