Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
6d0daf14
Commit
6d0daf14
authored
Jan 27, 2019
by
Paul Ganssle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wrap build_meta tests in a reusable test class
parent
f40a47a7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
134 additions
and
134 deletions
+134
-134
setuptools/tests/test_build_meta.py
setuptools/tests/test_build_meta.py
+134
-134
No files found.
setuptools/tests/test_build_meta.py
View file @
6d0daf14
...
...
@@ -6,7 +6,6 @@ import tarfile
import
pytest
from
setuptools.build_meta
import
build_sdist
from
.files
import
build_files
from
.textwrap
import
DALS
from
.
import
py2_only
...
...
@@ -103,136 +102,137 @@ defns = [
]
@
pytest
.
fixture
(
params
=
defns
)
def
build_backend
(
tmpdir
,
request
):
build_files
(
request
.
param
,
prefix
=
str
(
tmpdir
))
with
tmpdir
.
as_cwd
():
yield
BuildBackend
(
cwd
=
'.'
)
def
test_get_requires_for_build_wheel
(
build_backend
):
actual
=
build_backend
.
get_requires_for_build_wheel
()
expected
=
[
'six'
,
'wheel'
]
assert
sorted
(
actual
)
==
sorted
(
expected
)
def
test_get_requires_for_build_sdist
(
build_backend
):
actual
=
build_backend
.
get_requires_for_build_sdist
()
expected
=
[
'six'
]
assert
sorted
(
actual
)
==
sorted
(
expected
)
def
test_build_wheel
(
build_backend
):
dist_dir
=
os
.
path
.
abspath
(
'pip-wheel'
)
os
.
makedirs
(
dist_dir
)
wheel_name
=
build_backend
.
build_wheel
(
dist_dir
)
assert
os
.
path
.
isfile
(
os
.
path
.
join
(
dist_dir
,
wheel_name
))
def
test_build_sdist
(
build_backend
):
dist_dir
=
os
.
path
.
abspath
(
'pip-sdist'
)
os
.
makedirs
(
dist_dir
)
sdist_name
=
build_backend
.
build_sdist
(
dist_dir
)
assert
os
.
path
.
isfile
(
os
.
path
.
join
(
dist_dir
,
sdist_name
))
def
test_prepare_metadata_for_build_wheel
(
build_backend
):
dist_dir
=
os
.
path
.
abspath
(
'pip-dist-info'
)
os
.
makedirs
(
dist_dir
)
dist_info
=
build_backend
.
prepare_metadata_for_build_wheel
(
dist_dir
)
assert
os
.
path
.
isfile
(
os
.
path
.
join
(
dist_dir
,
dist_info
,
'METADATA'
))
@
py2_only
def
test_prepare_metadata_for_build_wheel_with_str
(
build_backend
):
dist_dir
=
os
.
path
.
abspath
(
str
(
'pip-dist-info'
))
os
.
makedirs
(
dist_dir
)
dist_info
=
build_backend
.
prepare_metadata_for_build_wheel
(
dist_dir
)
assert
os
.
path
.
isfile
(
os
.
path
.
join
(
dist_dir
,
dist_info
,
'METADATA'
))
def
test_build_sdist_explicit_dist
(
build_backend
):
# explicitly specifying the dist folder should work
# the folder sdist_directory and the ``--dist-dir`` can be the same
dist_dir
=
os
.
path
.
abspath
(
'dist'
)
sdist_name
=
build_backend
.
build_sdist
(
dist_dir
)
assert
os
.
path
.
isfile
(
os
.
path
.
join
(
dist_dir
,
sdist_name
))
def
test_build_sdist_version_change
(
build_backend
):
sdist_into_directory
=
os
.
path
.
abspath
(
"out_sdist"
)
os
.
makedirs
(
sdist_into_directory
)
sdist_name
=
build_backend
.
build_sdist
(
sdist_into_directory
)
assert
os
.
path
.
isfile
(
os
.
path
.
join
(
sdist_into_directory
,
sdist_name
))
# if the setup.py changes subsequent call of the build meta
# should still succeed, given the
# sdist_directory the frontend specifies is empty
with
open
(
os
.
path
.
abspath
(
"setup.py"
),
'rt'
)
as
file_handler
:
content
=
file_handler
.
read
()
with
open
(
os
.
path
.
abspath
(
"setup.py"
),
'wt'
)
as
file_handler
:
file_handler
.
write
(
content
.
replace
(
"version='0.0.0'"
,
"version='0.0.1'"
))
shutil
.
rmtree
(
sdist_into_directory
)
os
.
makedirs
(
sdist_into_directory
)
sdist_name
=
build_backend
.
build_sdist
(
"out_sdist"
)
assert
os
.
path
.
isfile
(
os
.
path
.
join
(
os
.
path
.
abspath
(
"out_sdist"
),
sdist_name
))
def
test_build_sdist_setup_py_exists
(
tmpdir_cwd
):
# If build_sdist is called from a script other than setup.py,
# ensure setup.py is include
build_files
(
defns
[
0
])
targz_path
=
build_sdist
(
"temp"
)
with
tarfile
.
open
(
os
.
path
.
join
(
"temp"
,
targz_path
))
as
tar
:
assert
any
(
'setup.py'
in
name
for
name
in
tar
.
getnames
())
def
test_build_sdist_setup_py_manifest_excluded
(
tmpdir_cwd
):
# Ensure that MANIFEST.in can exclude setup.py
files
=
{
'setup.py'
:
DALS
(
"""
__import__('setuptools').setup(
name='foo',
version='0.0.0',
py_modules=['hello']
)"""
),
'hello.py'
:
''
,
'MANIFEST.in'
:
DALS
(
"""
exclude setup.py
"""
)
}
build_files
(
files
)
targz_path
=
build_sdist
(
"temp"
)
with
tarfile
.
open
(
os
.
path
.
join
(
"temp"
,
targz_path
))
as
tar
:
assert
not
any
(
'setup.py'
in
name
for
name
in
tar
.
getnames
())
def
test_build_sdist_builds_targz_even_if_zip_indicated
(
tmpdir_cwd
):
files
=
{
'setup.py'
:
DALS
(
"""
__import__('setuptools').setup(
name='foo',
version='0.0.0',
py_modules=['hello']
)"""
),
'hello.py'
:
''
,
'setup.cfg'
:
DALS
(
"""
[sdist]
formats=zip
"""
)
}
build_files
(
files
)
build_sdist
(
"temp"
)
class
TestBuildMetaBackend
:
backend_name
=
'setuptools.build_meta'
def
get_build_backend
(
self
):
return
BuildBackend
(
cwd
=
'.'
,
backend_name
=
self
.
backend_name
)
@
pytest
.
fixture
(
params
=
defns
)
def
build_backend
(
self
,
tmpdir
,
request
):
build_files
(
request
.
param
,
prefix
=
str
(
tmpdir
))
with
tmpdir
.
as_cwd
():
yield
self
.
get_build_backend
()
def
test_get_requires_for_build_wheel
(
self
,
build_backend
):
actual
=
build_backend
.
get_requires_for_build_wheel
()
expected
=
[
'six'
,
'wheel'
]
assert
sorted
(
actual
)
==
sorted
(
expected
)
def
test_get_requires_for_build_sdist
(
self
,
build_backend
):
actual
=
build_backend
.
get_requires_for_build_sdist
()
expected
=
[
'six'
]
assert
sorted
(
actual
)
==
sorted
(
expected
)
def
test_build_wheel
(
self
,
build_backend
):
dist_dir
=
os
.
path
.
abspath
(
'pip-wheel'
)
os
.
makedirs
(
dist_dir
)
wheel_name
=
build_backend
.
build_wheel
(
dist_dir
)
assert
os
.
path
.
isfile
(
os
.
path
.
join
(
dist_dir
,
wheel_name
))
def
test_build_sdist
(
self
,
build_backend
):
dist_dir
=
os
.
path
.
abspath
(
'pip-sdist'
)
os
.
makedirs
(
dist_dir
)
sdist_name
=
build_backend
.
build_sdist
(
dist_dir
)
assert
os
.
path
.
isfile
(
os
.
path
.
join
(
dist_dir
,
sdist_name
))
def
test_prepare_metadata_for_build_wheel
(
self
,
build_backend
):
dist_dir
=
os
.
path
.
abspath
(
'pip-dist-info'
)
os
.
makedirs
(
dist_dir
)
dist_info
=
build_backend
.
prepare_metadata_for_build_wheel
(
dist_dir
)
assert
os
.
path
.
isfile
(
os
.
path
.
join
(
dist_dir
,
dist_info
,
'METADATA'
))
@
py2_only
def
test_prepare_metadata_for_build_wheel_with_str
(
self
,
build_backend
):
dist_dir
=
os
.
path
.
abspath
(
str
(
'pip-dist-info'
))
os
.
makedirs
(
dist_dir
)
dist_info
=
build_backend
.
prepare_metadata_for_build_wheel
(
dist_dir
)
assert
os
.
path
.
isfile
(
os
.
path
.
join
(
dist_dir
,
dist_info
,
'METADATA'
))
def
test_build_sdist_explicit_dist
(
self
,
build_backend
):
# explicitly specifying the dist folder should work
# the folder sdist_directory and the ``--dist-dir`` can be the same
dist_dir
=
os
.
path
.
abspath
(
'dist'
)
sdist_name
=
build_backend
.
build_sdist
(
dist_dir
)
assert
os
.
path
.
isfile
(
os
.
path
.
join
(
dist_dir
,
sdist_name
))
def
test_build_sdist_version_change
(
self
,
build_backend
):
sdist_into_directory
=
os
.
path
.
abspath
(
"out_sdist"
)
os
.
makedirs
(
sdist_into_directory
)
sdist_name
=
build_backend
.
build_sdist
(
sdist_into_directory
)
assert
os
.
path
.
isfile
(
os
.
path
.
join
(
sdist_into_directory
,
sdist_name
))
# if the setup.py changes subsequent call of the build meta
# should still succeed, given the
# sdist_directory the frontend specifies is empty
with
open
(
os
.
path
.
abspath
(
"setup.py"
),
'rt'
)
as
file_handler
:
content
=
file_handler
.
read
()
with
open
(
os
.
path
.
abspath
(
"setup.py"
),
'wt'
)
as
file_handler
:
file_handler
.
write
(
content
.
replace
(
"version='0.0.0'"
,
"version='0.0.1'"
))
shutil
.
rmtree
(
sdist_into_directory
)
os
.
makedirs
(
sdist_into_directory
)
sdist_name
=
build_backend
.
build_sdist
(
"out_sdist"
)
assert
os
.
path
.
isfile
(
os
.
path
.
join
(
os
.
path
.
abspath
(
"out_sdist"
),
sdist_name
))
def
test_build_sdist_setup_py_exists
(
self
,
tmpdir_cwd
):
# If build_sdist is called from a script other than setup.py,
# ensure setup.py is included
build_files
(
defns
[
0
])
build_backend
=
self
.
get_build_backend
()
targz_path
=
build_backend
.
build_sdist
(
"temp"
)
with
tarfile
.
open
(
os
.
path
.
join
(
"temp"
,
targz_path
))
as
tar
:
assert
any
(
'setup.py'
in
name
for
name
in
tar
.
getnames
())
def
test_build_sdist_setup_py_manifest_excluded
(
self
,
tmpdir_cwd
):
# Ensure that MANIFEST.in can exclude setup.py
files
=
{
'setup.py'
:
DALS
(
"""
__import__('setuptools').setup(
name='foo',
version='0.0.0',
py_modules=['hello']
)"""
),
'hello.py'
:
''
,
'MANIFEST.in'
:
DALS
(
"""
exclude setup.py
"""
)
}
build_files
(
files
)
build_backend
=
self
.
get_build_backend
()
targz_path
=
build_backend
.
build_sdist
(
"temp"
)
with
tarfile
.
open
(
os
.
path
.
join
(
"temp"
,
targz_path
))
as
tar
:
assert
not
any
(
'setup.py'
in
name
for
name
in
tar
.
getnames
())
def
test_build_sdist_builds_targz_even_if_zip_indicated
(
self
,
tmpdir_cwd
):
files
=
{
'setup.py'
:
DALS
(
"""
__import__('setuptools').setup(
name='foo',
version='0.0.0',
py_modules=['hello']
)"""
),
'hello.py'
:
''
,
'setup.cfg'
:
DALS
(
"""
[sdist]
formats=zip
"""
)
}
build_files
(
files
)
build_backend
=
self
.
get_build_backend
()
build_backend
.
build_sdist
(
"temp"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment