diff --git a/asyncssh/tuntap.py b/asyncssh/tuntap.py index 76eed78..8326cfc 100644 --- a/asyncssh/tuntap.py +++ b/asyncssh/tuntap.py @@ -22,7 +22,6 @@ import asyncio import errno -import fcntl import os import socket import struct @@ -31,6 +30,9 @@ from typing import Callable, Optional, Tuple, cast +if sys.platform != 'win32': + import fcntl + SSH_TUN_MODE_POINTTOPOINT = 1 # layer 3 IP packets SSH_TUN_MODE_ETHERNET = 2 # layer 2 Ethenet frames diff --git a/tests/test_tuntap.py b/tests/test_tuntap.py index 6ef2c33..fbb10ae 100644 --- a/tests/test_tuntap.py +++ b/tests/test_tuntap.py @@ -23,12 +23,11 @@ import asyncio import builtins import errno -import fcntl import socket import struct import sys -from unittest import skipUnless +from unittest import skipIf, skipUnless from unittest.mock import patch import asyncssh @@ -37,6 +36,9 @@ from .server import Server, ServerTestCase from .util import asynctest +if sys.platform != 'win32': + import fcntl + _orig_funcs = {} @@ -304,11 +306,13 @@ def patch_tuntap(cls): _orig_funcs['open'] = builtins.open _orig_funcs['socket'] = socket.socket - _orig_funcs['ioctl'] = fcntl.ioctl cls = patch('builtins.open', _open)(cls) cls = patch('socket.socket', _socket)(cls) - cls = patch('fcntl.ioctl', _ioctl)(cls) + + if sys.platform != 'win32': # pragma: no branch + _orig_funcs['ioctl'] = fcntl.ioctl + cls = patch('fcntl.ioctl', _ioctl)(cls) return cls @@ -367,6 +371,7 @@ def tap_requested(self, unit): return True +@skipIf(sys.platform == 'win32', 'skip TUN/TAP tests on Windows') @patch_tuntap class _TestTunTap(ServerTestCase): """Unit tests for TUN/TAP functions"""