Skip to content

Commit

Permalink
closes #309
Browse files Browse the repository at this point in the history
  • Loading branch information
alimanfoo committed Jan 21, 2015
1 parent 60081e8 commit ed50403
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
21 changes: 21 additions & 0 deletions petl/test/util/test_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import, print_function, division


from petl.errors import ArgumentError
from petl.test.helpers import ieq, eq_
from petl.compat import next
from petl.util.base import header, fieldnames, data, dicts, records, \
Expand Down Expand Up @@ -86,6 +87,26 @@ def test_records():
eq_(2, o.bar)


def test_records_errors():
table = (('foo', 'bar'), ('a', 1), ('b', 2))
actual = records(table)
# access items
it = iter(actual)
o = next(it)
try:
o['baz']
except ArgumentError:
pass
else:
raise Exception('expected exception not raised')
try:
o.baz
except ArgumentError:
pass
else:
raise Exception('expected exception not raised')


def test_records_unevenrows():
table = (('foo', 'bar'), ('a', 1, True), ('b',))
actual = records(table)
Expand Down
2 changes: 1 addition & 1 deletion petl/transform/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import re
import operator
from petl.compat import next, string_types, text_type
from petl.compat import next, text_type


from petl.errors import ArgumentError
Expand Down
1 change: 0 additions & 1 deletion petl/transform/selects.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


import operator
import re
from petl.compat import next, string_types, callable, text_type
from petl.comparison import Comparable

Expand Down
6 changes: 3 additions & 3 deletions petl/util/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
next, string_types, text_type


from petl.errors import FieldSelectionError
from petl.errors import FieldSelectionError, ArgumentError
from petl.comparison import comparable_itemgetter


Expand Down Expand Up @@ -563,7 +563,7 @@ def __getitem__(self, f):
idx = self.flds.index(f)
else:
raise ArgumentError('item ' + repr(f) +
' not in fields ' + repr(self.flds))
' not in fields ' + repr(self.flds))
try:
return super(Record, self).__getitem__(idx)
except IndexError: # handle short rows
Expand All @@ -577,7 +577,7 @@ def __getattr__(self, f):
return self.missing
else:
raise ArgumentError('item ' + repr(f) +
' not in fields ' + repr(self.flds))
' not in fields ' + repr(self.flds))


def records(table, *sliceargs, **kwargs):
Expand Down

0 comments on commit ed50403

Please sign in to comment.