Coverage for tests/test_collector.py: 100.00%

Shortcuts on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

13 statements  

1# -*- coding: utf-8 -*- 

2"""Tests for the `collector` module.""" 

3from unittest import mock 

4 

5import pytest 

6 

7from mkdocstrings.handlers.base import CollectionError 

8from mkdocstrings_handlers.python import get_handler 

9 

10 

11@pytest.mark.parametrize( 

12 ("retval", "exp_res"), 

13 [ 

14 ({"error": "error1", "traceback": "hello"}, "error1\nhello"), 

15 ({"error": "error1"}, "error1"), 

16 ({"error": "", "traceback": "hello"}, "\nhello"), 

17 ], 

18) 

19def test_collect_result_error(retval, exp_res): 

20 """Test handling of errors when collecting an object. 

21 

22 Args: 

23 retval: Return value to mock `json.loads` with. 

24 exp_res: Expected result. 

25 """ 

26 with mock.patch("mkdocstrings_handlers.python.handler.json.loads") as m_loads: 

27 with pytest.raises(CollectionError) as excinfo: # noqa: PT012 

28 m_loads.return_value = retval 

29 handler = get_handler("material") 

30 assert handler.collect("", {}) 

31 assert str(excinfo.value) == exp_res