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:
parent
e2f8594ea7
commit
319b8124be
@ -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
|
||||
|
32
pywb/cdx/test/test_cdxobject.py
Normal file
32
pywb/cdx/test/test_cdxobject.py
Normal 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')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user