Skip to content

Commit 3fae199

Browse files
author
unknown
committed
Fixed import error on Windows
1 parent a64ccc5 commit 3fae199

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

‎test/test_socketcan.py‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import ctypes
88
import os
9-
import resource
109
import struct
1110
import sys
1211
import tempfile
@@ -32,7 +31,20 @@
3231
build_bcm_update_header,
3332
)
3433

35-
from .config import IS_LINUX, IS_PYPY, TEST_INTERFACE_SOCKETCAN
34+
from .config import IS_LINUX, IS_PYPY, IS_WINDOWS, TEST_INTERFACE_SOCKETCAN
35+
36+
if IS_WINDOWS:
37+
38+
def get_fd_limit() -> int:
39+
"""Get the current limit on the number of file descriptors."""
40+
return ctypes.CDLL("msvcrt")._getmaxstdio()
41+
42+
else:
43+
import resource
44+
45+
def get_fd_limit() -> int:
46+
"""Get the current limit on the number of file descriptors."""
47+
return resource.getrlimit(resource.RLIMIT_NOFILE)[0]
3648

3749

3850
class SocketCANTest(unittest.TestCase):
@@ -396,7 +408,7 @@ def test_pypy_socketcan_support(self):
396408

397409
@unittest.skipUnless(TEST_INTERFACE_SOCKETCAN, "Only run when vcan0 is available")
398410
@unittest.skipUnless(
399-
resource.getrlimit(resource.RLIMIT_NOFILE)[0] > 1024,
411+
get_fd_limit() > 1024,
400412
"Only run when the system supports high file limit",
401413
)
402414
def test_high_socket_fileno(self):

0 commit comments

Comments
 (0)