|
| 1 | +"""Tests for dynamic and static characteristics of git.types module attributes.""" |
| 2 | + |
| 3 | +importsys |
| 4 | + |
| 5 | +ifsys.version_info>= (3,8): |
| 6 | +fromtypingimportLiteral |
| 7 | +else: |
| 8 | +fromtyping_extensionsimportLiteral |
| 9 | + |
| 10 | +importpytest |
| 11 | + |
| 12 | +importgit.types |
| 13 | + |
| 14 | + |
| 15 | +deftest_cannot_access_undefined()->None: |
| 16 | +"""Accessing a bogus attribute in git.types remains a dynamic and static error.""" |
| 17 | +withpytest.raises(AttributeError): |
| 18 | +git.types.foo# type: ignore[attr-defined] |
| 19 | + |
| 20 | + |
| 21 | +deftest_lit_commit_ish()->None: |
| 22 | +""" """ |
| 23 | +# It would be fine to test attribute access rather than a "from" import. But a |
| 24 | +# "from" import is more likely to appear in actual usage, so it is used here. |
| 25 | +withpytest.deprecated_call()asctx: |
| 26 | +fromgit.typesimportLit_commit_ish |
| 27 | + |
| 28 | +# As noted in test_toplevel.test_util_alias_import, there may be multiple warnings, |
| 29 | +# but all with the same message. |
| 30 | + (message,)= {str(entry.message)forentryinctx} |
| 31 | +assert"Lit_commit_ish is deprecated."inmessage |
| 32 | +assert'Literal["commit", "tag", "blob", "tree"]'inmessage,"Has old definition." |
| 33 | +assert'Literal["commit", "tag"]'inmessage,"Has new definition." |
| 34 | +assert"GitObjectTypeString"inmessage,"Has new type name for old definition." |
| 35 | + |
| 36 | +_:Lit_commit_ish="commit"# type: ignore[valid-type] |
| 37 | + |
| 38 | +# It should be as documented (even though deliberately unusable in static checks). |
| 39 | +assertLit_commit_ish==Literal["commit","tag"] |