Skip to content

Commit 4d92b1d

Browse files
author
Dean Malmgren
committed
added Detector.filth_cls. closes #13
1 parent 1cc1a57 commit 4d92b1d

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

docs/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ latest changes in development for next release
1111

1212
.. THANKS FOR CONTRIBUTING; MENTION WHAT YOU DID IN THIS SECTION HERE!
1313
14+
1.0.2
15+
-----
16+
17+
* minor change to force ``Detector.filth_cls`` to exist (`#13`_)
18+
1419
1.0.1
1520
-----
1621

@@ -66,3 +71,4 @@ latest changes in development for next release
6671
.. _#10: https://github.com/datascopeanalytics/scrubadub/issues/10
6772
.. _#11: https://github.com/datascopeanalytics/scrubadub/issues/11
6873
.. _#12: https://github.com/datascopeanalytics/scrubadub/issues/12
74+
.. _#13: https://github.com/datascopeanalytics/scrubadub/issues/13

scrubadub/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from . import filth
55
from . import detectors
66

7-
__version__ = VERSION = "1.0.1"
7+
__version__ = VERSION = "1.0.2"
88

99

1010
def clean(text, cls=None, **kwargs):

scrubadub/detectors/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import re
22

33
from .. import exceptions
4-
from ..filth import RegexFilth
4+
from ..filth import Filth, RegexFilth
55

66

77
class Detector(object):
8+
filth_cls = None
9+
810
def iter_filth(self, text):
911
raise NotImplementedError('must be overridden by base classes')
1012

1113

1214
class RegexDetector(Detector):
13-
filth_cls = RegexFilth
1415

1516
def iter_filth(self, text):
1617
if not issubclass(self.filth_cls, RegexFilth):

scrubadub/detectors/phone.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class PhoneDetector(Detector):
1414
``"US"``). Specify ``None`` to only consider numbers with a leading
1515
``+`` to be considered.
1616
"""
17+
filth_cls = PhoneFilth
1718
region = 'US'
1819

1920
def iter_filth(self, text):

tests/test_detector.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import unittest
22

3+
import scrubadub
34
from scrubadub.detectors.base import RegexDetector
45
from scrubadub.filth.base import Filth
56
from scrubadub.exceptions import UnexpectedFilth
@@ -21,3 +22,10 @@ class MyDetector(RegexDetector):
2122
with self.assertRaises(UnexpectedFilth):
2223
for filth in detector.iter_filth(text):
2324
pass
25+
26+
def test_detector_filth_cls(self):
27+
"""Detector.filth_cls should always exist"""
28+
for name, detector_cls in scrubadub.detectors.types.iteritems():
29+
self.assertTrue(getattr(detector_cls, 'filth_cls', False),
30+
'%s does not have a filth_cls set' % detector_cls
31+
)

0 commit comments

Comments
 (0)