Skip to content

Commit 97379aa

Browse files
committed
tests: Use system-specific ENOTCONN value
The integer values for `errno` are not standard and can vary from platform to platform, so the tests should rely on the constants provided in `errno` module. Closes: python-ldap#228
1 parent e8cc39d commit 97379aa

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

Tests/t_cext.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from __future__ import unicode_literals
99

10+
import errno
1011
import os
1112
import unittest
1213

@@ -731,15 +732,16 @@ def test_cancel(self):
731732
if not self._require_attr(l, 'cancel'): # FEATURE_CANCEL
732733
return
733734

734-
def test_errno107(self):
735+
def test_enotconn(self):
735736
l = _ldap.initialize('ldap://127.0.0.1:42')
736737
try:
737738
m = l.simple_bind("", "")
738739
r = l.result4(m, _ldap.MSG_ALL, self.timeout)
739740
except _ldap.SERVER_DOWN as ldap_err:
740-
errno = ldap_err.args[0]['errno']
741-
if errno != 107:
742-
self.fail("expected errno=107, got %d" % errno)
741+
errno_val = ldap_err.args[0]['errno']
742+
if errno_val != errno.ENOTCONN:
743+
self.fail("expected errno=%d, got %d"
744+
% (errno.ENOTCONN, errno_val))
743745
else:
744746
self.fail("expected SERVER_DOWN, got %r" % r)
745747

Tests/t_ldapobject.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
PY2 = False
1717
text_type = str
1818

19+
import errno
1920
import contextlib
2021
import linecache
2122
import os
@@ -451,18 +452,20 @@ def test_search_subschema_have_bytes(self):
451452
]
452453
)
453454

454-
def test004_errno107(self):
455+
def test004_enotconn(self):
455456
l = self.ldap_object_class('ldap://127.0.0.1:42')
456457
try:
457458
m = l.simple_bind_s("", "")
458459
r = l.result4(m, ldap.MSG_ALL, self.timeout)
459460
except ldap.SERVER_DOWN as ldap_err:
460-
errno = ldap_err.args[0]['errno']
461-
if errno != 107:
462-
self.fail("expected errno=107, got %d" % errno)
461+
errno_val = ldap_err.args[0]['errno']
462+
if errno_val != errno.ENOTCONN:
463+
self.fail("expected errno=%d, got %d"
464+
% (errno.ENOTCONN, errno_val))
463465
info = ldap_err.args[0]['info']
464-
if info != os.strerror(107):
465-
self.fail("expected info=%r, got %d" % (os.strerror(107), info))
466+
expected_info = os.strerror(errno.ENOTCONN)
467+
if info != expected_info:
468+
self.fail("expected info=%r, got %d" % (expected_info, info))
466469
else:
467470
self.fail("expected SERVER_DOWN, got %r" % r)
468471

0 commit comments

Comments
 (0)