@@ -1632,3 +1632,95 @@ def test_autodoc_pydantic_field_swap_name_and_alias_true_directive_global(parse_
16321632 },
16331633 )
16341634 assert_node (doctree , output_nodes )
1635+
1636+
1637+ def test_autodoc_pydantic_field_show_examples_true (autodocument ):
1638+ kwargs = dict (
1639+ object_path = 'target.configuration.FieldShowExamples.field' , ** KWARGS
1640+ )
1641+
1642+ result = [
1643+ '' ,
1644+ '.. py:pydantic_field:: FieldShowExamples.field' ,
1645+ ' :module: target.configuration' ,
1646+ ' :type: int' ,
1647+ '' ,
1648+ ' Field.' ,
1649+ '' ,
1650+ ' :Examples:' ,
1651+ ' - 2' ,
1652+ ' - 3' ,
1653+ '' ,
1654+ ]
1655+
1656+ # explicit local
1657+ actual = autodocument (options_doc = {'field-show-examples' : True }, ** kwargs )
1658+ assert result == actual
1659+
1660+ # explicit local overwrite global
1661+ actual = autodocument (
1662+ options_app = {'autodoc_pydantic_field_show_examples' : False },
1663+ options_doc = {'field-show-examples' : True },
1664+ ** kwargs ,
1665+ )
1666+ assert result == actual
1667+
1668+
1669+ def test_autodoc_pydantic_field_show_examples_false (autodocument ):
1670+ kwargs = dict (
1671+ object_path = 'target.configuration.FieldShowExamples.field' , ** KWARGS
1672+ )
1673+
1674+ result = [
1675+ '' ,
1676+ '.. py:pydantic_field:: FieldShowExamples.field' ,
1677+ ' :module: target.configuration' ,
1678+ ' :type: int' ,
1679+ '' ,
1680+ ' Field.' ,
1681+ '' ,
1682+ ]
1683+
1684+ # explicit local
1685+ actual = autodocument (options_doc = {'field-show-examples' : False }, ** kwargs )
1686+ assert result == actual
1687+
1688+ # explicit local overwrite global
1689+ actual = autodocument (
1690+ options_app = {'autodoc_pydantic_field_show_examples' : True },
1691+ options_doc = {'field-show-examples' : False },
1692+ ** kwargs ,
1693+ )
1694+ assert result == actual
1695+
1696+
1697+ def test_autodoc_pydantic_field_show_examples_ignore_extra (autodocument ):
1698+ kwargs = dict (
1699+ object_path = 'target.configuration.FieldShowExamplesExtra.field' , ** KWARGS
1700+ )
1701+
1702+ result = [
1703+ '' ,
1704+ '.. py:pydantic_field:: FieldShowExamplesExtra.field' ,
1705+ ' :module: target.configuration' ,
1706+ ' :type: int' ,
1707+ '' ,
1708+ ' Field.' ,
1709+ '' ,
1710+ ' :Examples:' ,
1711+ ' - 2' ,
1712+ ' - 3' ,
1713+ '' ,
1714+ ]
1715+
1716+ # explicit local
1717+ actual = autodocument (options_doc = {'field-show-examples' : True }, ** kwargs )
1718+ assert result == actual
1719+
1720+ # explicit local overwrite global
1721+ actual = autodocument (
1722+ options_app = {'autodoc_pydantic_field_show_examples' : False },
1723+ options_doc = {'field-show-examples' : True },
1724+ ** kwargs ,
1725+ )
1726+ assert result == actual
0 commit comments