Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
GitPython/test/deprecation/test_compat.py at fix-ci · gitpython-developers/GitPython · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
gitpython-developers
/
GitPython
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
999
Star
5.2k
Code
Issues
6
Pull requests
4
Discussions
Actions
Security and quality
35
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Files
Expand file tree
fix-ci
Breadcrumbs
GitPython
/
test
/
deprecation
/
test_compat.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
84 lines (65 loc) · 2.96 KB
fix-ci
Breadcrumbs
GitPython
/
test
/
deprecation
/
test_compat.py
Copy path
Top
File metadata and controls
Code
Blame
84 lines (65 loc) · 2.96 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
"""Tests for dynamic and static characteristics of git.compat module attributes.
These tests verify that the is_<platform> attributes are available, and are even listed
in the output of dir(), but issue warnings, and that bogus (misspelled or unrecognized)
attribute access is still an error both at runtime and with mypy. This is similar to
some of the tests in test_toplevel, but the situation being tested here is simpler
because it does not involve unintuitive module aliasing or import behavior. So this only
tests attribute access, not "from" imports (whose behavior can be intuitively inferred).
"""
import
os
import
sys
if
sys
.
version_info
>=
(
3
,
11
):
from
typing
import
assert_type
else
:
from
typing_extensions
import
assert_type
import
pytest
import
git
.
compat
_MESSAGE_LEADER
=
"{} and other is_<platform> aliases are deprecated."
"""Form taken by the beginning of the warnings issued for is_<platform> access."""
def
test_cannot_access_undefined
()
->
None
:
"""Accessing a bogus attribute in git.compat remains a dynamic and static error."""
with
pytest
.
raises
(
AttributeError
):
git
.
compat
.
foo
# type: ignore[attr-defined]
def
test_is_platform
()
->
None
:
"""The is_<platform> attributes work, warn, and mypy accepts code accessing them."""
fully_qualified_names
=
[
"git.compat.is_win"
,
"git.compat.is_posix"
,
"git.compat.is_darwin"
,
]
with
pytest
.
deprecated_call
()
as
ctx
:
is_win
=
git
.
compat
.
is_win
is_posix
=
git
.
compat
.
is_posix
is_darwin
=
git
.
compat
.
is_darwin
assert_type
(
is_win
,
bool
)
assert_type
(
is_posix
,
bool
)
assert_type
(
is_darwin
,
bool
)
messages
=
[
str
(
entry
.
message
)
for
entry
in
ctx
]
assert
len
(
messages
)
==
3
for
fullname
,
message
in
zip
(
fully_qualified_names
,
messages
):
assert
message
.
startswith
(
_MESSAGE_LEADER
.
format
(
fullname
))
# These assertions exactly reproduce the expressions in the code under test, so they
# are not good for testing that the values are correct. Instead, their purpose is to
# ensure that any dynamic machinery put in place in git.compat to cause warnings to
# be issued does not get in the way of the intended values being accessed.
assert
is_win
==
(
os
.
name
==
"nt"
)
assert
is_posix
==
(
os
.
name
==
"posix"
)
assert
is_darwin
==
(
sys
.
platform
==
"darwin"
)
def
test_dir
()
->
None
:
"""dir() on git.compat includes all public attributes, even if deprecated.
As dir() usually does, it also has nonpublic attributes, which should also not be
removed by a custom __dir__ function, but those are less important to test.
"""
expected_subset
=
{
"is_win"
,
"is_posix"
,
"is_darwin"
,
"defenc"
,
"safe_decode"
,
"safe_encode"
,
"win_encode"
,
}
actual
=
set
(
dir
(
git
.
compat
))
assert
expected_subset
<=
actual
You can’t perform that action at this time.