From 0c79e4d09cf429a2aabbcb6d4cf1455ec45a0137 Mon Sep 17 00:00:00 2001 From: Alexander Duryagin Date: Fri, 11 Jan 2019 15:29:40 +0300 Subject: include pyproject.toml in sdist (#1632) --- setuptools/tests/test_sdist.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index d2c4e0cf..06813a00 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -449,6 +449,20 @@ class TestSdistTest: except UnicodeDecodeError: filename not in cmd.filelist.files + def test_pyproject_toml_in_sdist(self): + """ + Check if pyproject.toml is included in source distribution if present + """ + open(os.path.join(self.temp_dir, 'pyproject.toml'), 'w').close() + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + cmd = sdist(dist) + cmd.ensure_finalized() + with quiet(): + cmd.run() + manifest = cmd.filelist.files + assert 'pyproject.toml' in manifest + def test_default_revctrl(): """ -- cgit v1.2.1 From f171cde1505fc5df438417dc5ae48d35fa60a002 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 31 Dec 2019 12:47:46 -0500 Subject: Add test for exclusion expectation. Ref #1650. --- setuptools/tests/test_sdist.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 06813a00..a413e4ed 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -463,6 +463,22 @@ class TestSdistTest: manifest = cmd.filelist.files assert 'pyproject.toml' in manifest + def test_pyproject_toml_excluded(self): + """ + Check that pyproject.toml can excluded even if present + """ + open(os.path.join(self.temp_dir, 'pyproject.toml'), 'w').close() + with open('MANIFEST.in', 'w') as mts: + print('exclude pyproject.toml', file=mts) + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + cmd = sdist(dist) + cmd.ensure_finalized() + with quiet(): + cmd.run() + manifest = cmd.filelist.files + assert 'pyproject.toml' not in manifest + def test_default_revctrl(): """ -- cgit v1.2.1 From 2eb3ba19f3153f83eb8b2470deb8ec02d21fca52 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 31 Dec 2019 12:50:25 -0500 Subject: Restore Python 2.7 compatibility --- setuptools/tests/test_sdist.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index a413e4ed..b27c4a83 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- """sdist tests""" +from __future__ import print_function + import os import shutil import sys -- cgit v1.2.1 From 9c40ab8861d1bbc18d1c8032f678e2ca15ada7ff Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 31 Dec 2019 13:29:43 -0500 Subject: Rewrite TestSdistTest setup/teardown_method as pytest fixture. --- setuptools/tests/test_sdist.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index b27c4a83..f2e9a5ec 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -91,30 +91,29 @@ fail_on_latin1_encoded_filenames = pytest.mark.xfail( ) +def touch(path): + path.write_text('', encoding='utf-8') + + class TestSdistTest: - def setup_method(self, method): - self.temp_dir = tempfile.mkdtemp() - with open(os.path.join(self.temp_dir, 'setup.py'), 'w') as f: - f.write(SETUP_PY) + @pytest.fixture(autouse=True) + def source_dir(self, tmpdir): + self.temp_dir = str(tmpdir) + (tmpdir / 'setup.py').write_text(SETUP_PY, encoding='utf-8') # Set up the rest of the test package - test_pkg = os.path.join(self.temp_dir, 'sdist_test') - os.mkdir(test_pkg) - data_folder = os.path.join(self.temp_dir, "d") - os.mkdir(data_folder) + test_pkg = tmpdir / 'sdist_test' + test_pkg.mkdir() + data_folder = tmpdir / 'd' + data_folder.mkdir() # *.rst was not included in package_data, so c.rst should not be # automatically added to the manifest when not under version control - for fname in ['__init__.py', 'a.txt', 'b.txt', 'c.rst', - os.path.join(data_folder, "e.dat")]: - # Just touch the files; their contents are irrelevant - open(os.path.join(test_pkg, fname), 'w').close() - - self.old_cwd = os.getcwd() - os.chdir(self.temp_dir) + for fname in ['__init__.py', 'a.txt', 'b.txt', 'c.rst']: + touch(test_pkg / fname) + touch(data_folder / 'e.dat') - def teardown_method(self, method): - os.chdir(self.old_cwd) - shutil.rmtree(self.temp_dir) + with tmpdir.as_cwd(): + yield def test_package_data_in_sdist(self): """Regression test for pull request #4: ensures that files listed in -- cgit v1.2.1 From 9e3149802ee214ee0500ec299250bf4febc67e52 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 31 Dec 2019 13:31:37 -0500 Subject: Remove instance attribute; rely on tmpdir fixture; re-use touch helper. --- setuptools/tests/test_sdist.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index f2e9a5ec..1b951a5b 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -98,7 +98,6 @@ def touch(path): class TestSdistTest: @pytest.fixture(autouse=True) def source_dir(self, tmpdir): - self.temp_dir = str(tmpdir) (tmpdir / 'setup.py').write_text(SETUP_PY, encoding='utf-8') # Set up the rest of the test package @@ -176,14 +175,14 @@ class TestSdistTest: manifest = cmd.filelist.files assert 'setup.py' not in manifest - def test_defaults_case_sensitivity(self): + def test_defaults_case_sensitivity(self, tmpdir): """ Make sure default files (README.*, etc.) are added in a case-sensitive way to avoid problems with packages built on Windows. """ - open(os.path.join(self.temp_dir, 'readme.rst'), 'w').close() - open(os.path.join(self.temp_dir, 'SETUP.cfg'), 'w').close() + touch(tmpdir / 'readme.rst') + touch(tmpdir / 'SETUP.cfg') dist = Distribution(SETUP_ATTRS) # the extension deliberately capitalized for this test @@ -450,11 +449,11 @@ class TestSdistTest: except UnicodeDecodeError: filename not in cmd.filelist.files - def test_pyproject_toml_in_sdist(self): + def test_pyproject_toml_in_sdist(self, tmpdir): """ Check if pyproject.toml is included in source distribution if present """ - open(os.path.join(self.temp_dir, 'pyproject.toml'), 'w').close() + touch(tmpdir / 'pyproject.toml') dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) @@ -464,11 +463,11 @@ class TestSdistTest: manifest = cmd.filelist.files assert 'pyproject.toml' in manifest - def test_pyproject_toml_excluded(self): + def test_pyproject_toml_excluded(self, tmpdir): """ Check that pyproject.toml can excluded even if present """ - open(os.path.join(self.temp_dir, 'pyproject.toml'), 'w').close() + touch(tmpdir / 'pyproject.toml') with open('MANIFEST.in', 'w') as mts: print('exclude pyproject.toml', file=mts) dist = Distribution(SETUP_ATTRS) -- cgit v1.2.1 From a87f975e65507382aaecfb01fe8df4608c38f466 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 31 Dec 2019 13:32:57 -0500 Subject: Remove unused import --- setuptools/tests/test_sdist.py | 1 - 1 file changed, 1 deletion(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 1b951a5b..dcc64cf2 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -4,7 +4,6 @@ from __future__ import print_function import os -import shutil import sys import tempfile import unicodedata -- cgit v1.2.1 From 90922a5eb9b2f002202a16c974b86750a46d21ea Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 1 Jan 2020 11:54:53 -0500 Subject: Restore Python 2.7 compatibility --- setuptools/tests/test_sdist.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index dcc64cf2..9ddbae8b 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """sdist tests""" -from __future__ import print_function +from __future__ import print_function, unicode_literals import os import sys @@ -229,10 +229,6 @@ class TestSdistTest: u_contents = contents.decode('UTF-8') # The manifest should contain the UTF-8 filename - if six.PY2: - fs_enc = sys.getfilesystemencoding() - filename = filename.decode(fs_enc) - assert posix(filename) in u_contents @py3_only -- cgit v1.2.1 From 3d5b7775b7b7ee6c0b354a04fe1d33c1f9b0e5df Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 1 Jan 2020 12:08:46 -0500 Subject: Fix latin1 and utf8 tests on Python 2 --- setuptools/tests/test_sdist.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 9ddbae8b..8538dd24 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -369,7 +369,7 @@ class TestSdistTest: @fail_on_latin1_encoded_filenames def test_sdist_with_utf8_encoded_filename(self): # Test for #303. - dist = Distribution(SETUP_ATTRS) + dist = Distribution(self.make_strings(SETUP_ATTRS)) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() @@ -400,10 +400,19 @@ class TestSdistTest: else: assert filename in cmd.filelist.files + @classmethod + def make_strings(cls, item): + if isinstance(item, dict): + return { + key: cls.make_strings(value) for key, value in item.items()} + if isinstance(item, list): + return list(map(cls.make_strings, item)) + return str(item) + @fail_on_latin1_encoded_filenames def test_sdist_with_latin1_encoded_filename(self): # Test for #303. - dist = Distribution(SETUP_ATTRS) + dist = Distribution(self.make_strings(SETUP_ATTRS)) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() -- cgit v1.2.1 From 796abd8dbec884cedf326cb5f85512a5d5648c4e Mon Sep 17 00:00:00 2001 From: Hugo Date: Wed, 8 Jan 2020 19:10:11 +0200 Subject: Fix for Python 4: replace unsafe six.PY3 with PY2 --- setuptools/tests/test_sdist.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 8538dd24..0bea53df 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -51,7 +51,7 @@ def quiet(): # Convert to POSIX path def posix(path): - if six.PY3 and not isinstance(path, str): + if not six.PY2 and not isinstance(path, str): return path.replace(os.sep.encode('ascii'), b'/') else: return path.replace(os.sep, '/') @@ -329,7 +329,7 @@ class TestSdistTest: cmd.read_manifest() # The filelist should contain the UTF-8 filename - if six.PY3: + if not six.PY2: filename = filename.decode('utf-8') assert filename in cmd.filelist.files @@ -383,7 +383,7 @@ class TestSdistTest: if sys.platform == 'darwin': filename = decompose(filename) - if six.PY3: + if not six.PY2: fs_enc = sys.getfilesystemencoding() if sys.platform == 'win32': @@ -425,7 +425,19 @@ class TestSdistTest: with quiet(): cmd.run() - if six.PY3: + if six.PY2: + # Under Python 2 there seems to be no decoded string in the + # filelist. However, due to decode and encoding of the + # file name to get utf-8 Manifest the latin1 maybe excluded + try: + # fs_enc should match how one is expect the decoding to + # be proformed for the manifest output. + fs_enc = sys.getfilesystemencoding() + filename.decode(fs_enc) + assert filename in cmd.filelist.files + except UnicodeDecodeError: + filename not in cmd.filelist.files + else: # not all windows systems have a default FS encoding of cp1252 if sys.platform == 'win32': # Latin-1 is similar to Windows-1252 however @@ -440,18 +452,6 @@ class TestSdistTest: # The Latin-1 filename should have been skipped filename = filename.decode('latin-1') filename not in cmd.filelist.files - else: - # Under Python 2 there seems to be no decoded string in the - # filelist. However, due to decode and encoding of the - # file name to get utf-8 Manifest the latin1 maybe excluded - try: - # fs_enc should match how one is expect the decoding to - # be proformed for the manifest output. - fs_enc = sys.getfilesystemencoding() - filename.decode(fs_enc) - assert filename in cmd.filelist.files - except UnicodeDecodeError: - filename not in cmd.filelist.files def test_pyproject_toml_in_sdist(self, tmpdir): """ -- cgit v1.2.1