From 3bcf6213d25381d9df9baa2b7a16c9449fbf78e7 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 24 Nov 2015 18:55:48 -0500 Subject: Use context manager for opening file --- setuptools/tests/test_develop.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'setuptools/tests/test_develop.py') diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py index ed1b194a..b920655d 100644 --- a/setuptools/tests/test_develop.py +++ b/setuptools/tests/test_develop.py @@ -32,15 +32,13 @@ class TestDevelopTest: os.mkdir(os.path.join(self.dir, 'foo')) # setup.py setup = os.path.join(self.dir, 'setup.py') - f = open(setup, 'w') - f.write(SETUP_PY) - f.close() + with open(setup, 'w') as f: + f.write(SETUP_PY) self.old_cwd = os.getcwd() # foo/__init__.py init = os.path.join(self.dir, 'foo', '__init__.py') - f = open(init, 'w') - f.write(INIT_PY) - f.close() + with open(init, 'w') as f: + f.write(INIT_PY) os.chdir(self.dir) self.old_base = site.USER_BASE -- cgit v1.2.1 From bc7f3b0a36a1c676809f89eae7299afbb7f70f32 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 24 Nov 2015 19:32:13 -0500 Subject: Extract setup/teardown methods as proper fixtures. --- setuptools/tests/test_develop.py | 57 +++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 27 deletions(-) (limited to 'setuptools/tests/test_develop.py') diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py index b920655d..96b9f4ef 100644 --- a/setuptools/tests/test_develop.py +++ b/setuptools/tests/test_develop.py @@ -6,8 +6,12 @@ import site import sys import tempfile +import pytest + from setuptools.command.develop import develop from setuptools.dist import Distribution +from . import contexts + SETUP_PY = """\ from setuptools import setup @@ -21,43 +25,42 @@ setup(name='foo', INIT_PY = """print "foo" """ +@pytest.yield_fixture +def temp_user(monkeypatch): + with contexts.tempdir() as user_base: + with contexts.tempdir() as user_site: + monkeypatch.setattr('site.USER_BASE', user_base) + monkeypatch.setattr('site.USER_SITE', user_site) + yield + + +@pytest.yield_fixture +def test_env(tmpdir, temp_user): + target = tmpdir + foo = target.mkdir('foo') + setup = target / 'setup.py' + if setup.isfile(): + raise ValueError(dir(target)) + with setup.open('w') as f: + f.write(SETUP_PY) + init = foo / '__init__.py' + with init.open('w') as f: + f.write(INIT_PY) + with target.as_cwd(): + yield target + + class TestDevelopTest: def setup_method(self, method): if hasattr(sys, 'real_prefix'): return - # Directory structure - self.dir = tempfile.mkdtemp() - os.mkdir(os.path.join(self.dir, 'foo')) - # setup.py - setup = os.path.join(self.dir, 'setup.py') - with open(setup, 'w') as f: - f.write(SETUP_PY) - self.old_cwd = os.getcwd() - # foo/__init__.py - init = os.path.join(self.dir, 'foo', '__init__.py') - with open(init, 'w') as f: - f.write(INIT_PY) - - os.chdir(self.dir) - self.old_base = site.USER_BASE - site.USER_BASE = tempfile.mkdtemp() - self.old_site = site.USER_SITE - site.USER_SITE = tempfile.mkdtemp() - def teardown_method(self, method): if hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix): return - os.chdir(self.old_cwd) - shutil.rmtree(self.dir) - shutil.rmtree(site.USER_BASE) - shutil.rmtree(site.USER_SITE) - site.USER_BASE = self.old_base - site.USER_SITE = self.old_site - - def test_develop(self): + def test_develop(self, test_env): if hasattr(sys, 'real_prefix'): return dist = Distribution( -- cgit v1.2.1 From 448cfc53cd16fb11562def2ee8b9bf66ed178b21 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 24 Nov 2015 19:37:11 -0500 Subject: Replace silent test acceptance with a proper skip check --- setuptools/tests/test_develop.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'setuptools/tests/test_develop.py') diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py index 96b9f4ef..2baf83bb 100644 --- a/setuptools/tests/test_develop.py +++ b/setuptools/tests/test_develop.py @@ -51,18 +51,9 @@ def test_env(tmpdir, temp_user): class TestDevelopTest: - - def setup_method(self, method): - if hasattr(sys, 'real_prefix'): - return - - def teardown_method(self, method): - if hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix): - return - + @pytest.mark.skipif(hasattr(sys, 'real_prefix'), + reason="Cannot run when invoked in a virtualenv") def test_develop(self, test_env): - if hasattr(sys, 'real_prefix'): - return dist = Distribution( dict(name='foo', packages=['foo'], -- cgit v1.2.1 From e1e3570fb01aa4f1fe6d0e56cfb73d38b781a307 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 24 Nov 2015 19:38:13 -0500 Subject: Extract variable --- setuptools/tests/test_develop.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'setuptools/tests/test_develop.py') diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py index 2baf83bb..49e007e6 100644 --- a/setuptools/tests/test_develop.py +++ b/setuptools/tests/test_develop.py @@ -54,12 +54,13 @@ class TestDevelopTest: @pytest.mark.skipif(hasattr(sys, 'real_prefix'), reason="Cannot run when invoked in a virtualenv") def test_develop(self, test_env): - dist = Distribution( - dict(name='foo', - packages=['foo'], - use_2to3=True, - version='0.0', - )) + settings = dict( + name='foo', + packages=['foo'], + use_2to3=True, + version='0.0', + ) + dist = Distribution(settings) dist.script_name = 'setup.py' cmd = develop(dist) cmd.user = 1 -- cgit v1.2.1 From 731c83fd5ebe79a7643465e68310c11387b427e8 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 24 Nov 2015 19:41:32 -0500 Subject: Remove unused imports --- setuptools/tests/test_develop.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'setuptools/tests/test_develop.py') diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py index 49e007e6..962c4f3c 100644 --- a/setuptools/tests/test_develop.py +++ b/setuptools/tests/test_develop.py @@ -1,10 +1,8 @@ """develop tests """ import os -import shutil import site import sys -import tempfile import pytest -- cgit v1.2.1 From 693f20d40fca6b41ac629665901c350cd3dcd4e8 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 24 Nov 2015 19:45:12 -0500 Subject: Use quiet context to suppress stdout. --- setuptools/tests/test_develop.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'setuptools/tests/test_develop.py') diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py index 962c4f3c..f0adcb18 100644 --- a/setuptools/tests/test_develop.py +++ b/setuptools/tests/test_develop.py @@ -65,12 +65,8 @@ class TestDevelopTest: cmd.ensure_finalized() cmd.install_dir = site.USER_SITE cmd.user = 1 - old_stdout = sys.stdout - #sys.stdout = StringIO() - try: + with contexts.quiet(): cmd.run() - finally: - sys.stdout = old_stdout # let's see if we got our egg link at the right place content = os.listdir(site.USER_SITE) -- cgit v1.2.1 From 0861296a63b3fafd059759840fb62ba12d4e6adc Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 24 Nov 2015 19:47:58 -0500 Subject: Use io.open and its context for simpler reading of a file --- setuptools/tests/test_develop.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'setuptools/tests/test_develop.py') diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py index f0adcb18..ec655462 100644 --- a/setuptools/tests/test_develop.py +++ b/setuptools/tests/test_develop.py @@ -3,6 +3,7 @@ import os import site import sys +import io import pytest @@ -74,16 +75,12 @@ class TestDevelopTest: assert content == ['easy-install.pth', 'foo.egg-link'] # Check that we are using the right code. - egg_link_file = open(os.path.join(site.USER_SITE, 'foo.egg-link'), 'rt') - try: + fn = os.path.join(site.USER_SITE, 'foo.egg-link') + with io.open(fn) as egg_link_file: path = egg_link_file.read().split()[0].strip() - finally: - egg_link_file.close() - init_file = open(os.path.join(path, 'foo', '__init__.py'), 'rt') - try: + fn = os.path.join(path, 'foo', '__init__.py') + with io.open(fn) as init_file: init = init_file.read().strip() - finally: - init_file.close() if sys.version < "3": assert init == 'print "foo"' else: -- cgit v1.2.1 From 951a3b9df51c1c46a39753dc6f2854ea18f45729 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 24 Nov 2015 20:01:32 -0500 Subject: Use if clause. --- setuptools/tests/test_develop.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'setuptools/tests/test_develop.py') diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py index ec655462..35f3ea25 100644 --- a/setuptools/tests/test_develop.py +++ b/setuptools/tests/test_develop.py @@ -10,6 +10,7 @@ import pytest from setuptools.command.develop import develop from setuptools.dist import Distribution from . import contexts +from setuptools.compat import PY3 SETUP_PY = """\ @@ -81,7 +82,6 @@ class TestDevelopTest: fn = os.path.join(path, 'foo', '__init__.py') with io.open(fn) as init_file: init = init_file.read().strip() - if sys.version < "3": - assert init == 'print "foo"' - else: - assert init == 'print("foo")' + + expected = 'print("foo")' if PY3 else 'print "foo"' + assert init == expected -- cgit v1.2.1 From 436be23a0ac5d7f21f261bdcd6fd9119a4f55346 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 24 Nov 2015 20:38:52 -0500 Subject: Rename tests for clarity --- setuptools/tests/test_develop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/tests/test_develop.py') diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py index 35f3ea25..725c4ce2 100644 --- a/setuptools/tests/test_develop.py +++ b/setuptools/tests/test_develop.py @@ -50,10 +50,10 @@ def test_env(tmpdir, temp_user): yield target -class TestDevelopTest: +class TestDevelop: @pytest.mark.skipif(hasattr(sys, 'real_prefix'), reason="Cannot run when invoked in a virtualenv") - def test_develop(self, test_env): + def test_2to3_user_mode(self, test_env): settings = dict( name='foo', packages=['foo'], -- cgit v1.2.1 From 7bd76e0869310de9da5a32ca2c860f6a1fa461b5 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 24 Nov 2015 21:21:09 -0500 Subject: Draft a test for testing the new expectation for develop command (and general functionality when console scripts are present). --- setuptools/tests/test_develop.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'setuptools/tests/test_develop.py') diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py index 725c4ce2..71f0d69a 100644 --- a/setuptools/tests/test_develop.py +++ b/setuptools/tests/test_develop.py @@ -85,3 +85,28 @@ class TestDevelop: expected = 'print("foo")' if PY3 else 'print "foo"' assert init == expected + + def test_console_scripts(self, tmpdir): + """ + Test that console scripts are installed and that they reference + only the project by name and not the current version. + """ + pytest.skip("TODO: needs a fixture to cause 'develop' " + "to be invoked without mutating environment.") + settings = dict( + name='foo', + packages=['foo'], + version='0.0', + entry_points={ + 'console_scripts': [ + 'foocmd = foo:foo', + ], + }, + ) + dist = Distribution(settings) + dist.script_name = 'setup.py' + cmd = develop(dist) + cmd.ensure_finalized() + cmd.install_dir = tmpdir + cmd.run() + #assert '0.0' not in foocmd_text -- cgit v1.2.1 From 75a571e4d9d5f5c3fde661c54a368b533be1978b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 25 Nov 2015 10:04:33 -0500 Subject: Skip the test when running under venv also --- setuptools/tests/test_develop.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'setuptools/tests/test_develop.py') diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py index 71f0d69a..ab5da00e 100644 --- a/setuptools/tests/test_develop.py +++ b/setuptools/tests/test_develop.py @@ -51,8 +51,10 @@ def test_env(tmpdir, temp_user): class TestDevelop: - @pytest.mark.skipif(hasattr(sys, 'real_prefix'), - reason="Cannot run when invoked in a virtualenv") + in_virtualenv = hasattr(sys, 'real_prefix') + in_venv = hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix + @pytest.mark.skipif(in_virtualenv or in_venv, + reason="Cannot run when invoked in a virtualenv or venv") def test_2to3_user_mode(self, test_env): settings = dict( name='foo', -- cgit v1.2.1