Skip to content

Commit

Permalink
Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
masaccio committed Dec 14, 2024
1 parent 720d774 commit 115cf5c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/numbers_parser/iwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ def save(self, filepath: Path, file_store: dict[str, object], package: bool) ->
def _open_zipfile(self, filepath: Path):
"""Open Zip file with the correct filename encoding supported by current python."""
# Coverage is python version dependent, so one path with always fail coverage
try:
if version_info >= (3, 11): # pragma: no cover
try: # pragma: no cover
if version_info >= (3, 11):
return ZipFile(filepath, metadata_encoding="utf-8")
# pragma: no cover
return ZipFile(filepath)

except BadZipFile:
msg = "invalid Numbers document"
raise FileFormatError(msg) from None
Expand Down
8 changes: 3 additions & 5 deletions src/numbers_parser/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,12 +877,11 @@ def table_id_to_sheet_id(self, table_id: int) -> int:
return None

@cache()
def table_uuids_to_id(self, table_uuid) -> int:
for sheet_id in self.sheet_ids(): # pragma: no branch
def table_uuids_to_id(self, table_uuid) -> int | None:
for sheet_id in self.sheet_ids(): # pragma: no branch # noqa: RET503
for table_id in self.table_ids(sheet_id):
if table_uuid == self.table_base_id(table_id):
return table_id
return None

def node_to_ref(self, this_table_id: int, row: int, col: int, node):
if node.HasField("AST_cross_table_reference_extra_info"):
Expand Down Expand Up @@ -1980,7 +1979,7 @@ def table_rich_text(self, table_id: int, string_key: int) -> dict:
# a string with a new bullet character
bds = self.objects[table_id].base_data_store
rich_text_table = self.objects[bds.rich_text_table.identifier]
for entry in rich_text_table.entries: # pragma: no branch
for entry in rich_text_table.entries: # pragma: no branch # noqa: RET503
if string_key == entry.key:
payload = self.objects[entry.rich_text_payload.identifier]
payload_storage = self.objects[payload.storage.identifier]
Expand Down Expand Up @@ -2034,7 +2033,6 @@ def table_rich_text(self, table_id: int, string_key: int) -> dict:
"bullet_chars": bullet_chars,
"hyperlinks": hyperlinks,
}
return None

def cell_text_style(self, cell: Cell) -> object:
"""
Expand Down
Binary file not shown.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileFormatVersion</key>
<string>12.1</string>
</dict>
</plist>
7 changes: 7 additions & 0 deletions tests/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
CellBorder,
CustomFormatting,
Document,
FileFormatError,
Formatting,
PaddingType,
UnsupportedError,
Expand Down Expand Up @@ -300,3 +301,9 @@ def test_invalid_format():
cell = doc.default_table.cell(1, 1)
cell._text_format_id = None
assert cell._custom_format() == cell.value


def test_invalid_format_2():
with pytest.raises(FileFormatError) as e:
_ = Document("tests/data/invalid-index-zip.numbers")
assert "invalid Numbers document" in str(e)

0 comments on commit 115cf5c

Please sign in to comment.