Skip to content

Commit

Permalink
Code review changes
Browse files Browse the repository at this point in the history
Added ``SerializeError``. Fixed overly long line.
  • Loading branch information
jrwdunham committed Sep 25, 2018
1 parent 669323a commit d4280dc
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
6 changes: 4 additions & 2 deletions metsrw/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

class MetsError(Exception):
""" Base Exception for this module. """
pass


class ParseError(MetsError):
""" Error parsing a METS file. """
pass


class SerializeError(MetsError):
""" Error serializing a METS file. """
2 changes: 1 addition & 1 deletion metsrw/fsentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def serialize_filesec(self):
flocat.set(
utils.lxmlns('xlink') + 'href', utils.urlencode(self.path))
except ValueError:
raise exceptions.MetsError(
raise exceptions.SerializeError(
'Value "{}" (for attribute xlink:href) is not a valid'
' URL.'.format(self.path))
flocat.set('LOCTYPE', 'OTHER')
Expand Down
2 changes: 1 addition & 1 deletion metsrw/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def serialize(self):
el.attrib[utils.lxmlns('xlink') + 'href'] = \
utils.urlencode(self.target)
except ValueError:
raise exceptions.MetsError(
raise exceptions.SerializeError(
'Value "{}" (for attribute xlink:href) is not a valid'
' URL.'.format(self.target))
el.attrib['MDTYPE'] = self.mdtype
Expand Down
7 changes: 6 additions & 1 deletion metsrw/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# -*- coding: utf-8 -*-
from six.moves.urllib.parse import quote_plus, unquote_plus, urlparse, urlunparse
from six.moves.urllib.parse import (
quote_plus,
unquote_plus,
urlparse,
urlunparse,
)


####################################
Expand Down
2 changes: 1 addition & 1 deletion tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def test_url_encoding(self):
mdreffed = mdref.serialize()
assert mdreffed.get(metsrw.lxmlns('xlink') + 'href') == (
'30_CFLQ_271_13-3-13_1524%5B1%5D.pdf')
with pytest.raises(metsrw.exceptions.MetsError,
with pytest.raises(metsrw.exceptions.SerializeError,
match='is not a valid URL.'):
mdref = metsrw.MDRef(
'http://foo[bar.com/hello[1].pdf', 'PREMIS:DUMMY', 'URL')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mets.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,6 @@ def test_files_invalid_path(self):
file_uuid=str(uuid.uuid4()))
mw = metsrw.METSDocument()
mw.append_file(f1)
with pytest.raises(metsrw.exceptions.MetsError,
with pytest.raises(metsrw.exceptions.SerializeError,
match='is not a valid URL.'):
mw.serialize()

0 comments on commit d4280dc

Please sign in to comment.