Skip to content

Commit

Permalink
Don't attempt to import fcntl on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ronf committed Feb 25, 2024
1 parent e4504e1 commit e8fe42a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion asyncssh/tuntap.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import asyncio
import errno
import fcntl
import os
import socket
import struct
Expand All @@ -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
Expand Down
13 changes: 9 additions & 4 deletions tests/test_tuntap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,6 +36,9 @@
from .server import Server, ServerTestCase
from .util import asynctest

if sys.platform != 'win32':
import fcntl


_orig_funcs = {}

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"""
Expand Down

0 comments on commit e8fe42a

Please sign in to comment.