Skip to content

Commit

Permalink
Merge pull request #131 – Add tests and coverage for tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Viktorin authored and GitHub committed Mar 14, 2018
2 parents f3868ea + 06800b3 commit 7a859f4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ matrix:
env:
- TOXENV=py3-nosasltls
- WITH_GCOV=1
- python: 3.6
env:
- TOXENV=py3-trace
- python: 3.6
env: TOXENV=doc
allow_failures:
Expand Down
11 changes: 9 additions & 2 deletions Lib/ldap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@

from ldap.pkginfo import __version__, __author__, __license__

import os
import sys

if __debug__:
# Tracing is only supported in debugging mode
import atexit
import traceback
_trace_level = 0
_trace_file = sys.stderr
_trace_level = int(os.environ.get("PYTHON_LDAP_TRACE_LEVEL", 0))
_trace_file = os.environ.get("PYTHON_LDAP_TRACE_FILE")
if _trace_file is None:
_trace_file = sys.stderr
else:
_trace_file = open(_trace_file, 'a')
atexit.register(_trace_file.close)
_trace_stack_limit = None

import _ldap
Expand Down
7 changes: 4 additions & 3 deletions Lib/ldap/ldapobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def __init__(
trace_level=0,trace_file=None,trace_stack_limit=5,bytes_mode=None,
bytes_strictness=None,
):
self._trace_level = trace_level
self._trace_file = trace_file or sys.stdout
self._trace_level = trace_level or ldap._trace_level
self._trace_file = trace_file or ldap._trace_file
self._trace_stack_limit = trace_stack_limit
self._uri = uri
self._ldap_object_lock = self._ldap_lock('opcall')
Expand Down Expand Up @@ -1123,7 +1123,8 @@ def __setstate__(self,d):
self._last_bind = getattr(SimpleLDAPObject, self._last_bind[0]), self._last_bind[1], self._last_bind[2]
self._ldap_object_lock = self._ldap_lock()
self._reconnect_lock = ldap.LDAPLock(desc='reconnect lock within %s' % (repr(self)))
self._trace_file = sys.stdout
# XXX cannot pickle file, use default trace file
self._trace_file = ldap._trace_file
self.reconnect(self._uri)

def _store_last_bind(self,method,*args,**kwargs):
Expand Down
2 changes: 1 addition & 1 deletion Tests/t_ldapobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def test103_reconnect_get_state(self):
str('_retry_delay'): 60.0,
str('_retry_max'): 1,
str('_start_tls'): 0,
str('_trace_level'): 0,
str('_trace_level'): ldap._trace_level,
str('_trace_stack_limit'): 5,
str('_uri'): self.server.ldap_uri,
str('bytes_mode'): l1.bytes_mode,
Expand Down
11 changes: 10 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[tox]
# Note: when updating Python versions, also change setup.py and .travis.yml
envlist = py27,py34,py35,py36,{py2,py3}-nosasltls,doc,coverage-report
envlist = py27,py34,py35,py36,{py2,py3}-nosasltls,doc,py3-trace,coverage-report
minver = 1.8

[testenv]
Expand Down Expand Up @@ -49,6 +49,15 @@ passenv = {[testenv]passenv}
setenv = {[testenv:py2-nosasltls]setenv}
commands = {[testenv:py2-nosasltls]commands}

[testenv:py3-trace]
basepython = python3
deps = {[testenv]deps}
passenv = {[testenv]passenv}
setenv =
PYTHON_LDAP_TRACE_LEVEL=9
PYTHON_LDAP_TRACE_FILE={envtmpdir}/trace.log
commands = {[testenv]commands}

[testenv:pypy]
# PyPy doesn't have working setup.py test
deps = pytest
Expand Down

0 comments on commit 7a859f4

Please sign in to comment.