Skip to content

Commit

Permalink
fix JobError.__str__() for python 2/3 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s committed Nov 27, 2020
1 parent 673a738 commit b0578e9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ckanserviceprovider/util.py
Expand Up @@ -3,10 +3,12 @@

import logging
import datetime
from future.utils import python_2_unicode_compatible

from . import db


@python_2_unicode_compatible
class JobError(Exception):
"""The exception type that jobs raise to signal failure."""

Expand All @@ -30,8 +32,7 @@ def as_dict(self):
return {"message": self.message}

def __str__(self):
return '{}'.format(self.message) \
.encode('ascii', 'replace')
return self.message


class StoringHandler(logging.Handler):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -3,3 +3,4 @@ APScheduler==2.1.2
requests==2.23.0
Flask==1.1.1
Flask-Login==0.5.0
future==0.18.2
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -16,6 +16,7 @@
'SQLAlchemy>=1.3.15,<1.4.0',
'requests>=2.23.0',
'flask-login>=0.5.0,<0.6.0',
'future',
]

if sys.version_info[0] < 3:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_joberror.py
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-

from ckanserviceprovider.util import JobError

def test_joberror():
err = JobError(u'oh no ❌')
assert err.message == u'oh no ❌'
assert str(err) == 'oh no ❌'

0 comments on commit b0578e9

Please sign in to comment.