FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
winpython/tests/test_distribution.py at master · winpython/winpython · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
winpython
/
winpython
Public
Notifications
You must be signed in to change notification settings
Fork
350
Star
2.3k
Code
Issues
79
Pull requests
0
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
winpython
/
tests
/
test_distribution.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
109 lines (87 loc) · 4.07 KB
Breadcrumbs
winpython
/
tests
/
test_distribution.py
Copy path
File metadata and controls
109 lines (87 loc) · 4.07 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- coding: utf-8 -*-
"""Distribution and the -md package index.
The CLI tests cannot catch "-md described the wrong interpreter", because a
venv made from the running Python reports the same version either way. These
check which path the code actually asks about.
"""
from
pathlib
import
Path
import
pytest
from
wppm
import
utils
,
wppm
from
conftest
import
write_dist
@
pytest
.
fixture
def
target
(
tmp_path
,
monkeypatch
):
"""A synthetic distribution, with the spawning probes stubbed out."""
root
=
tmp_path
/
"WPy64-1234"
/
"python"
site
=
root
/
"Lib"
/
"site-packages"
site
.
mkdir
(
parents
=
True
)
(
root
/
"python.exe"
).
write_bytes
(
b"MZ"
)
write_dist
(
site
,
"somepkg"
,
"1.2.3"
,
summary
=
"A package"
)
monkeypatch
.
setattr
(
utils
,
"get_python_infos"
,
lambda
path
: (
"9.9"
,
64
))
return
root
@
pytest
.
fixture
def
tools_probe
(
monkeypatch
):
"""Record the path -md asks get_installed_tools about."""
seen
=
[]
def
fake
(
path
=
None
):
seen
.
append
(
path
)
return
[(
"Python"
,
"http://www.python.org/"
,
"9.9.9"
,
"stub"
)]
monkeypatch
.
setattr
(
utils
,
"get_installed_tools"
,
fake
)
return
seen
class
TestPackageIndexTarget
:
def
test_tools_are_read_from_the_target_not_the_running_interpreter
(
self
,
target
,
tools_probe
):
"""Regression: -md used to describe whatever interpreter ran wppm."""
wppm
.
Distribution
(
str
(
target
)).
get_package_index_data
()
assert
len
(
tools_probe
)
==
1
asked
=
Path
(
tools_probe
[
0
])
assert
target
in
asked
.
parents
or
asked
==
target
/
"python.exe"
def
test_explicit_directory_argument_still_wins
(
self
,
target
,
tools_probe
,
tmp_path
):
other
=
tmp_path
/
"other"
other
.
mkdir
()
(
other
/
"python.exe"
).
write_bytes
(
b"MZ"
)
wppm
.
Distribution
(
str
(
target
)).
get_package_index_data
(
python_executable_directory
=
str
(
other
)
)
assert
Path
(
tools_probe
[
0
])
==
other
/
"python.exe"
def
test_packages_come_from_the_target
(
self
,
target
,
tools_probe
):
data
=
wppm
.
Distribution
(
str
(
target
)).
get_package_index_data
()
assert
[
p
[
"name"
]
for
p
in
data
[
"packages"
]]
==
[
"somepkg"
]
def
test_identity_is_plain_python_without_winpyver2
(
self
,
target
,
tools_probe
,
monkeypatch
):
monkeypatch
.
delenv
(
"WINPYVER2"
,
raising
=
False
)
data
=
wppm
.
Distribution
(
str
(
target
)).
get_package_index_data
()
assert
data
[
"distribution"
][
"name"
]
==
"Python"
def
test_identity_is_winpython_when_told_so
(
self
,
target
,
tools_probe
):
data
=
wppm
.
Distribution
(
str
(
target
)).
get_package_index_data
(
winpyver2
=
"3.14.7.0"
,
flavor
=
"slim"
,
release_level
=
"b3"
)
assert
data
[
"distribution"
][
"name"
]
==
"WinPython"
assert
data
[
"distribution"
][
"version"
]
==
"3.14.7.0slim"
def
test_explicit_arguments_beat_the_environment
(
self
,
target
,
tools_probe
,
monkeypatch
):
"""The build passes these as env vars today; arguments must take priority."""
monkeypatch
.
setenv
(
"WINPYVER2"
,
"0.0.0.0"
)
monkeypatch
.
setenv
(
"WINPYFLAVOR"
,
"wrong"
)
data
=
wppm
.
Distribution
(
str
(
target
)).
get_package_index_data
(
winpyver2
=
"3.14.7.0"
,
flavor
=
"slim"
)
assert
data
[
"distribution"
][
"version"
]
==
"3.14.7.0slim"
class
TestVersionProbesDoNotCrash
:
"""Every version probe used to end in an unguarded splitlines()[0]."""
def
test_first_line_falls_back_when_output_is_empty
(
self
):
assert
utils
.
first_line
(
""
)
==
"?"
assert
utils
.
first_line
(
"
\n
\n
"
)
==
"?"
def
test_first_line_skips_blank_leading_lines
(
self
):
assert
utils
.
first_line
(
"
\n
\n
3.14.2
\n
rest"
)
==
"3.14.2"
def
test_installed_tools_survives_a_silent_probe
(
self
,
tmp_path
,
monkeypatch
):
"""A tool that prints nothing must not take the whole -md down."""
root
=
tmp_path
/
"python"
root
.
mkdir
()
(
root
/
"python.exe"
).
write_bytes
(
b"MZ"
)
monkeypatch
.
setattr
(
utils
,
"exec_shell_cmd"
,
lambda
*
a
,
**
k
:
""
)
tools
=
utils
.
get_installed_tools
(
str
(
root
))
assert
[
t
[
0
]
for
t
in
tools
]
==
[
"Python"
]
assert
tools
[
0
][
2
]
==
"?"
Back
|
FazBrowse Home
|
New Git URL