Skip to content

Commit

Permalink
tests: Use system-specific ENOTCONN value
Browse files Browse the repository at this point in the history
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: #228
  • Loading branch information
Ivan A. Melnikov committed Jul 9, 2018
1 parent e8cc39d commit 97379aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
10 changes: 6 additions & 4 deletions Tests/t_cext.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from __future__ import unicode_literals

import errno
import os
import unittest

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

def test_errno107(self):
def test_enotconn(self):
l = _ldap.initialize('ldap://127.0.0.1:42')
try:
m = l.simple_bind("", "")
r = l.result4(m, _ldap.MSG_ALL, self.timeout)
except _ldap.SERVER_DOWN as ldap_err:
errno = ldap_err.args[0]['errno']
if errno != 107:
self.fail("expected errno=107, got %d" % errno)
errno_val = ldap_err.args[0]['errno']
if errno_val != errno.ENOTCONN:
self.fail("expected errno=%d, got %d"
% (errno.ENOTCONN, errno_val))
else:
self.fail("expected SERVER_DOWN, got %r" % r)

Expand Down
15 changes: 9 additions & 6 deletions Tests/t_ldapobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
PY2 = False
text_type = str

import errno
import contextlib
import linecache
import os
Expand Down Expand Up @@ -451,18 +452,20 @@ def test_search_subschema_have_bytes(self):
]
)

def test004_errno107(self):
def test004_enotconn(self):
l = self.ldap_object_class('ldap://127.0.0.1:42')
try:
m = l.simple_bind_s("", "")
r = l.result4(m, ldap.MSG_ALL, self.timeout)
except ldap.SERVER_DOWN as ldap_err:
errno = ldap_err.args[0]['errno']
if errno != 107:
self.fail("expected errno=107, got %d" % errno)
errno_val = ldap_err.args[0]['errno']
if errno_val != errno.ENOTCONN:
self.fail("expected errno=%d, got %d"
% (errno.ENOTCONN, errno_val))
info = ldap_err.args[0]['info']
if info != os.strerror(107):
self.fail("expected info=%r, got %d" % (os.strerror(107), info))
expected_info = os.strerror(errno.ENOTCONN)
if info != expected_info:
self.fail("expected info=%r, got %d" % (expected_info, info))
else:
self.fail("expected SERVER_DOWN, got %r" % r)

Expand Down

0 comments on commit 97379aa

Please sign in to comment.