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
0bc8f31f
Commit
0bc8f31f
authored
Jan 01, 2015
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move contexts to their own module
parent
189b1c02
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
59 deletions
+69
-59
setuptools/tests/contexts.py
setuptools/tests/contexts.py
+59
-0
setuptools/tests/test_easy_install.py
setuptools/tests/test_easy_install.py
+10
-59
No files found.
setuptools/tests/contexts.py
0 → 100644
View file @
0bc8f31f
import
tempfile
import
os
import
shutil
import
sys
import
contextlib
from
..compat
import
StringIO
@
contextlib
.
contextmanager
def
tempdir
(
cd
=
lambda
dir
:
None
):
temp_dir
=
tempfile
.
mkdtemp
()
orig_dir
=
os
.
getcwd
()
try
:
cd
(
temp_dir
)
yield
temp_dir
finally
:
cd
(
orig_dir
)
shutil
.
rmtree
(
temp_dir
)
@
contextlib
.
contextmanager
def
environment
(
**
updates
):
old_env
=
os
.
environ
.
copy
()
os
.
environ
.
update
(
updates
)
try
:
yield
finally
:
for
key
in
updates
:
del
os
.
environ
[
key
]
os
.
environ
.
update
(
old_env
)
@
contextlib
.
contextmanager
def
argv
(
repl
):
old_argv
=
sys
.
argv
[:]
sys
.
argv
[:]
=
repl
yield
sys
.
argv
[:]
=
old_argv
@
contextlib
.
contextmanager
def
quiet
():
"""
Redirect stdout/stderr to StringIO objects to prevent console output from
distutils commands.
"""
old_stdout
=
sys
.
stdout
old_stderr
=
sys
.
stderr
new_stdout
=
sys
.
stdout
=
StringIO
()
new_stderr
=
sys
.
stderr
=
StringIO
()
try
:
yield
new_stdout
,
new_stderr
finally
:
new_stdout
.
seek
(
0
)
new_stderr
.
seek
(
0
)
sys
.
stdout
=
old_stdout
sys
.
stderr
=
old_stderr
setuptools/tests/test_easy_install.py
View file @
0bc8f31f
...
...
@@ -29,6 +29,7 @@ import setuptools.tests.server
import
pkg_resources
from
.py26compat
import
tarfile_open
from
.
import
contexts
def
DALS
(
input
):
...
...
@@ -264,7 +265,7 @@ class TestUserInstallTest(unittest.TestCase):
test_setup_py
=
os
.
path
.
join
(
test_pkg
,
'setup.py'
)
try
:
with
quiet_contex
t
():
with
contexts
.
quie
t
():
with
self
.
patched_setup_context
():
run_setup
(
test_setup_py
,
[
'install'
])
except
SandboxViolation
:
...
...
@@ -281,7 +282,7 @@ def distutils_package():
'from setuptools import setup'
,
'from distutils.core import setup'
,
)
with
tempdir_context
(
cd
=
os
.
chdir
):
with
contexts
.
tempdir
(
cd
=
os
.
chdir
):
with
open
(
'setup.py'
,
'w'
)
as
f
:
f
.
write
(
distutils_setup_py
)
yield
...
...
@@ -309,11 +310,11 @@ class TestSetupRequires(unittest.TestCase):
# Some platforms (Jython) don't find a port to which to bind,
# so skip this test for them.
return
with
quiet_contex
t
():
with
contexts
.
quie
t
():
# create an sdist that has a build-time dependency.
with
TestSetupRequires
.
create_sdist
()
as
dist_file
:
with
tempdir_context
()
as
temp_install_dir
:
with
environment_contex
t
(
PYTHONPATH
=
temp_install_dir
):
with
contexts
.
tempdir
()
as
temp_install_dir
:
with
contexts
.
environmen
t
(
PYTHONPATH
=
temp_install_dir
):
ei_params
=
[
'--index-url'
,
p_index
.
url
,
'--allow-hosts'
,
p_index_loc
,
...
...
@@ -321,7 +322,7 @@ class TestSetupRequires(unittest.TestCase):
'--install-dir'
,
temp_install_dir
,
dist_file
,
]
with
argv_context
([
'easy_install'
]):
with
contexts
.
argv
([
'easy_install'
]):
# attempt to install the dist. It should fail because
# it doesn't exist.
with
pytest
.
raises
(
SystemExit
):
...
...
@@ -338,7 +339,7 @@ class TestSetupRequires(unittest.TestCase):
Return an sdist with a setup_requires dependency (of something that
doesn't exist)
"""
with
tempdir_context
()
as
dir
:
with
contexts
.
tempdir
()
as
dir
:
dist_path
=
os
.
path
.
join
(
dir
,
'setuptools-test-fetcher-1.0.tar.gz'
)
script
=
DALS
(
"""
import setuptools
...
...
@@ -366,10 +367,10 @@ class TestSetupRequires(unittest.TestCase):
working_set
.
add
(
fake_dist
)
try
:
with
tempdir_context
()
as
temp_dir
:
with
contexts
.
tempdir
()
as
temp_dir
:
test_pkg
=
create_setup_requires_package
(
temp_dir
)
test_setup_py
=
os
.
path
.
join
(
test_pkg
,
'setup.py'
)
with
quiet_contex
t
()
as
(
stdout
,
stderr
):
with
contexts
.
quie
t
()
as
(
stdout
,
stderr
):
try
:
# Don't even need to install the package, just
# running the setup.py at all is sufficient
...
...
@@ -436,53 +437,3 @@ def make_trivial_sdist(dist_path, setup_py):
setup_py_file
.
size
=
len
(
setup_py_bytes
.
getvalue
())
with
tarfile_open
(
dist_path
,
'w:gz'
)
as
dist
:
dist
.
addfile
(
setup_py_file
,
fileobj
=
setup_py_bytes
)
@
contextlib
.
contextmanager
def
tempdir_context
(
cd
=
lambda
dir
:
None
):
temp_dir
=
tempfile
.
mkdtemp
()
orig_dir
=
os
.
getcwd
()
try
:
cd
(
temp_dir
)
yield
temp_dir
finally
:
cd
(
orig_dir
)
shutil
.
rmtree
(
temp_dir
)
@
contextlib
.
contextmanager
def
environment_context
(
**
updates
):
old_env
=
os
.
environ
.
copy
()
os
.
environ
.
update
(
updates
)
try
:
yield
finally
:
for
key
in
updates
:
del
os
.
environ
[
key
]
os
.
environ
.
update
(
old_env
)
@
contextlib
.
contextmanager
def
argv_context
(
repl
):
old_argv
=
sys
.
argv
[:]
sys
.
argv
[:]
=
repl
yield
sys
.
argv
[:]
=
old_argv
@
contextlib
.
contextmanager
def
quiet_context
():
"""
Redirect stdout/stderr to StringIO objects to prevent console output from
distutils commands.
"""
old_stdout
=
sys
.
stdout
old_stderr
=
sys
.
stderr
new_stdout
=
sys
.
stdout
=
StringIO
()
new_stderr
=
sys
.
stderr
=
StringIO
()
try
:
yield
new_stdout
,
new_stderr
finally
:
new_stdout
.
seek
(
0
)
new_stderr
.
seek
(
0
)
sys
.
stdout
=
old_stdout
sys
.
stderr
=
old_stderr
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