示例#1
0
def test_get_value_invalid_offset():
    ifd = Ifd("<", blob=ifd_bytes)
    assert len(ifd.entries) == 2
    assert ifd.get_value(ifd.entries['data_offset']) == \
        ifd.entries['data_offset'].raw_value
    assert ifd.get_value(ifd.entries['data_length']) == \
        ifd.entries['data_length'].raw_value
示例#2
0
def test_new_ifd_from_file(tmpdir):
    p = tmpdir.realpath().strpath
    with open(os.path.join(p, 'ifd'), mode='w+b') as tmpfile:
        tmpfile.write(ifd_bytes)
        tmpfile.seek(0)
        ifd = Ifd("<", file=tmpfile)
        assert len(ifd.entries) == 2
示例#3
0
    def __init__(self, blob=None, file=None, filename=None):
        super(Cr2, self).__init__(blob=blob, file=file, filename=filename)

        pos = self.tell()
        self.header = Header(self.read(16))
        self.ifds = []
        self.ifds.append(Ifd(self.endianness, file=self.fhandle, tags=tags,
                             subdirs=subdirs))
        next_ifd_offset = self.ifds[0].next_ifd_offset

        while next_ifd_offset != 0:
            self.seek(next_ifd_offset)
            self.ifds.append(Ifd(self.endianness, file=self.fhandle, tags=tags,
                                 subdirs=subdirs))
            next_ifd_offset = self.ifds[len(self.ifds) - 1].next_ifd_offset

        self.seek(pos)
示例#4
0
def test_ifds_must_parse_sub_ifds():
    ifd = Ifd("<", blob=ifd_bytes_sub_ifd, subdirs=[0x8769])
    assert 'exif' in ifd.entries
    assert len(ifd.subifds) == 1
    assert 'exif' in ifd.subifds
    assert 'data_offset' in ifd.subifds['exif'].entries
示例#5
0
def test_new_ifd_from_blob_with_offset():
    ifd = Ifd("<", blob=b'\x00' + ifd_bytes, offset=1)
    assert len(ifd.entries) == 2
示例#6
0
def test_new_ifd_from_blob():
    ifd = Ifd("<", blob=ifd_bytes)
    assert len(ifd.entries) == 2
    assert 'data_offset' in ifd.entries
    assert 'data_length' in ifd.entries
示例#7
0
def test_ifd_must_have_single_data_source():
    with pytest.raises(TypeError):
        Ifd("<")
    with pytest.raises(TypeError):
        Ifd("<", blob=1, file=1, offset=1)
示例#8
0
def test_ifd_get_float():
    ifd = Ifd("<", blob=ifd_bytes_float)
    val = ifd.get_value(ifd.entries["make"])
    assert round(val - 1.62, 2) == 0
示例#9
0
def test_ifd_get_float():
    ifd = Ifd("<", blob=ifd_bytes_float)
    val = ifd.get_value(ifd.entries['make'])
    assert round(val - 1.62, 2) == 0
示例#10
0
def test_ifd_get_double():
    ifd = Ifd("<", blob=ifd_bytes_double)
    val = ifd.get_value(ifd.entries['make'])
    assert round(val - 3.14, 2) == 0
示例#11
0
def test_ifd_get_byte_array_value():
    ifd = Ifd("<", blob=ifd_bytes_byte_array)
    val = ifd.get_value(ifd.entries["make"])
    assert isinstance(val, bytes)
    assert val == b"Canon\x00"
示例#12
0
def test_ifd_get_string_value():
    ifd = Ifd("<", blob=ifd_bytes_string_value)
    val = ifd.get_value(ifd.entries["make"])
    assert isinstance(val, (type(u""), str))
    assert val == "Canon"
示例#13
0
def test_get_value_invalid_offset():
    ifd = Ifd("<", blob=ifd_bytes)
    assert len(ifd.entries) == 2
    assert ifd.get_value(ifd.entries["data_offset"]) == ifd.entries["data_offset"].raw_value
    assert ifd.get_value(ifd.entries["data_length"]) == ifd.entries["data_length"].raw_value
示例#14
0
def test_ifd_invalid_pointer():
    ifd = Ifd("<", blob=ifd_bytes_invalid_pointer)
    val = ifd.get_value(ifd.entries["make"])
    assert val == 303174162
示例#15
0
def test_ifd_get_string_value():
    ifd = Ifd("<", blob=ifd_bytes_string_value)
    val = ifd.get_value(ifd.entries['make'])
    assert isinstance(val, (type(u""), str))
    assert val == 'Canon'
示例#16
0
def test_ifd_invalid_pointer():
    ifd = Ifd("<", blob=ifd_bytes_invalid_pointer)
    val = ifd.get_value(ifd.entries['make'])
    assert val == 303174162
示例#17
0
def test_ifd_get_byte_array_value():
    ifd = Ifd("<", blob=ifd_bytes_byte_array)
    val = ifd.get_value(ifd.entries['make'])
    assert isinstance(val, bytes)
    assert val == b'Canon\x00'
示例#18
0
def test_ifd_get_double():
    ifd = Ifd("<", blob=ifd_bytes_double)
    val = ifd.get_value(ifd.entries["make"])
    assert round(val - 3.14, 2) == 0