From a5414bf8736edb68e0a97233720f5de10d408e2d Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 11 Jan 2024 13:33:36 -0500 Subject: [PATCH 1/2] Remove test dependency on sumtypes library --- test-requirements.txt | 1 - test/test_index.py | 52 +++++++++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/test-requirements.txt b/test-requirements.txt index fcdc93c1d..7cfb977a1 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -9,4 +9,3 @@ pytest-cov pytest-instafail pytest-mock pytest-sugar -sumtypes diff --git a/test/test_index.py b/test/test_index.py index 8a64e2293..876d1220d 100644 --- a/test/test_index.py +++ b/test/test_index.py @@ -4,6 +4,7 @@ # 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/ import contextlib +from dataclasses import dataclass from io import BytesIO import logging import os @@ -12,12 +13,11 @@ import re import shutil from stat import S_ISLNK, ST_MODE -import subprocess +from subprocess import CompletedProcess, run import tempfile import ddt import pytest -from sumtypes import constructor, sumtype from git import ( BlobFilter, @@ -66,34 +66,48 @@ def _get_windows_ansi_encoding(): return f"cp{value}" -@sumtype class WinBashStatus: - """Status of bash.exe for native Windows. Affects which commit hook tests can pass. + """Namespace of native-Windows bash.exe statuses. Affects what hook tests can pass. Call check() to check the status. (CheckError and WinError should not typically be used to trigger skip or xfail, because they represent unexpected situations.) """ - Inapplicable = constructor() - """This system is not native Windows: either not Windows at all, or Cygwin.""" + @dataclass + class Inapplicable: + """This system is not native Windows: either not Windows at all, or Cygwin.""" - Absent = constructor() - """No command for bash.exe is found on the system.""" + @dataclass + class Absent: + """No command for bash.exe is found on the system.""" - Native = constructor() - """Running bash.exe operates outside any WSL distribution (as with Git Bash).""" + @dataclass + class Native: + """Running bash.exe operates outside any WSL distribution (as with Git Bash).""" - Wsl = constructor() - """Running bash.exe calls bash in a WSL distribution.""" + @dataclass + class Wsl: + """Running bash.exe calls bash in a WSL distribution.""" - WslNoDistro = constructor("process", "message") - """Running bash.exe tries to run bash on a WSL distribution, but none exists.""" + @dataclass + class WslNoDistro: + """Running bash.exe tries to run bash on a WSL distribution, but none exists.""" - CheckError = constructor("process", "message") - """Running bash.exe fails in an unexpected error or gives unexpected output.""" + process: CompletedProcess[bytes] + message: str - WinError = constructor("exception") - """bash.exe may exist but can't run. CreateProcessW fails unexpectedly.""" + @dataclass + class CheckError: + """Running bash.exe fails in an unexpected error or gives unexpected output.""" + + process: CompletedProcess[bytes] + message: str + + @dataclass + class WinError: + """bash.exe may exist but can't run. CreateProcessW fails unexpectedly.""" + + exception: OSError @classmethod def check(cls): @@ -119,7 +133,7 @@ def check(cls): # information on ways to check for WSL, see https://superuser.com/a/1749811. script = 'test -e /proc/sys/fs/binfmt_misc/WSLInterop; echo "$?"' command = ["bash.exe", "-c", script] - process = subprocess.run(command, capture_output=True) + process = run(command, capture_output=True) except FileNotFoundError: return cls.Absent() except OSError as error: From 70ea7ec475a82b2483cf151abb9e542f5085af4c Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 11 Jan 2024 13:35:05 -0500 Subject: [PATCH 2/2] Fix annotations for Python 3.8 and lower --- test/test_index.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_index.py b/test/test_index.py index 876d1220d..22eac355b 100644 --- a/test/test_index.py +++ b/test/test_index.py @@ -13,7 +13,7 @@ import re import shutil from stat import S_ISLNK, ST_MODE -from subprocess import CompletedProcess, run +import subprocess import tempfile import ddt @@ -93,14 +93,14 @@ class Wsl: class WslNoDistro: """Running bash.exe tries to run bash on a WSL distribution, but none exists.""" - process: CompletedProcess[bytes] + process: "subprocess.CompletedProcess[bytes]" message: str @dataclass class CheckError: """Running bash.exe fails in an unexpected error or gives unexpected output.""" - process: CompletedProcess[bytes] + process: "subprocess.CompletedProcess[bytes]" message: str @dataclass @@ -133,7 +133,7 @@ def check(cls): # information on ways to check for WSL, see https://superuser.com/a/1749811. script = 'test -e /proc/sys/fs/binfmt_misc/WSLInterop; echo "$?"' command = ["bash.exe", "-c", script] - process = run(command, capture_output=True) + process = subprocess.run(command, capture_output=True) except FileNotFoundError: return cls.Absent() except OSError as error: