Browse files

BUMP_VERSION: 1.5.3.1

Add tweaks to make more Python version indepedent (avoid: Deprecated warnings).
Fix unknown ZERO variable problem in parse.FixedTzOffset (detected by pylint).
Fix: remove unknown 'variable' TODO in date_convert() function.
  • Loading branch information...
1 parent 6f6c1c1 commit 14be08a149dad19555bc576c58d350085917136c @jenisys jenisys committed with Nov 3, 2012
Showing with 36 additions and 26 deletions.
  1. +3 −0 .gitignore
  2. +5 −4 README.rst
  3. +10 −7 parse.py
  4. +13 −13 test_parse.py
  5. +5 −2 tox.ini
View
3 .gitignore
@@ -1,5 +1,8 @@
*.pyc
+*.pyo
+.cache/
+.idea/
.tox/
__pycache__/
View
9 README.rst
@@ -233,21 +233,22 @@ with the same identifier.
<Result ('HELLO',) {}>
-If the converter has a ``pattern`` attribute, it is used for better
-pattern matching (instead of the default one).
+If the converter has the optional ``pattern`` attribute, it is used as
+regular expression for better pattern matching (instead of the default one).
>>> def parse_number(text):
... return int(text)
>>> parse_number.pattern = r'\d+'
>>> parse('Answer: {number:Number}', 'Answer: 42', dict(Number=parse_number))
<Result () {'number': 42}>
->>> parse('Answer: {number:Number}', 'Answer: Alice', dict(Number=parse_number))
->>> # -- MISMATCH: Returns None
+>>> _ = parse('Answer: {:Number}', 'Answer: Alice', dict(Number=parse_number))
+>>> assert _ is None, "MISMATCH"
----
**Version history (in brief)**:
+- 1.5.3.1 Add support for optional 'pattern' attribute in user-defined types.
- 1.5.3 fix handling of question marks
- 1.5.2 fix type conversion error with dotted names (thanks Sebastian Thiel)
- 1.5.1 implement handling of named datetime fields
View
17 parse.py
@@ -233,21 +233,22 @@
<Result ('HELLO',) {}>
-If the converter has a ``pattern`` attribute, it is used for better
-pattern matching (instead of the default one).
+If the converter has the optional ``pattern`` attribute, it is used as
+regular expression for better pattern matching (instead of the default one).
>>> def parse_number(text):
... return int(text)
>>> parse_number.pattern = r'\d+'
>>> parse('Answer: {number:Number}', 'Answer: 42', dict(Number=parse_number))
<Result () {'number': 42}>
->>> parse('Answer: {number:Number}', 'Answer: Alice', dict(Number=parse_number))
->>> # -- MISMATCH: Returns None
+>>> _ = parse('Answer: {:Number}', 'Answer: Alice', dict(Number=parse_number))
+>>> assert _ is None, "MISMATCH"
----
**Version history (in brief)**:
+- 1.5.3.1 Add support for optional 'pattern' attribute in user-defined types.
- 1.5.3 fix handling of question marks
- 1.5.2 fix type conversion error with dotted names (thanks Sebastian Thiel)
- 1.5.1 implement handling of named datetime fields
@@ -284,7 +285,7 @@
This code is copyright 2012 Richard Jones <richard@python.org>
See the end of the source file for the license of use.
'''
-__version__ = '1.5.3'
+__version__ = '1.5.3.1'
# yes, I now have two problems
import re
@@ -338,6 +339,8 @@ def percentage(string, match):
class FixedTzOffset(tzinfo):
"""Fixed offset in minutes east from UTC.
"""
+ ZERO = timedelta(0)
+
def __init__(self, offset, name):
self._offset = timedelta(minutes = offset)
self._name = name
@@ -352,7 +355,7 @@ def tzname(self, dt):
return self._name
def dst(self, dt):
- return ZERO
+ return self.ZERO
def __eq__(self, other):
return self._name == other._name and self._offset == other._offset
@@ -427,7 +430,7 @@ def date_convert(string, match, ymd=None, mdy=None, dmy=None,
tz = tz.strip()
if tz.isupper():
# TODO use the awesome python TZ module?
- TODO
+ pass
else:
sign = tz[0]
if ':' in tz:
View
26 test_parse.py
@@ -91,20 +91,20 @@ def test_dot_separated_fields_name_collisions(self):
assert res.named['a___b'] == 'd'
def test_invalid_groupnames_are_handled_gracefully(self):
- self.failUnlessRaises(NotImplementedError, parse.parse,
+ self.assertRaises(NotImplementedError, parse.parse,
"{hello['world']}", "doesn't work")
class TestResult(unittest.TestCase):
def test_fixed_access(self):
r = parse.Result((1, 2), {}, None)
- self.assertEquals(r[0], 1)
- self.assertEquals(r[1], 2)
+ self.assertEqual(r[0], 1)
+ self.assertEqual(r[1], 2)
self.assertRaises(IndexError, r.__getitem__, 2)
self.assertRaises(KeyError, r.__getitem__, 'spam')
def test_named_access(self):
r = parse.Result((), {'spam': 'ham'}, None)
- self.assertEquals(r['spam'], 'ham')
+ self.assertEqual(r['spam'], 'ham')
self.assertRaises(KeyError, r.__getitem__, 'ham')
self.assertRaises(IndexError, r.__getitem__, 0)
@@ -561,25 +561,25 @@ def test_findall(self):
class TestBugs(unittest.TestCase):
def test_named_date_issue7(self):
r = parse.parse('on {date:ti}', 'on 2012-09-17')
- self.assertEquals(r['date'], datetime(2012, 9, 17, 0, 0, 0))
+ self.assertEqual(r['date'], datetime(2012, 9, 17, 0, 0, 0))
# fix introduced regressions
r = parse.parse('a {:ti} b', 'a 1997-07-16T19:20 b')
- self.assertEquals(r[0], datetime(1997, 7, 16, 19, 20, 0))
+ self.assertEqual(r[0], datetime(1997, 7, 16, 19, 20, 0))
r = parse.parse('a {:ti} b', 'a 1997-07-16T19:20Z b')
utc = parse.FixedTzOffset(0, 'UTC')
- self.assertEquals(r[0], datetime(1997, 7, 16, 19, 20, tzinfo=utc))
+ self.assertEqual(r[0], datetime(1997, 7, 16, 19, 20, tzinfo=utc))
r = parse.parse('a {date:ti} b', 'a 1997-07-16T19:20Z b')
- self.assertEquals(r['date'], datetime(1997, 7, 16, 19, 20, tzinfo=utc))
+ self.assertEqual(r['date'], datetime(1997, 7, 16, 19, 20, tzinfo=utc))
def test_dotted_type_conversion_pull_8(self):
# test pull request 8 which fixes type conversion related to dotted
# names being applied correctly
r = parse.parse('{a.b:d}', '1')
- self.assertEquals(r['a.b'], 1)
+ self.assertEqual(r['a.b'], 1)
r = parse.parse('{a_b:w} {a.b:d}', '1 2')
- self.assertEquals(r['a_b'], '1')
- self.assertEquals(r['a.b'], 2)
+ self.assertEqual(r['a_b'], '1')
+ self.assertEqual(r['a.b'], 2)
# -----------------------------------------------------------------------------
# TEST SUPPORT FOR: TestParseType
@@ -610,7 +610,7 @@ class TestParseType(unittest.TestCase):
def _check(self, parser, text, param_name, expected):
result = parser.parse(text)
- self.assertEquals(result[param_name], expected)
+ self.assertEqual(result[param_name], expected)
def _check_mismatch(self, parser, text, param_name):
result = parser.parse(text)
@@ -633,7 +633,7 @@ def test_pattern_should_be_used2(self):
# -- ENSURE: Known enum values are correctly extracted.
for value_name, value in parse_yesno.mapping.items():
- text = "Answer: {0}".format(value_name)
+ text = "Answer: %s" % value_name
self._check(parser, text, "answer", value)
# -- IGNORE-CASE: In parsing, calls type converter function !!!
View
7 tox.ini
@@ -1,5 +1,5 @@
[tox]
-envlist = py25, py26, py27, py31, py32, doctest, rst
+envlist = py25, py26, py27, py31, py32, py33, doctest, rst
[testenv]
commands = {envpython} test_parse.py
@@ -8,5 +8,8 @@ commands = {envpython} test_parse.py
commands = python -mdoctest README.rst
[testenv:rst]
+changedir = {toxworkdir}/{envname}
+commands = rst2html.py --halt=warning ../../README.rst README.html
+# -- FAILS with tox 1.4.2:
+# commands = rst2html.py --halt=warning README.rst {envtmpdir}/README.html
deps = docutils
-commands = rst2html.py --halt=warning README.rst {envtmpdir}/README.html

0 comments on commit 14be08a

Please sign in to comment.