/usr/lib/python3/dist-packages/openpyxl/reader/tests/test_excel.py is in python3-openpyxl 2.3.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | from __future__ import absolute_import
# Copyright (c) 2010-2015 openpyxl
from io import BytesIO
from tempfile import NamedTemporaryFile
from zipfile import BadZipfile
from openpyxl.utils.exceptions import InvalidFileException
from .. excel import load_workbook
import pytest
def test_read_empty_file(datadir):
datadir.chdir()
with pytest.raises(BadZipfile):
load_workbook('null_file.xlsx')
def test_load_workbook_from_fileobj(datadir):
""" can a workbook be loaded from a file object without exceptions
This tests for regressions of
https://bitbucket.org/openpyxl/openpyxl/issue/433
"""
datadir.chdir()
with open('empty_with_no_properties.xlsx', 'rb') as f:
load_workbook(f)
def test_repair_central_directory():
from ..excel import repair_central_directory, CENTRAL_DIRECTORY_SIGNATURE
data_a = b"foobarbaz" + CENTRAL_DIRECTORY_SIGNATURE
data_b = b"bazbarfoo1234567890123456890"
# The repair_central_directory looks for a magic set of bytes
# (CENTRAL_DIRECTORY_SIGNATURE) and strips off everything 18 bytes past the sequence
f = repair_central_directory(BytesIO(data_a + data_b), True)
assert f.read() == data_a + data_b[:18]
f = repair_central_directory(BytesIO(data_b), True)
assert f.read() == data_b
@pytest.mark.parametrize("extension",
['.xlsb', '.xls', 'no-format']
)
def test_invalid_file_extension(extension):
tmp = NamedTemporaryFile(suffix=extension)
with pytest.raises(InvalidFileException):
load_workbook(filename=tmp.name)
def test_style_assignment(datadir):
from ..excel import load_workbook
datadir.chdir()
wb = load_workbook("complex-styles.xlsx")
assert len(wb._alignments) == 9
assert len(wb._fills) == 6
assert len(wb._fonts) == 8
assert len(wb._borders) == 7
assert len(wb._number_formats) == 0
assert len(wb._protections) == 1
def test_read_stringio():
filelike = BytesIO(b"certainly not a valid XSLX content")
# Test invalid file-like objects are detected and not handled as regular files
with pytest.raises(BadZipfile):
load_workbook(filelike)
|