Skip to content

Commit

Permalink
Merge pull request #3 from zopefoundation/new-py-versions
Browse files Browse the repository at this point in the history
Update to new Python versions.
  • Loading branch information
Michael Howitz committed Feb 13, 2020
2 parents 7142a1f + ccf49ad commit 45478e0
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 74 deletions.
10 changes: 10 additions & 0 deletions .coveragerc
@@ -0,0 +1,10 @@
[run]
branch = True
source = src

[report]
precision = 2
exclude_lines = pragma: no cover

[html]
directory = htmlcov
19 changes: 2 additions & 17 deletions .travis.yml
@@ -1,18 +1,3 @@
version: ~> 1.0
language: python
sudo: false
python:
- 2.7
- 3.3
- 3.4
- 3.5
install:
- python bootstrap.py
- bin/buildout
script:
- bin/nosetests --with-coverage --cover-package=zLOG --cover-min-percentage=100%
notifications:
email: false
cache:
pip: true
directories:
- eggs/
import: zopefoundation/meta:travis-ci-config/minimal-no-pypy.yml
6 changes: 6 additions & 0 deletions CHANGES.rst
Expand Up @@ -4,6 +4,12 @@ Changelog
3.1 (unreleased)
----------------

- Add support for Python 3.6 up to 3.8.

- Drop support for Python 3.3 and 3.4.

- Flake8 the code.


3.0 (2016-04-03)
----------------
Expand Down
2 changes: 0 additions & 2 deletions TODO.txt

This file was deleted.

20 changes: 14 additions & 6 deletions setup.py
Expand Up @@ -15,17 +15,21 @@
"""
from setuptools import setup, find_packages

__version__ = '3.1.dev0'
version = '3.1.dev0'

with open('README.rst') as f:
README = f.read()

with open('CHANGES.rst') as f:
CHANGES = f.read()

tests_require = [
'zope.testrunner',
]

setup(name='zLOG',
version=__version__,
url='http://pypi.python.org/pypi/zLOG',
version=version,
url='https://github.com/zopefoundation/zLOG',
license='ZPL 2.1',
description='A general logging facility',
author='Zope Foundation and Contributors',
Expand All @@ -38,17 +42,21 @@
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Framework :: Zope2",
],
packages=find_packages('src'),
package_dir={'': 'src'},
test_suite='zLOG.tests',
install_requires=['ZConfig >= 2.9.2'],
install_requires=[
'ZConfig >= 3.4',
],
extras_require=dict(test=tests_require),
include_package_data=True,
zip_safe=False,
)
38 changes: 19 additions & 19 deletions src/zLOG/EventLogger.py
Expand Up @@ -25,22 +25,22 @@
# logging configuration is activated (the logger factory is called).
#
# Custom logging levels
CUSTOM_BLATHER = 15 # Mapping for zLOG.BLATHER
CUSTOM_TRACE = 5 # Mapping for zLOG.TRACE
CUSTOM_BLATHER = 15 # Mapping for zLOG.BLATHER
CUSTOM_TRACE = 5 # Mapping for zLOG.TRACE
logging.addLevelName("BLATHER", CUSTOM_BLATHER)
logging.addLevelName("TRACE", CUSTOM_TRACE)

try: # pragma: no cover
# Python 3
Exception.with_traceback
# Python 3
Exception.with_traceback

def fmt_raise(error):
raise error[0](error[1]).with_traceback(error[2])
def fmt_raise(error):
raise error[0](error[1]).with_traceback(error[2])

except AttributeError: # pragma: no cover
# Python 2
def fmt_raise(error):
return error[0], error[1], error[2]
# Python 2
def fmt_raise(error):
return error[0], error[1], error[2]


def log_write(subsystem, severity, summary, detail, error):
Expand All @@ -56,22 +56,21 @@ def log_write(subsystem, severity, summary, detail, error):


def severity_string(severity, mapping={
-300: 'TRACE',
-200: 'DEBUG',
-100: 'BLATHER',
0: 'INFO',
100: 'PROBLEM',
200: 'ERROR',
300: 'PANIC',
}):
-300: 'TRACE',
-200: 'DEBUG',
-100: 'BLATHER',
0: 'INFO',
100: 'PROBLEM',
200: 'ERROR',
300: 'PANIC'}):
"""Convert a severity code to a string."""
s = mapping.get(int(severity), '')
return "%s(%s)" % (s, severity)


def zlog_to_pep282_severity(zlog_severity):
"""
We map zLOG severities to PEP282 severities here.
"""We map zLOG severities to PEP282 severities here.
This is how they are mapped:
zLOG severity PEP282 severity
Expand Down Expand Up @@ -101,6 +100,7 @@ def zlog_to_pep282_severity(zlog_severity):
return logging.DEBUG
return CUSTOM_TRACE


zlog_to_pep282_severity_cache = {}
for _sev in range(-300, 301, 100):
zlog_to_pep282_severity_cache[_sev] = zlog_to_pep282_severity(_sev)
Expand Down
25 changes: 16 additions & 9 deletions src/zLOG/__init__.py
Expand Up @@ -78,24 +78,27 @@
"""

from zLOG.EventLogger import log_write, log_time, severity_string
from zLOG.EventLogger import log_write
from zLOG.EventLogger import log_time
from zLOG.EventLogger import severity_string # noqa: F401
from zLOG.EventLogger import fmt_raise
from traceback import format_exception
from traceback import format_exception # noqa: F401

# Standard severities
TRACE = -300
DEBUG = -200
TRACE = -300
DEBUG = -200
BLATHER = -100
INFO = 0
PROBLEM = 100
WARNING = 100
ERROR = 200
PANIC = 300
INFO = 0
PROBLEM = 100
WARNING = 100
ERROR = 200
PANIC = 300


def initialize():
pass


def set_initializer(func):
"""Set the function used to re-initialize the logs.
Expand Down Expand Up @@ -137,7 +140,10 @@ def LOG(subsystem, severity, summary, detail='', error=None, reraise=None):
if reraise and error:
raise fmt_raise(error)


_subsystems = []


def register_subsystem(subsystem):
"""Register a subsystem name
Expand All @@ -146,6 +152,7 @@ def register_subsystem(subsystem):
"""
_subsystems.append(subsystem)


# Most apps interested in logging only want the names below.
__all__ = ['LOG', 'TRACE', 'DEBUG', 'BLATHER', 'INFO', 'PROBLEM',
'WARNING', 'ERROR', 'PANIC', 'log_time']
4 changes: 2 additions & 2 deletions src/zLOG/tests/test_logging.py
Expand Up @@ -16,7 +16,7 @@
import logging
import unittest

from ZConfig.components.logger.tests.test_logger import LoggingTestHelper
from ZConfig.components.logger.tests.support import LoggingTestHelper

import zLOG

Expand All @@ -43,7 +43,7 @@ def setUp(self):
self.logger.addHandler(self.handler)

def test_log_record(self):
#log_write(subsystem, severity, summary, detail, error)
# log_write(subsystem, severity, summary, detail, error)
log_write("sample.subsystem", zLOG.WARNING, "summary", "detail", None)
self.assertEqual(len(self.records), 1)
record = self.records[0]
Expand Down
19 changes: 8 additions & 11 deletions src/zLOG/tests/testzLog.py
Expand Up @@ -24,11 +24,11 @@
-300: 'TRACE',
-200: 'DEBUG',
-100: 'BLATHER',
0: 'INFO',
100: 'PROBLEM',
200: 'ERROR',
300: 'PANIC',
}
0: 'INFO',
100: 'PROBLEM',
200: 'ERROR',
300: 'PANIC',
}


class EventLogTest(unittest.TestCase):
Expand Down Expand Up @@ -63,7 +63,7 @@ def verifyEntry(self, f, time=None, subsys=None, severity=None,
line = f.readline().strip()
line = f.readline().strip()
_time, rest = line.split(" ", 1)
if subsys is not None:
if subsys is not None: # pragma: no cover
self.assertIn(subsys, rest, "subsystem mismatch")
if severity is not None and severity >= self._severity:
s = severity_string[severity]
Expand All @@ -77,7 +77,6 @@ def verifyEntry(self, f, time=None, subsys=None, severity=None,
line = f.readline().strip()
self.assertTrue(line.startswith('Traceback'),
"missing traceback")
last = "%s: %s" % (error[0].__name__, error[1])

def getLogFile(self):
return open(self.path, 'r')
Expand Down Expand Up @@ -117,10 +116,9 @@ def test_reraise_error(self):
self.verifyEntry(f, subsys="basic", severity=zLOG.ERROR, error=err)

def test_bbb(self):
""" test existence of backwards compatibility methods that do nothing
"""
"""Test existence of BBB methods that do nothing."""
zLOG.initialize()
zLOG.set_initializer(lambda :False)
zLOG.set_initializer(lambda: False) # pragma: no cover
zLOG.register_subsystem('foo')
self.assertTrue('foo' in zLOG._subsystems)

Expand All @@ -131,6 +129,5 @@ def test_severity_string(self):
self.assertEqual(zLOG.severity_string(99), '(99)')

def test_log_time(self):
now = time.localtime()
self.assertTrue(zLOG.log_time().startswith(
'%4.4d-%2.2d-%2.2dT' % time.localtime()[:3]))
27 changes: 19 additions & 8 deletions tox.ini
@@ -1,17 +1,28 @@
[tox]
envlist =
py27,py33,py34,py35,pypy3,coverage
envlist = flake8,
py27,
py35,
py36,
py37,
py38,
coverage

[testenv]
usedevelop = true
commands =
python setup.py test -q
zope-testrunner --test-path=src []
extras = test

[testenv:coverage]
basepython =
python2.7
basepython = python3
commands =
nosetests --with-xunit --with-xcoverage --cover-package=zLOG --cover-min-percentage=100
coverage run -m zope.testrunner --test-path=src []
coverage report --fail-under=100
deps =
nose
coverage
nosexcover

[testenv:flake8]
basepython = python3
skip_install = true
deps = flake8
commands = flake8 src setup.py

0 comments on commit 45478e0

Please sign in to comment.