1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 08:04:49 +01:00

cdxobject: add ability to create empty CDXObject(), add tests for

CDXObject/IDXObject checking for supported and unsupported number of
fields
This commit is contained in:
Ilya Kreymer 2014-09-22 21:12:25 -07:00
parent e2f8594ea7
commit 319b8124be
2 changed files with 39 additions and 1 deletions

View File

@ -46,10 +46,16 @@ class CDXObject(OrderedDict):
"orig.length", "orig.offset", "orig.filename"]
]
def __init__(self, cdxline):
def __init__(self, cdxline=''):
OrderedDict.__init__(self)
cdxline = cdxline.rstrip()
# Allows for filling the fields later or in a custom way
if not cdxline:
self.cdxline = cdxline
return
fields = cdxline.split(' ')
cdxformat = None

View File

@ -0,0 +1,32 @@
from pywb.cdx.cdxobject import CDXObject, IDXObject, CDXException
from pytest import raises
def test_empty_cdxobject():
x = CDXObject('')
assert len(x) == 0
def test_invalid_cdx_format():
with raises(CDXException):
x = CDXObject('a b c')
def _make_line(fields):
line = ' '.join(['-'] * fields)
x = CDXObject(line)
assert len(x) == fields
assert str(x) == line
def test_valid_cdx_formats():
# Currently supported cdx formats, 9, 11, 12, 14 field
# See CDXObject for more details
_make_line(9)
_make_line(12)
_make_line(11)
_make_line(14)
def test_invalid_idx_format():
with raises(CDXException):
x = IDXObject('a b c')