From 4d4d32a78f0fcfbeff49e271377f735402ba0d74 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sat, 18 Dec 2021 11:18:49 +0100 Subject: [PATCH 1/3] tests: skip uid/gid using tests under Cygwin There is no single user/group with UID/GID=0 under Cygwin unlike Unix. Skip the tests that assume this for now. --- distutils/tests/test_archive_util.py | 3 ++- distutils/tests/test_sdist.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/distutils/tests/test_archive_util.py b/distutils/tests/test_archive_util.py index ce6456dc..0f90ea15 100644 --- a/distutils/tests/test_archive_util.py +++ b/distutils/tests/test_archive_util.py @@ -339,7 +339,7 @@ def test_make_archive_xztar(self): def test_make_archive_owner_group(self): # testing make_archive with owner and group, with various combinations # this works even if there's not gid/uid support - if UID_GID_SUPPORT: + if UID_GID_SUPPORT and sys.platform != "cygwin": group = grp.getgrgid(0)[0] owner = pwd.getpwuid(0)[0] else: @@ -365,6 +365,7 @@ def test_make_archive_owner_group(self): @unittest.skipUnless(ZLIB_SUPPORT, "Requires zlib") @unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support") + @unittest.skipUnless(sys.platform != "cygwin", "Cygwin doesn't have UID=0") def test_tarfile_root_owner(self): tmpdir = self._create_files() base_name = os.path.join(self.mkdtemp(), 'archive') diff --git a/distutils/tests/test_sdist.py b/distutils/tests/test_sdist.py index b087a817..21e3974a 100644 --- a/distutils/tests/test_sdist.py +++ b/distutils/tests/test_sdist.py @@ -1,5 +1,6 @@ """Tests for distutils.command.sdist.""" import os +import sys import tarfile import unittest import warnings @@ -441,6 +442,7 @@ def test_manual_manifest(self): @unittest.skipUnless(ZLIB_SUPPORT, "requires zlib") @unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support") + @unittest.skipUnless(sys.platform != "cygwin", "Cygwin doesn't have UID=0") @unittest.skipIf(find_executable('tar') is None, "The tar command is not found") @unittest.skipIf(find_executable('gzip') is None, From 2a95a48dcee29f2396bee63de34e2ad0ef1247a3 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sat, 18 Dec 2021 09:14:03 +0100 Subject: [PATCH 2/3] CI: add a CI job for testing under Cygwin There are some tests skipped because of missing docutils, but cygwin currently is missing a docutils package for Python 3.9 --- .github/workflows/main.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 947b8551..bd0e1992 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,6 +21,30 @@ jobs: - name: Run tests run: tox + test_cygwin: + strategy: + matrix: + python: [39] + platform: [windows-latest] + runs-on: ${{ matrix.platform }} + steps: + - uses: actions/checkout@v2 + - name: Install Cygwin + uses: cygwin/cygwin-install-action@v1 + with: + platform: x86_64 + packages: >- + python${{ matrix.python }}, + python${{ matrix.python }}-devel, + python${{ matrix.python }}-pytest, + gcc-core, + gcc-g++, + ncompress + - name: Run tests + shell: C:\cygwin\bin\env.exe CYGWIN_NOWINPATH=1 CHERE_INVOKING=1 C:\cygwin\bin\bash.exe -leo pipefail -o igncr {0} + run: | + pytest -rs + ci_setuptools: # Integration testing with setuptools strategy: From 1d98a156026cbbb43588c5f307a3b8d66d40a1bb Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 18 Dec 2021 10:18:55 -0500 Subject: [PATCH 3/3] Extract grp/pwd handling to a unix_compat module. --- distutils/tests/test_archive_util.py | 13 ++++--------- distutils/tests/test_sdist.py | 13 +++---------- distutils/tests/unix_compat.py | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 19 deletions(-) create mode 100644 distutils/tests/unix_compat.py diff --git a/distutils/tests/test_archive_util.py b/distutils/tests/test_archive_util.py index 0f90ea15..c5560372 100644 --- a/distutils/tests/test_archive_util.py +++ b/distutils/tests/test_archive_util.py @@ -14,16 +14,11 @@ from distutils.spawn import find_executable, spawn from distutils.tests import support from test.support import run_unittest, patch +from .unix_compat import require_unix_id, require_uid_0, grp, pwd, UID_0_SUPPORT from .py38compat import change_cwd from .py38compat import check_warnings -try: - import grp - import pwd - UID_GID_SUPPORT = True -except ImportError: - UID_GID_SUPPORT = False try: import zipfile @@ -339,7 +334,7 @@ def test_make_archive_xztar(self): def test_make_archive_owner_group(self): # testing make_archive with owner and group, with various combinations # this works even if there's not gid/uid support - if UID_GID_SUPPORT and sys.platform != "cygwin": + if UID_0_SUPPORT: group = grp.getgrgid(0)[0] owner = pwd.getpwuid(0)[0] else: @@ -364,8 +359,8 @@ def test_make_archive_owner_group(self): self.assertTrue(os.path.exists(res)) @unittest.skipUnless(ZLIB_SUPPORT, "Requires zlib") - @unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support") - @unittest.skipUnless(sys.platform != "cygwin", "Cygwin doesn't have UID=0") + @require_unix_id + @require_uid_0 def test_tarfile_root_owner(self): tmpdir = self._create_files() base_name = os.path.join(self.mkdtemp(), 'archive') diff --git a/distutils/tests/test_sdist.py b/distutils/tests/test_sdist.py index 21e3974a..880044fa 100644 --- a/distutils/tests/test_sdist.py +++ b/distutils/tests/test_sdist.py @@ -1,6 +1,5 @@ """Tests for distutils.command.sdist.""" import os -import sys import tarfile import unittest import warnings @@ -8,6 +7,7 @@ from os.path import join from textwrap import dedent from test.support import captured_stdout, run_unittest +from .unix_compat import require_unix_id, require_uid_0, pwd, grp from .py38compat import check_warnings @@ -17,13 +17,6 @@ except ImportError: ZLIB_SUPPORT = False -try: - import grp - import pwd - UID_GID_SUPPORT = True -except ImportError: - UID_GID_SUPPORT = False - from distutils.command.sdist import sdist, show_formats from distutils.core import Distribution from distutils.tests.test_config import BasePyPIRCCommandTestCase @@ -441,8 +434,8 @@ def test_manual_manifest(self): 'fake-1.0/README.manual']) @unittest.skipUnless(ZLIB_SUPPORT, "requires zlib") - @unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support") - @unittest.skipUnless(sys.platform != "cygwin", "Cygwin doesn't have UID=0") + @require_unix_id + @require_uid_0 @unittest.skipIf(find_executable('tar') is None, "The tar command is not found") @unittest.skipIf(find_executable('gzip') is None, diff --git a/distutils/tests/unix_compat.py b/distutils/tests/unix_compat.py new file mode 100644 index 00000000..b7718c26 --- /dev/null +++ b/distutils/tests/unix_compat.py @@ -0,0 +1,16 @@ +import sys +import unittest + +try: + import grp + import pwd +except ImportError: + grp = pwd = None + + +UNIX_ID_SUPPORT = grp and pwd +UID_0_SUPPORT = UNIX_ID_SUPPORT and sys.platform != "cygwin" + +require_unix_id = unittest.skipUnless( + UNIX_ID_SUPPORT, "Requires grp and pwd support") +require_uid_0 = unittest.skipUnless(UID_0_SUPPORT, "Requires UID 0 support")