Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove xlsx #371

Merged
merged 5 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
[run]
source = xlrd,scripts,tests

[report]
exclude_lines =
# the original exclude
pragma: no cover

# debug stuff
if DEBUG:
Binary file removed tests/apachepoi_49609.xlsx
Binary file not shown.
Binary file removed tests/apachepoi_52348.xlsx
Binary file not shown.
Binary file removed tests/err_cell_empty.xlsx
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/base.py → tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os


def from_this_dir(filename):
return os.path.join(os.path.dirname(os.path.abspath(__file__)), filename)
def from_sample(filename):
return os.path.join(os.path.dirname(os.path.abspath(__file__)), 'samples', filename)
Binary file removed tests/issue150.xlsx
Binary file not shown.
Binary file removed tests/merged_cells.xlsx
Binary file not shown.
Binary file removed tests/reveng1.xlsx
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added tests/samples/sample.ods
Binary file not shown.
1 change: 1 addition & 0 deletions tests/samples/sample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a text file.
Binary file added tests/samples/sample.xlsb
Binary file not shown.
File renamed without changes.
Binary file added tests/samples/sample.zip
Binary file not shown.
File renamed without changes.
Binary file removed tests/self_evaluation_report_2014-05-19.xlsx
Binary file not shown.
Binary file removed tests/sharedstrings_alt_location.xlsx
Binary file not shown.
18 changes: 0 additions & 18 deletions tests/test_alt_sharedstrings_loc.py

This file was deleted.

29 changes: 3 additions & 26 deletions tests/test_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import xlrd
from xlrd.timemachine import UNICODE_LITERAL

from .base import from_this_dir
from .helpers import from_sample


class TestCell(unittest.TestCase):

def setUp(self):
self.book = xlrd.open_workbook(from_this_dir('profiles.xls'), formatting_info=True)
self.book = xlrd.open_workbook(from_sample('profiles.xls'), formatting_info=True)
self.sheet = self.book.sheet_by_name('PROFILEDEF')

def test_empty_cell(self):
Expand Down Expand Up @@ -43,31 +43,8 @@ def test_calculated_cell(self):
self.assertTrue(cell.xf_index > 0)

def test_merged_cells(self):
book = xlrd.open_workbook(from_this_dir('xf_class.xls'), formatting_info=True)
book = xlrd.open_workbook(from_sample('xf_class.xls'), formatting_info=True)
sheet3 = book.sheet_by_name('table2')
row_lo, row_hi, col_lo, col_hi = sheet3.merged_cells[0]
self.assertEqual(sheet3.cell(row_lo, col_lo).value, 'MERGED')
self.assertEqual((row_lo, row_hi, col_lo, col_hi), (3, 7, 2, 5))

def test_merged_cells_xlsx(self):
book = xlrd.open_workbook(from_this_dir('merged_cells.xlsx'))

sheet1 = book.sheet_by_name('Sheet1')
expected = []
got = sheet1.merged_cells
self.assertEqual(expected, got)

sheet2 = book.sheet_by_name('Sheet2')
expected = [(0, 1, 0, 2)]
got = sheet2.merged_cells
self.assertEqual(expected, got)

sheet3 = book.sheet_by_name('Sheet3')
expected = [(0, 1, 0, 2), (0, 1, 2, 4), (1, 4, 0, 2), (1, 9, 2, 4)]
got = sheet3.merged_cells
self.assertEqual(expected, got)

sheet4 = book.sheet_by_name('Sheet4')
expected = [(0, 1, 0, 2), (2, 20, 0, 1), (1, 6, 2, 5)]
got = sheet4.merged_cells
self.assertEqual(expected, got)
Binary file removed tests/test_comments_excel.xlsx
Binary file not shown.
Binary file removed tests/test_comments_excel_sheet2.xlsx
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import xlrd

from .base import from_this_dir
from .helpers import from_sample

if sys.version_info[0] >= 3:
def u(s): return s
Expand All @@ -18,7 +18,7 @@ def u(s):
class TestCellContent(TestCase):

def setUp(self):
self.book = xlrd.open_workbook(from_this_dir('Formate.xls'), formatting_info=True)
self.book = xlrd.open_workbook(from_sample('Formate.xls'), formatting_info=True)
self.sheet = self.book.sheet_by_name(u('Blätt1'))

def test_text_cells(self):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_formulas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import xlrd

from .base import from_this_dir
from .helpers import from_sample

try:
ascii
Expand All @@ -20,7 +20,7 @@ def ascii(s):
class TestFormulas(TestCase):

def setUp(self):
book = xlrd.open_workbook(from_this_dir('formula_test_sjmachin.xls'))
book = xlrd.open_workbook(from_sample('formula_test_sjmachin.xls'))
self.sheet = book.sheet_by_index(0)

def get_value(self, col, row):
Expand Down Expand Up @@ -56,7 +56,7 @@ def test_cell_B8(self):
class TestNameFormulas(TestCase):

def setUp(self):
book = xlrd.open_workbook(from_this_dir('formula_test_names.xls'))
book = xlrd.open_workbook(from_sample('formula_test_names.xls'))
self.sheet = book.sheet_by_index(0)

def get_value(self, col, row):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_ignore_workbook_corruption_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import xlrd

from .base import from_this_dir
from .helpers import from_sample


class TestIgnoreWorkbookCorruption(TestCase):

def test_not_corrupted(self):
with self.assertRaises(Exception) as context:
xlrd.open_workbook(from_this_dir('corrupted_error.xls'))
xlrd.open_workbook(from_sample('corrupted_error.xls'))
self.assertTrue('Workbook corruption' in str(context.exception))

xlrd.open_workbook(from_this_dir('corrupted_error.xls'), ignore_workbook_corruption=True)
xlrd.open_workbook(from_sample('corrupted_error.xls'), ignore_workbook_corruption=True)
32 changes: 32 additions & 0 deletions tests/test_inspect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from xlrd import inspect_format

from .helpers import from_sample


def test_xlsx():
assert inspect_format(from_sample('sample.xlsx')) == 'xlsx'


def test_xlsb():
assert inspect_format(from_sample('sample.xlsb')) == 'xlsb'


def test_ods():
assert inspect_format(from_sample('sample.ods')) == 'ods'


def test_zip():
assert inspect_format(from_sample('sample.zip')) == 'zip'


def test_xls():
assert inspect_format(from_sample('namesdemo.xls')) == 'xls'


def test_content():
with open(from_sample('sample.xlsx'), 'rb') as source:
assert inspect_format(content=source.read()) == 'xlsx'


def test_unknown():
assert inspect_format(from_sample('sample.txt')) is None
Binary file removed tests/test_lower_case_cellnames.xlsx
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/test_missing_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from xlrd import open_workbook
from xlrd.biffh import XL_CELL_TEXT

from .base import from_this_dir
from .helpers import from_sample


class TestMissingRecords(TestCase):

def setUp(self):
path = from_this_dir('biff4_no_format_no_window2.xls')
path = from_sample('biff4_no_format_no_window2.xls')
self.book = open_workbook(path)
self.sheet = self.book.sheet_by_index(0)

Expand Down
47 changes: 14 additions & 33 deletions tests/test_open_workbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,34 @@
import tempfile
from unittest import TestCase

from xlrd import open_workbook
import pytest

from .base import from_this_dir
from xlrd import open_workbook, XLRDError

from .helpers import from_sample

class TestOpen(TestCase):

class TestOpen(object):
# test different uses of open_workbook

def test_names_demo(self):
# For now, we just check this doesn't raise an error.
open_workbook(
from_this_dir(from_this_dir('namesdemo.xls')),
)

def test_tilde_path_expansion(self):
with tempfile.NamedTemporaryFile(suffix='.xlsx', dir=os.path.expanduser('~')) as fp:
shutil.copyfile(from_this_dir('text_bar.xlsx'), fp.name)
# For now, we just check this doesn't raise an error.
open_workbook(os.path.join('~', os.path.basename(fp.name)))
open_workbook(from_sample('namesdemo.xls'))

def test_ragged_rows_tidied_with_formatting(self):
# For now, we just check this doesn't raise an error.
open_workbook(from_this_dir('issue20.xls'),
open_workbook(from_sample('issue20.xls'),
formatting_info=True)

def test_BYTES_X00(self):
# For now, we just check this doesn't raise an error.
open_workbook(from_this_dir('picture_in_cell.xls'),
open_workbook(from_sample('picture_in_cell.xls'),
formatting_info=True)

def test_xlsx_simple(self):
# For now, we just check this doesn't raise an error.
open_workbook(from_this_dir('text_bar.xlsx'))
# we should make assertions here that data has been
# correctly processed.

def test_xlsx(self):
# For now, we just check this doesn't raise an error.
open_workbook(from_this_dir('reveng1.xlsx'))
# we should make assertions here that data has been
# correctly processed.


def test_err_cell_empty(self):
# For cell with type "e" (error) but without inner 'val' tags
open_workbook(from_this_dir('err_cell_empty.xlsx'))
def test_open_xlsx(self):
with pytest.raises(XLRDError, match='Excel xlsx file; not supported'):
open_workbook(from_sample('sample.xlsx'))

def test_xlsx_lower_case_cellnames(self):
# Check if it opens with lower cell names
open_workbook(from_this_dir('test_lower_case_cellnames.xlsx'))
def test_open_unknown(self):
with pytest.raises(XLRDError, match="Unsupported format, or corrupt file"):
open_workbook(from_sample('sample.txt'))
15 changes: 3 additions & 12 deletions tests/test_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import xlrd
from xlrd.timemachine import xrange

from .base import from_this_dir
from .helpers import from_sample

SHEETINDEX = 0
NROWS = 15
Expand All @@ -22,7 +22,7 @@ class TestSheet(TestCase):
'AXISDATUMLEVELS', 'PROFILELEVELS']

def setUp(self):
self.book = xlrd.open_workbook(from_this_dir('profiles.xls'), formatting_info=True)
self.book = xlrd.open_workbook(from_sample('profiles.xls'), formatting_info=True)

def check_sheet_function(self, function):
self.assertTrue(function(0, 0))
Expand Down Expand Up @@ -151,19 +151,10 @@ def test_row_values(self):
class TestSheetRagged(TestCase):

def test_read_ragged(self):
book = xlrd.open_workbook(from_this_dir('ragged.xls'), ragged_rows=True)
book = xlrd.open_workbook(from_sample('ragged.xls'), ragged_rows=True)
sheet = book.sheet_by_index(0)
self.assertEqual(sheet.row_len(0), 3)
self.assertEqual(sheet.row_len(1), 2)
self.assertEqual(sheet.row_len(2), 1)
self.assertEqual(sheet.row_len(3), 4)
self.assertEqual(sheet.row_len(4), 4)


class TestMergedCells(TestCase):

def test_tidy_dimensions(self):
book = xlrd.open_workbook(from_this_dir('merged_cells.xlsx'))
for sheet in book.sheets():
for rowx in xrange(sheet.nrows):
self.assertEqual(sheet.row_len(rowx), sheet.ncols)
4 changes: 2 additions & 2 deletions tests/test_workbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from xlrd.book import Book
from xlrd.sheet import Sheet

from .base import from_this_dir
from .helpers import from_sample

SHEETINDEX = 0
NROWS = 15
Expand All @@ -19,7 +19,7 @@ class TestWorkbook(TestCase):
'AXISDATUMLEVELS', 'PROFILELEVELS']

def setUp(self):
self.book = open_workbook(from_this_dir('profiles.xls'))
self.book = open_workbook(from_sample('profiles.xls'))

def test_open_workbook(self):
self.assertTrue(isinstance(self.book, Book))
Expand Down
54 changes: 0 additions & 54 deletions tests/test_xlsx_comments.py

This file was deleted.

Loading