Skip to content

Commit

Permalink
type annotate the rest of twisted.test.test_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Sep 19, 2023
1 parent 3732a10 commit 7e9e45a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,6 @@ module = [
'twisted.test.test_main',
'twisted.test.test_memcache',
'twisted.test.test_modules',
'twisted.test.test_paths',
'twisted.test.test_pcp',
'twisted.test.test_policies',
'twisted.test.test_postfix',
Expand Down
22 changes: 16 additions & 6 deletions src/twisted/test/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
from __future__ import annotations

import errno
import io
import os
import pickle
import stat
import sys
import time
from pprint import pformat
from typing import IO, AnyStr, Callable, Dict, List, Optional, Tuple, TypeVar, Union
from unittest import skipIf

from zope.interface.verify import verifyObject

from typing_extensions import NoReturn

from twisted.python import filepath
from twisted.python.filepath import FileMode, OtherAnyStr
from twisted.python.runtime import platform
Expand Down Expand Up @@ -47,15 +51,15 @@ class AbstractFilePathTests(BytesTestCase):
f1content = b"file 1"
f2content = b"file 2"

def _mkpath(self, *p):
def _mkpath(self, *p: bytes) -> bytes:
x = os.path.abspath(os.path.join(self.cmn, *p))
self.all.append(x)
return x

def subdir(self, *dirname):
def subdir(self, *dirname: bytes) -> None:
os.mkdir(self._mkpath(*dirname))

def subfile(self, *dirname):
def subfile(self, *dirname: bytes) -> io.BufferedWriter:
return open(self._mkpath(*dirname), "wb")

def setUp(self) -> None:
Expand Down Expand Up @@ -254,13 +258,19 @@ def listdir(self) -> List[AnyStr]:
)


if sys.platform != "win32":

class WindowsError:
pass


class ListingCompatibilityTests(BytesTestCase):
"""
These tests verify compatibility with legacy behavior of directory listing.
"""

@skipIf(not platform.isWindows(), "Only relevant on on Windows.")
def test_windowsErrorExcept(self):
def test_windowsErrorExcept(self) -> None:
"""
Verify that when a WindowsError is raised from listdir, catching
WindowsError works.
Expand Down Expand Up @@ -303,13 +313,13 @@ class ExplodingFile:

closed = False

def read(self, n=0):
def read(self, n: int = 0) -> NoReturn:
"""
@raise IOError: Always raised.
"""
raise OSError()

def write(self, what):
def write(self, what: bytes) -> NoReturn:
"""
@raise IOError: Always raised.
"""
Expand Down

0 comments on commit 7e9e45a

Please sign in to comment.