Skip to content

Commit

Permalink
replace @unittest.skipIf with pytest counterpart
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Jun 21, 2024
1 parent 52eaa56 commit 671766c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 43 deletions.
9 changes: 4 additions & 5 deletions pyftpdlib/test/test_authorizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import random
import string
import sys
import unittest
import warnings

import pytest
Expand Down Expand Up @@ -484,9 +483,9 @@ def test_override_user_errors(self):
# =====================================================================


@unittest.skipUnless(POSIX, "UNIX only")
@unittest.skipUnless(
UnixAuthorizer is not None, "UnixAuthorizer class not available"
@pytest.mark.skipif(not POSIX, reason="UNIX only")
@pytest.mark.skipif(
UnixAuthorizer is None, reason="UnixAuthorizer class not available"
)
class TestUnixAuthorizer(_SharedAuthorizerTests, PyftpdlibTestCase):
"""Unix authorizer specific tests."""
Expand Down Expand Up @@ -614,7 +613,7 @@ def test_not_root(self):
# =====================================================================


@unittest.skipUnless(WINDOWS, "Windows only")
@pytest.mark.skipif(not WINDOWS, reason="Windows only")
class TestWindowsAuthorizer(_SharedAuthorizerTests, PyftpdlibTestCase):
"""Windows authorizer specific tests."""

Expand Down
5 changes: 3 additions & 2 deletions pyftpdlib/test/test_filesystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import os
import tempfile
import unittest

import pytest

from pyftpdlib._compat import getcwdu
from pyftpdlib._compat import u
Expand Down Expand Up @@ -194,7 +195,7 @@ def test_validpath_external_symlink(self):
safe_rmpath(testfn)


@unittest.skipUnless(POSIX, "UNIX only")
@pytest.mark.skipif(not POSIX, reason="UNIX only")
class TestUnixFilesystem(PyftpdlibTestCase):

def test_case(self):
Expand Down
37 changes: 23 additions & 14 deletions pyftpdlib/test/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
except ImportError:
from io import BytesIO

import unittest

import pytest

Expand Down Expand Up @@ -1043,8 +1042,10 @@ def test_stor_empty_file(self):
assert not f.read()


@unittest.skipUnless(POSIX, "POSIX only")
@unittest.skipIf(not PY3 and sendfile is None, "pysendfile not installed")
@pytest.mark.skipif(not POSIX, reason="POSIX only")
@pytest.mark.skipif(
not PY3 and sendfile is None, reason="pysendfile not installed"
)
class TestFtpStoreDataNoSendfile(TestFtpStoreData):
"""Test STOR, STOU, APPE, REST, TYPE not using sendfile()."""

Expand Down Expand Up @@ -1184,8 +1185,10 @@ def test_retr_empty_file(self):
assert self.dummyfile.read() == b""


@unittest.skipUnless(POSIX, "POSIX only")
@unittest.skipIf(not PY3 and sendfile is None, "pysendfile not installed")
@pytest.mark.skipif(not POSIX, reason="POSIX only")
@pytest.mark.skipif(
not PY3 and sendfile is None, reason="pysendfile not installed"
)
class TestFtpRetrieveDataNoSendfile(TestFtpRetrieveData):
"""Test RETR, REST, TYPE by not using sendfile()."""

Expand Down Expand Up @@ -1434,8 +1437,10 @@ def test_abor_during_transfer(self):
# with a 226
assert self.client.voidresp()[:3] == '226'

@unittest.skipUnless(hasattr(socket, 'MSG_OOB'), "MSG_OOB not available")
@unittest.skipIf(OSX, "does not work on OSX")
@pytest.mark.skipif(
not hasattr(socket, 'MSG_OOB'), reason="MSG_OOB not available"
)
@pytest.mark.skipif(OSX, reason="does not work on OSX")
def test_oob_abor(self):
# Send ABOR by following the RFC-959 directives of sending
# Telnet IP/Synch sequence as OOB data.
Expand Down Expand Up @@ -2236,7 +2241,7 @@ def test_epsv_all(self):
)


@unittest.skipUnless(SUPPORTS_IPV4, "IPv4 not supported")
@pytest.mark.skipif(not SUPPORTS_IPV4, reason="IPv4 not supported")
class TestIPv4Environment(_TestNetworkProtocols, PyftpdlibTestCase):
"""Test PASV, EPSV, PORT and EPRT commands.
Expand Down Expand Up @@ -2286,7 +2291,7 @@ def test_pasv_v4(self):
s.connect((host, port))


@unittest.skipUnless(SUPPORTS_IPV6, "IPv6 not supported")
@pytest.mark.skipif(not SUPPORTS_IPV6, reason="IPv6 not supported")
class TestIPv6Environment(_TestNetworkProtocols, PyftpdlibTestCase):
"""Test PASV, EPSV, PORT and EPRT commands.
Expand Down Expand Up @@ -2318,7 +2323,9 @@ def test_eprt_v6(self):
assert 'foreign address' in resp


@unittest.skipUnless(SUPPORTS_HYBRID_IPV6, "IPv4/6 dual stack not supported")
@pytest.mark.skipif(
not SUPPORTS_HYBRID_IPV6, reason="IPv4/6 dual stack not supported"
)
class TestIPv6MixedEnvironment(PyftpdlibTestCase):
"""By running the server by specifying "::" as IP address the
server is supposed to listen on all interfaces, supporting both
Expand Down Expand Up @@ -2447,7 +2454,7 @@ def test_port_race_condition(self):
s, _ = sock.accept()
s.close()

@unittest.skipUnless(POSIX, "POSIX only")
@pytest.mark.skipif(not POSIX, reason="POSIX only")
def test_quick_connect(self):
# Clients that connected and disconnected quickly could cause
# the server to crash, due to a failure to catch errors in the
Expand Down Expand Up @@ -2541,7 +2548,7 @@ def test_ioloop_fileno(self):
# # TODO: disabled as on certain platforms (OSX and Windows)
# # produces failures with python3. Will have to get back to
# # this and fix it.
# @unittest.skipIf(OSX or WINDOWS, "fails on OSX or Windows")
# @pytest.mark.skipif(OSX or WINDOWS, reason="fails on OSX or Windows")
# class TestUnicodePathNames(PyftpdlibTestCase):
# """Test FTP commands and responses by using path names with non
# ASCII characters.
Expand Down Expand Up @@ -2913,8 +2920,10 @@ def test_permit_privileged_ports(self):
s.close()
sock.close()

@unittest.skipUnless(POSIX, "POSIX only")
@unittest.skipIf(not PY3 and sendfile is None, "pysendfile not installed")
@pytest.mark.skipif(not POSIX, reason="POSIX only")
@pytest.mark.skipif(
not PY3 and sendfile is None, reason="pysendfile not installed"
)
@retry_on_failure()
def test_sendfile_fails(self):
# Makes sure that if sendfile() fails and no bytes were
Expand Down
13 changes: 6 additions & 7 deletions pyftpdlib/test/test_functional_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import os
import socket
import ssl
import unittest

import OpenSSL # requires "pip install pyopenssl"
import pytest
Expand Down Expand Up @@ -95,11 +94,11 @@ class TestFtpFsOperationsTLSMixin(TLSTestMixin, TestFtpFsOperations):

class TestFtpStoreDataTLSMixin(TLSTestMixin, TestFtpStoreData):

@unittest.skipIf(1, "fails with SSL")
@pytest.mark.skip(reason="fails with SSL")
def test_stou(self):
pass

@unittest.skipIf(WINDOWS, "unreliable on Windows + SSL")
@pytest.mark.skipif(WINDOWS, reason="unreliable on Windows + SSL")
def test_stor_ascii_2(self):
pass

Expand All @@ -113,7 +112,7 @@ def test_stor_ascii_2(self):

class TestFtpRetrieveDataTLSMixin(TLSTestMixin, TestFtpRetrieveData):

@unittest.skipIf(WINDOWS, "may fail on windows")
@pytest.mark.skipif(WINDOWS, reason="may fail on windows")
def test_restore_on_retr(self):
super().test_restore_on_retr()

Expand All @@ -127,21 +126,21 @@ class TestFtpListingCmdsTLSMixin(TLSTestMixin, TestFtpListingCmds):
# File "/opt/python/2.7.9/lib/python2.7/ssl.py", line 771, in unwrap
# s = self._sslobj.shutdown()
# error: [Errno 0] Error
@unittest.skipIf(CI_TESTING, "may fail on CI")
@pytest.mark.skipif(CI_TESTING, reason="may fail on CI")
def test_nlst(self):
super().test_nlst()


class TestFtpAbortTLSMixin(TLSTestMixin, TestFtpAbort):

@unittest.skipIf(1, "fails with SSL")
@pytest.mark.skip(reason="fails with SSL")
def test_oob_abor(self):
pass


class TestTimeoutsTLSMixin(TLSTestMixin, TestTimeouts):

@unittest.skipIf(1, "fails with SSL")
@pytest.mark.skip(reason="fails with SSL")
def test_data_timeout_not_reached(self):
pass

Expand Down
24 changes: 12 additions & 12 deletions pyftpdlib/test/test_ioloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import select
import socket
import time
import unittest

import pytest

Expand Down Expand Up @@ -188,8 +187,9 @@ def test_select_eintr(self):
# ===================================================================


@unittest.skipUnless(
hasattr(pyftpdlib.ioloop, 'Poll'), "poll() not available on this platform"
@pytest.mark.skipif(
not hasattr(pyftpdlib.ioloop, 'Poll'),
reason="poll() not available on this platform",
)
class PollIOLoopTestCase(PyftpdlibTestCase, BaseIOLoopTestCase):
ioloop_class = getattr(pyftpdlib.ioloop, "Poll", None)
Expand Down Expand Up @@ -264,9 +264,9 @@ def test_enoent_on_modify(self):
# ===================================================================


@unittest.skipUnless(
hasattr(pyftpdlib.ioloop, 'Epoll'),
"epoll() not available on this platform (Linux only)",
@pytest.mark.skipif(
not hasattr(pyftpdlib.ioloop, 'Epoll'),
reason="epoll() not available on this platform (Linux only)",
)
class EpollIOLoopTestCase(PollIOLoopTestCase):
ioloop_class = getattr(pyftpdlib.ioloop, "Epoll", None)
Expand All @@ -278,9 +278,9 @@ class EpollIOLoopTestCase(PollIOLoopTestCase):
# ===================================================================


@unittest.skipUnless(
hasattr(pyftpdlib.ioloop, 'DevPoll'),
"/dev/poll not available on this platform (Solaris only)",
@pytest.mark.skipif(
not hasattr(pyftpdlib.ioloop, 'DevPoll'),
reason="/dev/poll not available on this platform (Solaris only)",
)
class DevPollIOLoopTestCase(PyftpdlibTestCase, BaseIOLoopTestCase):
ioloop_class = getattr(pyftpdlib.ioloop, "DevPoll", None)
Expand All @@ -291,9 +291,9 @@ class DevPollIOLoopTestCase(PyftpdlibTestCase, BaseIOLoopTestCase):
# ===================================================================


@unittest.skipUnless(
hasattr(pyftpdlib.ioloop, 'Kqueue'),
"/dev/poll not available on this platform (BSD only)",
@pytest.mark.skipif(
not hasattr(pyftpdlib.ioloop, 'Kqueue'),
reason="/dev/poll not available on this platform (BSD only)",
)
class KqueueIOLoopTestCase(PyftpdlibTestCase, BaseIOLoopTestCase):
ioloop_class = getattr(pyftpdlib.ioloop, "Kqueue", None)
Expand Down
7 changes: 4 additions & 3 deletions pyftpdlib/test/test_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import contextlib
import ftplib
import socket
import unittest

import pytest

from pyftpdlib import handlers
from pyftpdlib import servers
Expand Down Expand Up @@ -52,7 +53,7 @@ def tearDown(self):
self.server.stop()
super().tearDown()

@unittest.skipIf(WINDOWS, "POSIX only")
@pytest.mark.skipif(WINDOWS, reason="POSIX only")
def test_sock_instead_of_addr(self):
# pass a socket object instead of an address tuple to FTPServer
# constructor
Expand Down Expand Up @@ -164,7 +165,7 @@ class MProcFTPTestMixin:

else:

@unittest.skipIf(True, "multiprocessing module not installed")
@pytest.mark.skip(reason="multiprocessing module not installed")
class MProcFTPTestMixin:
pass

Expand Down

0 comments on commit 671766c

Please sign in to comment.