New upstream version 1.4.0
IƱaki Malerba
5 years ago
18 | 18 | env: |
19 | 19 | - DISABLE_LOGBOOK_CEXT=True |
20 | 20 | - CYBUILD=True |
21 | ||
21 | 22 | script: |
22 | 23 | - pip install -e .[all] |
24 | - if [[ $GEVENT == 'True' ]] ; then pip install gevent; fi | |
23 | 25 | - py.test --cov=logbook -r s tests |
26 | ||
24 | 27 | matrix: |
25 | 28 | exclude: |
26 | 29 | - python: pypy |
27 | 30 | env: CYBUILD=True |
28 | 31 | - python: pypy3 |
29 | 32 | env: CYBUILD=True |
33 | include: | |
34 | - python: "3.6" | |
35 | env: GEVENT=True CYBUILD=True | |
36 | - python: "2.7" | |
37 | env: GEVENT=True CYBUILD=True | |
38 | ||
30 | 39 | after_success: |
31 | 40 | - coveralls |
41 | ||
32 | 42 | notifications: |
33 | 43 | email: |
34 | 44 | recipients: |
1 | 1 | ================= |
2 | 2 | |
3 | 3 | Here you can see the full list of changes between each Logbook release. |
4 | ||
5 | Version 1.4.0 | |
6 | ------------- | |
7 | ||
8 | Released on May 15th, 2018 | |
9 | ||
10 | - Added support for checking if trace logs have been emitted in TestHandler (thanks @thedrow) | |
11 | ||
4 | 12 | |
5 | 13 | Version 1.3.0 |
6 | 14 | ------------- |
27 | 27 | |
28 | 28 | |
29 | 29 | if has_gevent: |
30 | from gevent._threading import (Lock as ThreadLock, | |
31 | RLock as ThreadRLock, | |
32 | get_ident as thread_get_ident, | |
33 | local as thread_local) | |
30 | from gevent.monkey import get_original as _get_original | |
31 | ThreadLock = _get_original('threading', 'Lock') | |
32 | ThreadRLock = _get_original('threading', 'RLock') | |
33 | try: | |
34 | thread_get_ident = _get_original('threading', 'get_ident') | |
35 | except AttributeError: | |
36 | # In 2.7, this is called _get_ident | |
37 | thread_get_ident = _get_original('threading', '_get_ident') | |
38 | thread_local = _get_original('threading', 'local') | |
39 | ||
34 | 40 | from gevent.thread import get_ident as greenlet_get_ident |
35 | 41 | from gevent.local import local as greenlet_local |
36 | 42 | from gevent.lock import BoundedSemaphore |
27 | 27 | from textwrap import dedent |
28 | 28 | |
29 | 29 | from logbook.base import ( |
30 | CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG, NOTSET, level_name_property, | |
30 | CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG, TRACE, NOTSET, level_name_property, | |
31 | 31 | _missing, lookup_level, Flags, ContextObject, ContextStackManager, |
32 | 32 | _datetime_factory) |
33 | 33 | from logbook.helpers import ( |
1053 | 1053 | def has_debugs(self): |
1054 | 1054 | """`True` if any :data:`DEBUG` records were found.""" |
1055 | 1055 | return any(r.level == DEBUG for r in self.records) |
1056 | ||
1057 | @property | |
1058 | def has_traces(self): | |
1059 | """`True` if any :data:`TRACE` records were found.""" | |
1060 | return any(r.level == TRACE for r in self.records) | |
1056 | 1061 | |
1057 | 1062 | def has_critical(self, *args, **kwargs): |
1058 | 1063 | """`True` if a specific :data:`CRITICAL` log record exists. |
1100 | 1105 | See :ref:`probe-log-records` for more information. |
1101 | 1106 | """ |
1102 | 1107 | kwargs['level'] = DEBUG |
1108 | return self._test_for(*args, **kwargs) | |
1109 | ||
1110 | def has_trace(self, *args, **kwargs): | |
1111 | """`True` if a specific :data:`TRACE` log record exists. | |
1112 | ||
1113 | See :ref:`probe-log-records` for more information. | |
1114 | """ | |
1115 | kwargs['level'] = TRACE | |
1103 | 1116 | return self._test_for(*args, **kwargs) |
1104 | 1117 | |
1105 | 1118 | def _test_for(self, message=None, channel=None, level=None): |
0 | 0 | import re |
1 | 1 | |
2 | import pytest | |
2 | 3 | |
3 | def test_regex_matching(active_handler, logger): | |
4 | logger.warn('Hello World!') | |
5 | assert active_handler.has_warning(re.compile('^Hello')) | |
6 | assert (not active_handler.has_warning(re.compile('world$'))) | |
7 | assert (not active_handler.has_warning('^Hello World')) | |
4 | ||
5 | @pytest.mark.parametrize("level, method", [ | |
6 | ("trace", "has_traces"), | |
7 | ("debug", "has_debugs"), | |
8 | ("info", "has_infos"), | |
9 | ("notice", "has_notices"), | |
10 | ("warning", "has_warnings"), | |
11 | ("error", "has_errors"), | |
12 | ("critical", "has_criticals"), | |
13 | ]) | |
14 | def test_has_level(active_handler, logger, level, method): | |
15 | log = getattr(logger, level) | |
16 | log('Hello World') | |
17 | assert getattr(active_handler, method) | |
18 | ||
19 | ||
20 | @pytest.mark.parametrize("level, method", [ | |
21 | ("trace", "has_trace"), | |
22 | ("debug", "has_debug"), | |
23 | ("info", "has_info"), | |
24 | ("notice", "has_notice"), | |
25 | ("warning", "has_warning"), | |
26 | ("error", "has_error"), | |
27 | ("critical", "has_critical"), | |
28 | ]) | |
29 | def test_regex_matching(active_handler, logger, level, method): | |
30 | log = getattr(logger, level) | |
31 | log('Hello World') | |
32 | has_level_method = getattr(active_handler, method) | |
33 | assert has_level_method(re.compile('^Hello')) | |
34 | assert (not has_level_method(re.compile('world$'))) | |
35 | assert (not has_level_method('^Hello World')) | |
8 | 36 | |
9 | 37 | |
10 | 38 | def test_test_handler_cache(active_handler, logger): |