def test_read_dictionary(): input = b""" << /Type /Example /Subtype /DictionaryExample /Version 0.01 /IntegerItem 12 /StringItem (a string) /Subdictionary << /Item1 0.4 /Item2 true /LastItem (not!) /VeryLastItem (OK) >> >>""" reader = PDFObjectReader(BytesIO(input)) result = reader.next_item() expected = cos.Dictionary([('Type', cos.Name('Example')), ('Subtype', cos.Name('DictionaryExample')), ('Version', cos.Real(0.01)), ('IntegerItem', cos.Integer(12)), ('StringItem', cos.String('a string')), ('Subdictionary', cos.Dictionary( [('Item1', cos.Real(0.4)), ('Item2', cos.Boolean(True)), ('LastItem', cos.String('not!')), ('VeryLastItem', cos.String('OK'))]))]) assert isinstance(result, cos.Dictionary) assert dict(result) == dict(expected)
def test_name(bytes_name, unicode_name): reader = PDFObjectReader(BytesIO(bytes_name)) result = reader.next_item() assert isinstance(result, cos.Name) and str(result) == unicode_name
def test_integer(bytes_integer, integer): reader = PDFObjectReader(BytesIO(bytes_integer)) result = reader.next_item() assert isinstance(result, cos.Integer) and result == integer
def test_real(bytes_real, real): reader = PDFObjectReader(BytesIO(bytes_real)) result = reader.next_item() assert isinstance(result, cos.Real) and result == real
def test_boolean(bytes_boolean, boolean): reader = PDFObjectReader(BytesIO(bytes_boolean)) result = reader.next_item() assert isinstance(result, cos.Boolean) and bool(result) == boolean