numbers-parser 4.18.3__tar.gz → 4.18.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. {numbers_parser-4.18.3/src/numbers_parser.egg-info → numbers_parser-4.18.4}/PKG-INFO +1 -1
  2. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/pyproject.toml +7 -6
  3. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/_csv2numbers.py +1 -1
  4. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/cell.py +35 -23
  5. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/constants.py +50 -46
  6. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/formula.py +1 -0
  7. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/model.py +5 -2
  8. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/xrefs.py +17 -5
  9. {numbers_parser-4.18.3 → numbers_parser-4.18.4/src/numbers_parser.egg-info}/PKG-INFO +1 -1
  10. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser.egg-info/SOURCES.txt +1 -0
  11. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_cat_numbers.py +30 -22
  12. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_csv2numbers.py +36 -7
  13. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_formatting.py +9 -1
  14. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_issues.py +20 -1
  15. numbers_parser-4.18.4/tests/test_local_docs.py +95 -0
  16. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_unpack_numbers.py +25 -10
  17. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/LICENSE.rst +0 -0
  18. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/README.md +0 -0
  19. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/setup.cfg +0 -0
  20. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/__init__.py +0 -0
  21. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/_cat_numbers.py +0 -0
  22. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/_unpack_numbers.py +0 -0
  23. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/bullets.py +0 -0
  24. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/containers.py +0 -0
  25. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/currencies.py +0 -0
  26. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/data/empty.numbers +0 -0
  27. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/document.py +0 -0
  28. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/exceptions.py +0 -0
  29. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/experimental.py +0 -0
  30. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TNArchives_pb2.py +0 -0
  31. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TNArchives_sos_pb2.py +0 -0
  32. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TNCommandArchives_pb2.py +0 -0
  33. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TNCommandArchives_sos_pb2.py +0 -0
  34. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSAArchives_pb2.py +0 -0
  35. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSAArchives_sos_pb2.py +0 -0
  36. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSACommandArchives_sos_pb2.py +0 -0
  37. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSCEArchives_pb2.py +0 -0
  38. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSCH3DArchives_pb2.py +0 -0
  39. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSCHArchives_Common_pb2.py +0 -0
  40. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSCHArchives_GEN_pb2.py +0 -0
  41. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSCHArchives_pb2.py +0 -0
  42. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSCHArchives_sos_pb2.py +0 -0
  43. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSCHCommandArchives_pb2.py +0 -0
  44. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSCHPreUFFArchives_pb2.py +0 -0
  45. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSCKArchives_pb2.py +0 -0
  46. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSCKArchives_sos_pb2.py +0 -0
  47. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSDArchives_pb2.py +0 -0
  48. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSDArchives_sos_pb2.py +0 -0
  49. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSDCommandArchives_pb2.py +0 -0
  50. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSKArchives_pb2.py +0 -0
  51. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSPArchiveMessages_pb2.py +0 -0
  52. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSPDatabaseMessages_pb2.py +0 -0
  53. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSPMessages_pb2.py +0 -0
  54. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSSArchives_pb2.py +0 -0
  55. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSSArchives_sos_pb2.py +0 -0
  56. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSTArchives_pb2.py +0 -0
  57. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSTArchives_sos_pb2.py +0 -0
  58. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSTCommandArchives_pb2.py +0 -0
  59. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSTStylePropertyArchiving_pb2.py +0 -0
  60. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSWPArchives_pb2.py +0 -0
  61. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSWPArchives_sos_pb2.py +0 -0
  62. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/TSWPCommandArchives_pb2.py +0 -0
  63. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/__init__.py +0 -0
  64. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/fontmap.py +0 -0
  65. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/functionmap.py +0 -0
  66. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/generated/mapping.py +0 -0
  67. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/iwafile.py +0 -0
  68. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/iwork.py +0 -0
  69. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/numbers_cache.py +0 -0
  70. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/numbers_uuid.py +0 -0
  71. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser/roman.py +0 -0
  72. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser.egg-info/dependency_links.txt +0 -0
  73. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser.egg-info/entry_points.txt +0 -0
  74. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser.egg-info/requires.txt +0 -0
  75. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/src/numbers_parser.egg-info/top_level.txt +0 -0
  76. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_all_formulas.py +0 -0
  77. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_api_change.py +0 -0
  78. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_borders.py +0 -0
  79. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_bullets.py +0 -0
  80. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_categories.py +0 -0
  81. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_coverage.py +0 -0
  82. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_create_cells.py +0 -0
  83. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_currency.py +0 -0
  84. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_folder.py +0 -0
  85. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_formulas.py +0 -0
  86. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_large.py +0 -0
  87. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_memory_leaks.py +0 -0
  88. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_merges.py +0 -0
  89. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_package.py +0 -0
  90. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_properties.py +0 -0
  91. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_roman.py +0 -0
  92. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_save.py +0 -0
  93. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_slices.py +0 -0
  94. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_styles.py +0 -0
  95. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_table_size.py +0 -0
  96. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_tables.py +0 -0
  97. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_unsupported.py +0 -0
  98. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_uuids.py +0 -0
  99. {numbers_parser-4.18.3 → numbers_parser-4.18.4}/tests/test_version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: numbers-parser
3
- Version: 4.18.3
3
+ Version: 4.18.4
4
4
  Summary: Read and write Apple Numbers spreadsheets
5
5
  Author-email: Jon Connell <python@figsandfudge.com>
6
6
  License-Expression: MIT
@@ -22,7 +22,7 @@ classifiers = [
22
22
  description = "Read and write Apple Numbers spreadsheets"
23
23
  name = "numbers-parser"
24
24
  readme = "README.md"
25
- version = "4.18.3"
25
+ version = "4.18.4"
26
26
 
27
27
  [project.urls]
28
28
  repository = "https://github.com/masaccio/numbers-parser"
@@ -35,7 +35,7 @@ csv2numbers = "numbers_parser._csv2numbers:main"
35
35
 
36
36
  [dependency-groups]
37
37
  dev = [
38
- "gprof2dot<2023.0.0,>=2022.7.29",
38
+ "gprof2dot>=2022.7.29,<2026.0.0",
39
39
  "line-profiler>=5.0.0",
40
40
  "mock>=5.1.0",
41
41
  "pytest>=7.2.0",
@@ -43,6 +43,7 @@ dev = [
43
43
  "pytest-console-scripts<2.0.0,>=1.3.1",
44
44
  "pytest-cov>=4.0,>=5.0",
45
45
  "pytest-xdist<4.0.0,>=3.3.1",
46
+ "pytest-profiling",
46
47
  "ruff",
47
48
  "tox<5.0.0,>=4.11.4",
48
49
  "python-magic>=0.4",
@@ -51,14 +52,14 @@ dev = [
51
52
  "pympler<2.0,>=1.1",
52
53
  ]
53
54
  docs = [
54
- "sphinx>=7.3",
55
+ "sphinx<9.0,>=7.3",
55
56
  "enum-tools>=0.11",
56
57
  "sphinx-toolbox>=3.5",
57
58
  "sphinx-nefertiti>=0.7",
58
59
  "sphinx-markdown-builder>=0.6",
59
60
  "sphinx-copybutton>=0.5.2",
60
61
  # Security updates
61
- "urllib3>=2.6.0",
62
+ "urllib3>=2.7.0",
62
63
  "filelock>=3.20.1"
63
64
  ]
64
65
  bootstrap = [
@@ -75,7 +76,7 @@ build-backend = "setuptools.build_meta"
75
76
  [tool.setuptools.packages.find]
76
77
  where = ["src"]
77
78
  include = ["numbers_parser*"]
78
- exclude = ["*tests*"]
79
+ exclude = ["*tests*", "numbers_parser.data"]
79
80
  namespaces = false # disable scanning PEP 420 namespaces
80
81
 
81
82
  [tool.setuptools.package-data]
@@ -94,7 +95,7 @@ addopts = "--cov=src/numbers_parser --cov-report=html --cov-report=term-missing:
94
95
 
95
96
  [tool.tox]
96
97
  requires = ["tox>=4.0"]
97
- envlist = ["py39", "py310", "py311", "py312", "py313"]
98
+ envlist = ["py310", "py311", "py312", "py313"]
98
99
 
99
100
  [testenv]
100
101
  deps = [
@@ -393,7 +393,7 @@ def main() -> None:
393
393
  output_filenames = args.output
394
394
 
395
395
  if len(args.csvfile) != len(output_filenames):
396
- print("The numbers of input and output file names do not match", file=sys.tderr)
396
+ print("The number of input and output file names do not match", file=sys.stderr)
397
397
  sys.exit(1)
398
398
 
399
399
  try:
@@ -867,19 +867,21 @@ class Cell(CellStorageFlags, Cacheable):
867
867
  if flags & 0x80:
868
868
  # cond_style_id skipped
869
869
  offset += 4
870
- # Skip flag 0x100 (cond_rule_style_id)
870
+ if flags & 0x100:
871
+ # cond_rule_style_id skipped
872
+ offset += 4
871
873
  if flags & 0x200:
872
874
  storage_flags._formula_id = unpack("<i", buffer[offset : offset + 4])[0]
873
875
  offset += 4
874
876
  if flags & 0x400:
875
877
  storage_flags._control_id = unpack("<i", buffer[offset : offset + 4])[0]
876
878
  offset += 4
877
- # Skip flag 0x800 (formula_error_id)
879
+ if flags & 0x800:
880
+ storage_flags.formula_error_id = unpack("<i", buffer[offset : offset + 4])[0]
881
+ offset += 4
878
882
  if flags & 0x1000:
879
883
  storage_flags._suggest_id = unpack("<i", buffer[offset : offset + 4])[0]
880
884
  offset += 4
881
- # Skip unused flags
882
- offset += 4 * bin(flags & 0x900).count("1")
883
885
  if flags & 0x2000:
884
886
  storage_flags._num_format_id = unpack("<i", buffer[offset : offset + 4])[0]
885
887
  offset += 4
@@ -1205,7 +1207,8 @@ class Cell(CellStorageFlags, Cacheable):
1205
1207
  elif custom_format.format_type == FormatType.BOOLEAN:
1206
1208
  return "TRUE" if self.value else "FALSE"
1207
1209
  elif custom_format.format_type == FormatType.PERCENT:
1208
- return _format_decimal(self._d128 * 100, custom_format, percent=True)
1210
+ d128 = self._d128 or 0.0
1211
+ return _format_decimal(d128 * 100, custom_format, percent=True)
1209
1212
  elif custom_format.format_type == FormatType.BASE:
1210
1213
  return _format_base(self._d128, custom_format)
1211
1214
  elif custom_format.format_type == FormatType.FRACTION:
@@ -1583,7 +1586,6 @@ def _decode_date_format(date_format, value):
1583
1586
  chars = [*date_format]
1584
1587
  index = 0
1585
1588
  in_string = False
1586
- in_field = False
1587
1589
  result = ""
1588
1590
  field = ""
1589
1591
  while index < len(chars):
@@ -1600,28 +1602,31 @@ def _decode_date_format(date_format, value):
1600
1602
  index += 1
1601
1603
  else:
1602
1604
  in_string = True
1603
- if in_field:
1604
- result += _decode_date_format_field(field, value)
1605
- in_field = False
1606
1605
  index += 1
1607
1606
  elif in_string:
1608
1607
  result += current_char
1609
1608
  index += 1
1610
- elif not current_char.isalpha():
1611
- if in_field:
1612
- result += _decode_date_format_field(field, value)
1613
- in_field = False
1614
- result += current_char
1615
- index += 1
1616
- elif in_field:
1617
- field += current_char
1618
- index += 1
1609
+ elif current_char.isalpha():
1610
+ remaining_str = date_format[index:]
1611
+ matched_field = None
1612
+ for field in DATETIME_FIELD_MAP:
1613
+ # Greedily match the longest possible valid field
1614
+ if remaining_str.startswith(field):
1615
+ matched_field = field
1616
+ break
1617
+
1618
+ if matched_field:
1619
+ result += _decode_date_format_field(matched_field, value)
1620
+ index += len(matched_field)
1621
+ else:
1622
+ unknown_field = ""
1623
+ while index < len(chars) and chars[index].isalpha():
1624
+ unknown_field += chars[index]
1625
+ index += 1
1626
+ result += _decode_date_format_field(unknown_field, value)
1619
1627
  else:
1620
- in_field = True
1621
- field = current_char
1628
+ result += current_char
1622
1629
  index += 1
1623
- if in_field:
1624
- result += _decode_date_format_field(field, value)
1625
1630
 
1626
1631
  return result
1627
1632
 
@@ -1660,6 +1665,9 @@ def _expand_quotes(value: str) -> str:
1660
1665
 
1661
1666
  def _decode_number_format(number_format, value, name): # noqa: PLR0912
1662
1667
  """Parse a custom date format string and return a formatted number value."""
1668
+ if value is None:
1669
+ return None
1670
+
1663
1671
  custom_format_string = number_format.custom_format_string
1664
1672
  value *= number_format.scale_factor
1665
1673
  if "%" in custom_format_string and number_format.scale_factor == 1.0:
@@ -1679,7 +1687,8 @@ def _decode_number_format(number_format, value, name): # noqa: PLR0912
1679
1687
  UnsupportedWarning,
1680
1688
  stacklevel=1,
1681
1689
  )
1682
- return custom_format_string
1690
+ return str(value)
1691
+
1683
1692
  format_spec = match.group(1)
1684
1693
  scientific_spec = match.group(2)
1685
1694
 
@@ -1830,6 +1839,9 @@ def _format_decimal(value: float, number_format, percent: bool = False) -> str:
1830
1839
 
1831
1840
 
1832
1841
  def _format_currency(value: float, number_format) -> str:
1842
+ if value is None:
1843
+ return None
1844
+
1833
1845
  formatted_value = _format_decimal(value, number_format)
1834
1846
  if number_format.currency_code in CURRENCY_SYMBOLS:
1835
1847
  symbol = CURRENCY_SYMBOLS[number_format.currency_code]
@@ -1,4 +1,3 @@
1
- from collections import OrderedDict
2
1
  from datetime import datetime
3
2
  from enum import IntEnum
4
3
  from math import ceil
@@ -82,6 +81,9 @@ CUSTOM_TEXT_PLACEHOLDER = "\ue421"
82
81
 
83
82
  # Supported versions
84
83
  SUPPORTED_NUMBERS_VERSIONS = [
84
+ "10.0",
85
+ "10.1",
86
+ "10.2",
85
87
  "10.3",
86
88
  "11.0",
87
89
  "11.1",
@@ -121,51 +123,53 @@ def _week_of_month(value: datetime) -> int:
121
123
  return ceil((value.day + value.replace(day=1).weekday()) / 7.0)
122
124
 
123
125
 
124
- DATETIME_FIELD_MAP = OrderedDict(
125
- [
126
- # Cell formats
127
- ("a", lambda x: x.strftime("%p").lower()),
128
- ("EEEE", "%A"),
129
- ("EEE", "%a"),
130
- ("yyyy", "%Y"),
131
- ("yy", "%y"),
132
- ("y", "%Y"),
133
- ("MMMM", "%B"),
134
- ("MMM", "%b"),
135
- ("MM", "%m"),
136
- ("M", "%-m"),
137
- ("d", "%-d"),
138
- ("dd", "%d"),
139
- ("DDD", lambda x: str(_day_of_year(x)).zfill(3)),
140
- ("DD", lambda x: str(_day_of_year(x)).zfill(2)),
141
- ("D", lambda x: str(_day_of_year(x)).zfill(1)),
142
- ("HH", "%H"),
143
- ("H", "%-H"),
144
- ("hh", "%I"),
145
- ("h", "%-I"),
146
- ("k", lambda x: str(x.hour).replace("0", "24")),
147
- ("kk", lambda x: str(x.hour).replace("0", "24").zfill(2)),
148
- ("K", lambda x: str(x.hour % 12)),
149
- ("KK", lambda x: str(x.hour % 12).zfill(2)),
150
- ("mm", lambda x: str(x.minute).zfill(2)),
151
- ("m", lambda x: str(x.minute)),
152
- ("ss", "%S"),
153
- ("s", lambda x: str(x.second)),
154
- ("W", lambda x: str(_week_of_month(x) - 1)),
155
- ("ww", "%W"),
156
- ("G", "AD"), # TODO: support BC
157
- ("F", lambda x: _days_occurred_in_month(x)),
158
- ("S", lambda x: str(x.microsecond).zfill(6)[0]),
159
- ("SS", lambda x: str(x.microsecond).zfill(6)[0:2]),
160
- ("SSS", lambda x: str(x.microsecond).zfill(6)[0:3]),
161
- ("SSSS", lambda x: str(x.microsecond).zfill(6)[0:4]),
162
- ("SSSSS", lambda x: str(x.microsecond).zfill(6)[0:5]),
163
- # Table category formats
164
- ("QQQ", lambda x: "Q" + str(int(x.month / 3) + 1)),
165
- ("LLLL", "%B"),
166
- ("w", "%-W"),
167
- ],
168
- )
126
+ # Cell formats. We reorder so that the keys are in length order to greedily
127
+ # match ss in favour of s, etc.
128
+ _DATETIME_FIELD_MAP = {
129
+ "a": lambda x: x.strftime("%p").lower(),
130
+ "EEEE": "%A",
131
+ "EEE": "%a",
132
+ "yyyy": "%Y",
133
+ "yy": "%y",
134
+ "y": "%Y",
135
+ "MMMM": "%B",
136
+ "MMM": "%b",
137
+ "MM": "%m",
138
+ "M": "%-m",
139
+ "d": "%-d",
140
+ "dd": "%d",
141
+ "DDD": lambda x: str(_day_of_year(x)).zfill(3),
142
+ "DD": lambda x: str(_day_of_year(x)).zfill(2),
143
+ "D": lambda x: str(_day_of_year(x)).zfill(1),
144
+ "HH": "%H",
145
+ "H": "%-H",
146
+ "hh": "%I",
147
+ "h": "%-I",
148
+ "k": lambda x: str(x.hour).replace("0", "24"),
149
+ "kk": lambda x: str(x.hour).replace("0", "24").zfill(2),
150
+ "K": lambda x: str(x.hour % 12),
151
+ "KK": lambda x: str(x.hour % 12).zfill(2),
152
+ "mm": lambda x: str(x.minute).zfill(2),
153
+ "m": lambda x: str(x.minute),
154
+ "ss": "%S",
155
+ "s": lambda x: str(x.second),
156
+ "W": lambda x: str(_week_of_month(x) - 1),
157
+ "ww": "%W",
158
+ "G": "AD", # TODO: support BC
159
+ "F": lambda x: _days_occurred_in_month(x),
160
+ "S": lambda x: str(x.microsecond).zfill(6)[0],
161
+ "SS": lambda x: str(x.microsecond).zfill(6)[0:2],
162
+ "SSS": lambda x: str(x.microsecond).zfill(6)[0:3],
163
+ "SSSS": lambda x: str(x.microsecond).zfill(6)[0:4],
164
+ "SSSSS": lambda x: str(x.microsecond).zfill(6)[0:5],
165
+ # Table category formats
166
+ "QQQ": lambda x: "Q" + str(int(x.month / 3) + 1),
167
+ "LLLL": "%B",
168
+ "w": "%-W",
169
+ }
170
+ DATETIME_FIELD_MAP = {
171
+ x: _DATETIME_FIELD_MAP[x] for x in sorted(_DATETIME_FIELD_MAP, key=len, reverse=True)
172
+ }
169
173
 
170
174
  # From TSCEArchives
171
175
  COLON_TRACT_NODE = 67
@@ -218,6 +218,7 @@ NODE_FUNCTION_MAP = {
218
218
  "NUMBER_NODE": "number",
219
219
  "PERCENT_NODE": "percent",
220
220
  "POWER_NODE": "power",
221
+ "PLUS_SIGN_NODE": None,
221
222
  "PREPEND_WHITESPACE_NODE": None,
222
223
  "STRING_NODE": "string",
223
224
  "SUBTRACTION_NODE": "sub",
@@ -2143,7 +2143,7 @@ class _NumbersModel(Cacheable):
2143
2143
  # a string with a new bullet character
2144
2144
  bds = self.objects[table_id].base_data_store
2145
2145
  rich_text_table = self.objects[bds.rich_text_table.identifier]
2146
- for entry in rich_text_table.entries: # pragma: no branch # noqa: RET503
2146
+ for entry in rich_text_table.entries: # pragma: no branch
2147
2147
  if string_key == entry.key:
2148
2148
  payload = self.objects[entry.rich_text_payload.identifier]
2149
2149
  payload_storage = self.objects[payload.storage.identifier]
@@ -2442,7 +2442,10 @@ class _NumbersModel(Cacheable):
2442
2442
  @cache()
2443
2443
  def extract_strokes(self, table_id: int) -> None:
2444
2444
  table_obj = self.objects[table_id]
2445
- sidecar_obj = self.objects[table_obj.stroke_sidecar.identifier]
2445
+ stroke_sidecar_id = table_obj.stroke_sidecar.identifier
2446
+ if stroke_sidecar_id == 0:
2447
+ return
2448
+ sidecar_obj = self.objects[stroke_sidecar_id]
2446
2449
  self.extract_strokes_in_layers(table_id, sidecar_obj.top_row_stroke_layers, "top")
2447
2450
  self.extract_strokes_in_layers(table_id, sidecar_obj.left_column_stroke_layers, "left")
2448
2451
  self.extract_strokes_in_layers(table_id, sidecar_obj.right_column_stroke_layers, "right")
@@ -62,13 +62,19 @@ class CellRange:
62
62
  from_table_id: int = None
63
63
  to_table_id: int = None
64
64
  range_type: CellRangeType = None
65
+ _ref_error: bool = False
65
66
  _do_init: bool = True
66
67
  _table_names: list[str] = field(init=False, default=None, repr=False)
67
68
 
68
69
  def __post_init__(self):
69
- self._initialize_table_data()
70
- self.model.name_ref_cache.refresh()
71
- self._set_sheet_ids()
70
+ if (self.row_start is not None and self.row_start < 0) or (
71
+ self.col_start is not None and self.col_start < 0
72
+ ):
73
+ self._ref_error = True
74
+ else:
75
+ self._initialize_table_data()
76
+ self.model.name_ref_cache.refresh()
77
+ self._set_sheet_ids()
72
78
 
73
79
  def _initialize_table_data(self):
74
80
  self._table_names = self.model.table_names()
@@ -84,6 +90,9 @@ class CellRange:
84
90
  self.to_sheet_id = self.model.table_id_to_sheet_id(self.to_table_id)
85
91
 
86
92
  def expand_ref(self, ref: str, is_abs: bool = False, no_prefix=False) -> str:
93
+ if self._ref_error:
94
+ return "#REF!"
95
+
87
96
  self.model.name_ref_cache.refresh()
88
97
  is_document_unique = (
89
98
  ref.scope == RefScope.DOCUMENT if isinstance(ref, ScopedNameRef) else False
@@ -119,6 +128,9 @@ class CellRange:
119
128
  return f"{sheet_name}::{table_name}::{ref_str}"
120
129
 
121
130
  def __str__(self):
131
+ if self._ref_error:
132
+ return "#REF!"
133
+
122
134
  self.model.name_ref_cache.refresh()
123
135
  # Handle row-only ranges
124
136
  if self.col_start is None:
@@ -183,13 +195,13 @@ class CellRange:
183
195
 
184
196
  def _format_single_column(self, col_start, col_range):
185
197
  """Formats a single column, either numeric or named."""
186
- if col_range[col_start] is None:
198
+ if col_range.get(col_start, None) is None:
187
199
  return self.expand_ref(xl_col_to_name(col_start, col_abs=self.col_start_is_abs))
188
200
  return self.expand_ref(col_range[col_start], self.col_start_is_abs)
189
201
 
190
202
  def _format_column_span(self, col_start, col_end, col_range):
191
203
  """Formats a range of columns."""
192
- if col_range[col_start] is None:
204
+ if col_range.get(col_start, None) is None:
193
205
  return f"{self.expand_ref(xl_col_to_name(col_start, col_abs=self.col_start_is_abs))}:{self.expand_ref(xl_col_to_name(col_end, col_abs=self.col_end_is_abs), no_prefix=True)}"
194
206
  return ":".join(
195
207
  [
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: numbers-parser
3
- Version: 4.18.3
3
+ Version: 4.18.4
4
4
  Summary: Read and write Apple Numbers spreadsheets
5
5
  Author-email: Jon Connell <python@figsandfudge.com>
6
6
  License-Expression: MIT
@@ -80,6 +80,7 @@ tests/test_formatting.py
80
80
  tests/test_formulas.py
81
81
  tests/test_issues.py
82
82
  tests/test_large.py
83
+ tests/test_local_docs.py
83
84
  tests/test_memory_leaks.py
84
85
  tests/test_merges.py
85
86
  tests/test_package.py
@@ -1,4 +1,7 @@
1
1
  import csv
2
+ import runpy
3
+ import sys
4
+ from unittest.mock import patch
2
5
 
3
6
  import pytest
4
7
  import pytest_check as check
@@ -38,11 +41,11 @@ def test_no_documents(script_runner):
38
41
  assert ret.stderr == ""
39
42
 
40
43
 
41
- @pytest.mark.script_launch_mode("subprocess")
44
+ @pytest.mark.script_launch_mode("inprocess")
42
45
  def test_version(script_runner):
43
46
  ret = script_runner.run(["cat-numbers", "--version"], print_result=False)
44
47
  assert ret.success
45
- assert ret.stdout == __version__ + "\n"
48
+ assert ret.stdout.replace("\r\n", "\n") == __version__ + "\n"
46
49
  assert ret.stderr == ""
47
50
 
48
51
 
@@ -97,7 +100,7 @@ def test_brief_contents(script_runner):
97
100
  assert ret.stderr == ""
98
101
 
99
102
 
100
- @pytest.mark.script_launch_mode("subprocess")
103
+ @pytest.mark.script_launch_mode("inprocess")
101
104
  def test_select_sheet(script_runner):
102
105
  ref = ""
103
106
  for row in ZZZ_TABLE_1_REF:
@@ -109,11 +112,11 @@ def test_select_sheet(script_runner):
109
112
  print_result=False,
110
113
  )
111
114
  assert ret.success
112
- assert ret.stdout == ref
115
+ assert ret.stdout.replace("\r\n", "\n") == ref
113
116
  assert ret.stderr == ""
114
117
 
115
118
 
116
- @pytest.mark.script_launch_mode("subprocess")
119
+ @pytest.mark.script_launch_mode("inprocess")
117
120
  def test_select_table(script_runner):
118
121
  ref = ""
119
122
  for row in XXX_TABLE_1_REF:
@@ -123,11 +126,11 @@ def test_select_table(script_runner):
123
126
  print_result=False,
124
127
  )
125
128
  assert ret.success
126
- assert ret.stdout == ref
129
+ assert ret.stdout.replace("\r\n", "\n") == ref
127
130
  assert ret.stderr == ""
128
131
 
129
132
 
130
- @pytest.mark.script_launch_mode("subprocess")
133
+ @pytest.mark.script_launch_mode("inprocess")
131
134
  def test_list_sheets(script_runner):
132
135
  ret = script_runner.run(["cat-numbers", "-S", DOCUMENT], print_result=False)
133
136
  assert ret.success
@@ -135,7 +138,7 @@ def test_list_sheets(script_runner):
135
138
  assert ret.stderr == ""
136
139
 
137
140
 
138
- @pytest.mark.script_launch_mode("subprocess")
141
+ @pytest.mark.script_launch_mode("inprocess")
139
142
  def test_list_tables(script_runner):
140
143
  ret = script_runner.run(["cat-numbers", "-T", DOCUMENT], print_result=False)
141
144
  assert ret.success
@@ -202,7 +205,7 @@ def test_with_formulas(script_runner):
202
205
  ]
203
206
 
204
207
 
205
- @pytest.mark.script_launch_mode("subprocess")
208
+ @pytest.mark.script_launch_mode("inprocess")
206
209
  def test_duration_formatting(script_runner):
207
210
  ret = script_runner.run(
208
211
  ["cat-numbers", "-b", "--formatting", "tests/data/duration_112.numbers"],
@@ -216,7 +219,7 @@ def test_duration_formatting(script_runner):
216
219
  check.equal(row[6], row[13])
217
220
 
218
221
 
219
- @pytest.mark.script_launch_mode("subprocess")
222
+ @pytest.mark.script_launch_mode("inprocess")
220
223
  def test_date_formatting(script_runner):
221
224
  ret = script_runner.run(
222
225
  ["cat-numbers", "-b", "--formatting", "tests/data/date_formats.numbers"],
@@ -230,7 +233,7 @@ def test_date_formatting(script_runner):
230
233
  check.equal(row[6], row[7])
231
234
 
232
235
 
233
- @pytest.mark.script_launch_mode("subprocess")
236
+ @pytest.mark.script_launch_mode("inprocess")
234
237
  def test_debug(script_runner):
235
238
  ret = script_runner.run(
236
239
  [
@@ -246,19 +249,24 @@ def test_debug(script_runner):
246
249
  assert "enabling ExperimentalFeatures.TESTING" in rows[0]
247
250
 
248
251
 
249
- @pytest.mark.script_launch_mode("subprocess")
250
- def test_main(script_runner):
251
- ret = script_runner.run(
252
- ["python3", "-m", "numbers_parser._cat_numbers", "--help"],
253
- print_result=False,
254
- )
255
- assert ret.success
256
- assert "List the names of tables" in ret.stdout
257
- assert "Names of sheet" in ret.stdout
258
- assert ret.stderr == ""
252
+ @pytest.mark.filterwarnings(
253
+ "ignore:'numbers_parser._cat_numbers' found in sys.modules:RuntimeWarning",
254
+ )
255
+ def test_main(capsys):
256
+ with patch.object(sys, "argv", ["_cat_numbers.py", "--help"]):
257
+ with pytest.raises(SystemExit) as excinfo:
258
+ # Use runpy instead of script_runner to ensure coverage
259
+ runpy.run_module("numbers_parser._cat_numbers", run_name="__main__")
259
260
 
261
+ assert excinfo.value.code == 0
260
262
 
261
- @pytest.mark.script_launch_mode("subprocess")
263
+ captured = capsys.readouterr()
264
+ assert "List the names of tables" in captured.out
265
+ assert "Names of sheet" in captured.out
266
+ assert captured.err == ""
267
+
268
+
269
+ @pytest.mark.script_launch_mode("inprocess")
262
270
  def test_errors(script_runner):
263
271
  ret = script_runner.run(["cat-numbers", "tests/data/corrupted.numbers"], print_result=False)
264
272
  assert not ret.success
@@ -1,7 +1,10 @@
1
1
  """Tests for CSV conversion."""
2
2
 
3
+ import runpy
3
4
  import shutil
5
+ import sys
4
6
  from pathlib import Path
7
+ from unittest.mock import patch
5
8
 
6
9
  import pytest
7
10
 
@@ -9,7 +12,7 @@ from numbers_parser import Document, _get_version
9
12
  from numbers_parser._csv2numbers import Transformer
10
13
 
11
14
 
12
- @pytest.mark.script_launch_mode("subprocess")
15
+ @pytest.mark.script_launch_mode("inprocess")
13
16
  def test_help(script_runner) -> None:
14
17
  """Test conversion with no transforms."""
15
18
  ret = script_runner.run(["csv2numbers"], print_result=False)
@@ -21,7 +24,7 @@ def test_help(script_runner) -> None:
21
24
  assert "usage: csv2numbers" in ret.stdout
22
25
 
23
26
 
24
- @pytest.mark.script_launch_mode("subprocess")
27
+ @pytest.mark.script_launch_mode("inprocess")
25
28
  def test_version(script_runner) -> None:
26
29
  """Test Version number."""
27
30
  ret = script_runner.run(["csv2numbers", "-V"], print_result=False)
@@ -64,7 +67,7 @@ def test_defaults_no_header(script_runner, tmp_path) -> None:
64
67
  assert table.cell(3, 1).value == "GROCERY STORE LONDON"
65
68
 
66
69
 
67
- @pytest.mark.script_launch_mode("subprocess")
70
+ @pytest.mark.script_launch_mode("inprocess")
68
71
  def test_errors(script_runner) -> None:
69
72
  """Test error detection in command line."""
70
73
  ret = script_runner.run(
@@ -162,7 +165,7 @@ def test_errors(script_runner) -> None:
162
165
  assert "Index/Metadata.iwa: invalid IWA file Index/Metadata.iwa" in ret.stderr
163
166
 
164
167
 
165
- @pytest.mark.script_launch_mode("subprocess")
168
+ @pytest.mark.script_launch_mode("inprocess")
166
169
  def test_multifile(script_runner, tmp_path) -> None:
167
170
  """Test conversion with no options."""
168
171
  csv_path_1 = str(tmp_path / "format-1.csv")
@@ -193,10 +196,36 @@ def test_multifile(script_runner, tmp_path) -> None:
193
196
  ],
194
197
  print_result=False,
195
198
  )
196
- assert "numbers of input and output file names do not match" in ret.stderr
199
+ assert "number of input and output file names do not match" in ret.stderr
200
+
197
201
 
202
+ @pytest.mark.filterwarnings(
203
+ "ignore:'numbers_parser._csv2numbers' found in sys.modules:RuntimeWarning",
204
+ )
205
+ def test_main(capsys):
206
+ with patch.object(sys, "argv", ["_csv2numbers.py", "--help"]):
207
+ with pytest.raises(SystemExit) as excinfo:
208
+ # Use runpy instead of script_runner to ensure coverage
209
+ runpy.run_module("numbers_parser._csv2numbers", run_name="__main__")
198
210
 
199
- @pytest.mark.script_launch_mode("subprocess")
211
+ assert excinfo.value.code == 0
212
+
213
+ captured = capsys.readouterr()
214
+ assert "strip whitespace from beginning" in captured.out
215
+ assert captured.err == ""
216
+
217
+
218
+ @pytest.mark.script_launch_mode("inprocess")
219
+ def test_arg_len_mismatch(script_runner) -> None:
220
+ """Test conversion with no transforms."""
221
+ ret = script_runner.run(
222
+ ["csv2numbers", "tests/data/format-1.csv", "tests/data/format-2.csv", "-o", "test.numbers"],
223
+ print_result=False,
224
+ )
225
+ assert "The number of input and output file names do not match" in ret.stderr
226
+
227
+
228
+ @pytest.mark.script_launch_mode("inprocess")
200
229
  def test_parse_error(script_runner) -> None:
201
230
  """Test conversion with no transforms."""
202
231
  ret = script_runner.run(
@@ -306,7 +335,7 @@ def test_transforms_format_3(script_runner, tmp_path) -> None:
306
335
  assert table.cell(7, 2).value == -1283.72
307
336
 
308
337
 
309
- @pytest.mark.script_launch_mode("subprocess")
338
+ @pytest.mark.script_launch_mode("inprocess")
310
339
  def test_transforms_lookup(script_runner, tmp_path) -> None:
311
340
  """Test conversion with transformation."""
312
341
  csv_path = str(tmp_path / "matches.csv")
@@ -634,7 +634,7 @@ def test_write_mixed_number_formats(configurable_save_file):
634
634
  -(0x1F0000007F): False,
635
635
  (-0x7FFFFFFFFFF): False,
636
636
  }
637
- for value, base_use_minus_sign in zip(values.keys(), values.values()):
637
+ for value, base_use_minus_sign in values.items():
638
638
  for base_places in [0, 8]:
639
639
  if base not in [2, 8, 16] and not base_use_minus_sign:
640
640
  continue
@@ -953,3 +953,11 @@ def test_write_interactive_formats(configurable_save_file):
953
953
  doc.save(configurable_save_file)
954
954
 
955
955
  run_test_interactive_formats(configurable_save_file)
956
+
957
+
958
+ def test_no_space_date_formats():
959
+ doc = Document("tests/data/date-format-nospace.numbers")
960
+ for row in doc.default_table.rows():
961
+ if row[0].formula is None:
962
+ continue
963
+ assert row[0].formatted_value == row[1].value
@@ -20,6 +20,7 @@ from numbers_parser.constants import (
20
20
  DEFAULT_ROW_COUNT,
21
21
  DEFAULT_ROW_HEIGHT,
22
22
  )
23
+ from numbers_parser.xrefs import CellRange
23
24
 
24
25
  ISSUE_3_REF = [("A", "B"), (2.0, 0.0), (3.0, 1.0), (None, None)]
25
26
  ISSUE_4_REF_1 = "Part 1 \n\nPart 2\n"
@@ -112,7 +113,7 @@ def test_issue_7():
112
113
  table = tables[0]
113
114
  assert table.cell(1, 1).value == ISSUE_7_REF_1
114
115
  assert table.cell(2, 1).value == ISSUE_7_REF_2
115
- assert table.cell(1, 1).bullets[0] == ISSUE_7_REF_1.split("\n")[0]
116
+ assert table.cell(1, 1).bullets[0] == ISSUE_7_REF_1.split("\n", maxsplit=1)[0]
116
117
  assert table.cell(2, 1).bullets[2] == ISSUE_7_REF_2.split("\n")[2]
117
118
 
118
119
 
@@ -629,3 +630,21 @@ def test_issue_104():
629
630
  data = tables["table_name"].rows()
630
631
  assert data[0][0].value == "Data"
631
632
  assert data[3][1].value == "4" # Cell deliberately formatted as text
633
+
634
+
635
+ def test_issue_121():
636
+ doc = Document("tests/data/issue-121.numbers")
637
+ table = doc.sheets[0].tables[0]
638
+ cell = table.cell(1, 2)
639
+ assert isinstance(cell, ErrorCell)
640
+ assert cell.formula == "#REF!"
641
+
642
+ r = CellRange(row_start=cell.row, col_start=-1, model=cell._model)
643
+ assert r.expand_ref("A1") == "#REF!"
644
+
645
+
646
+ def test_issue_131():
647
+ doc = Document("tests/data/issue-131.numbers")
648
+ table = doc.sheets["Test"].tables["Summary"]
649
+ assert table.cell(0, 1).formula == 'SUMIF(Category,"="&A1,Amount)'
650
+ assert table.cell(9, 1).formula == "-SUM(B1:B6)"
@@ -0,0 +1,95 @@
1
+ import os
2
+ import traceback
3
+ import warnings
4
+
5
+ import pytest
6
+
7
+ from numbers_parser import Document, FileFormatError
8
+
9
+ ALL_DOCS_DIRS = [
10
+ os.path.join(os.environ.get("HOME"), x)
11
+ for x in [
12
+ "Documents",
13
+ "Library/Mobile Documents/com~apple~Numbers/Documents",
14
+ ]
15
+ ]
16
+
17
+
18
+ @pytest.mark.experimental
19
+ def test_local_docs():
20
+ def all_doc_cells(doc: Document):
21
+ for sheet in doc.sheets:
22
+ for table in sheet.tables:
23
+ for row in table.rows():
24
+ yield from row
25
+
26
+ def all_docs_paths():
27
+ for docs_dir in ALL_DOCS_DIRS:
28
+ for root, dirs, files in os.walk(docs_dir):
29
+ for file in files + dirs:
30
+ if not file.endswith(".numbers"):
31
+ continue
32
+ path = os.path.join(root, file)
33
+ yield path
34
+
35
+ def check_cell_values(doc: Document):
36
+ for cell in all_doc_cells(doc):
37
+ _ = cell.value
38
+
39
+ def check_cell_formatted_values(doc: Document):
40
+ for cell in all_doc_cells(doc):
41
+ _ = cell.formatted_value
42
+
43
+ def check_cell_formulas(doc: Document):
44
+ for cell in all_doc_cells(doc):
45
+ _ = cell.formula
46
+
47
+ def check_cell_style(doc: Document):
48
+ for cell in all_doc_cells(doc):
49
+ _ = cell.style
50
+
51
+ def check_cell_borders(doc: Document):
52
+ for cell in all_doc_cells(doc):
53
+ _ = cell.border
54
+
55
+ tests = [
56
+ check_cell_values,
57
+ check_cell_formatted_values,
58
+ check_cell_formulas,
59
+ check_cell_style,
60
+ check_cell_borders,
61
+ ]
62
+
63
+ print("\n*** Testing local docs")
64
+ for doc_path in all_docs_paths():
65
+ test_ok_count = 0
66
+ try:
67
+ with warnings.catch_warnings(record=True) as captured_warnings:
68
+ warnings.simplefilter("always")
69
+ doc = Document(doc_path)
70
+ for test in tests:
71
+ test(doc)
72
+ test_ok_count += 1
73
+ except FileFormatError:
74
+ print(f"{doc_path}: invalid Numbers document")
75
+ except Exception as e:
76
+ exc_type = type(e).__name__
77
+ exc_message = str(e)
78
+ extracted_tb = traceback.extract_tb(e.__traceback__)
79
+ last_frame = extracted_tb[-1]
80
+ filename = last_frame.filename
81
+ line_number = last_frame.lineno
82
+ test_name = tests[test_ok_count].__name__
83
+ print(f"{doc_path}: FAILED with {exc_type} exception")
84
+ print(f"\tFailing test: {test_name}")
85
+ print(f"\tMessage: {exc_message}")
86
+ print(f"\tLocation: File '{filename}', line {line_number}")
87
+ else:
88
+ if len(captured_warnings) > 0:
89
+ print(f"{doc_path}: OK with {len(captured_warnings)} warnings")
90
+ for ii, w in enumerate(captured_warnings, start=1):
91
+ if "Custom font" not in str(w.message):
92
+ # Non-standard font found
93
+ print(f"\tWarning #{ii}: {w.category.__name__}: {w.message}")
94
+ else:
95
+ print(f"{doc_path}: OK")
@@ -1,6 +1,8 @@
1
1
  import json
2
+ import runpy
2
3
  import sys
3
4
  from pathlib import Path
5
+ from unittest.mock import patch
4
6
 
5
7
  import magic
6
8
  import pytest
@@ -180,18 +182,23 @@ def test_compact_json(script_runner, tmp_path):
180
182
  assert '"formula_owner_id": {"uuid_w0": 666, "uuid_w1": 0, "uuid_w2": 0, "uuid_w3": 0},' in data
181
183
 
182
184
 
183
- @pytest.mark.script_launch_mode("subprocess")
184
- def test_main(script_runner):
185
- ret = script_runner.run(
186
- ["python3", "-m", "numbers_parser._unpack_numbers", "--help"],
187
- print_result=False,
188
- )
189
- assert ret.success
190
- assert "directory name to unpack into" in ret.stdout
191
- assert ret.stderr == ""
185
+ @pytest.mark.filterwarnings(
186
+ "ignore:'numbers_parser._unpack_numbers' found in sys.modules:RuntimeWarning",
187
+ )
188
+ def test_main(capsys):
189
+ with patch.object(sys, "argv", ["_unpack_numbers.py", "--help"]):
190
+ with pytest.raises(SystemExit) as excinfo:
191
+ # Use runpy instead of script_runner to ensure coverage
192
+ runpy.run_module("numbers_parser._unpack_numbers", run_name="__main__")
192
193
 
194
+ assert excinfo.value.code == 0
193
195
 
194
- @pytest.mark.script_launch_mode("subprocess")
196
+ captured = capsys.readouterr()
197
+ assert "directory name to unpack into" in captured.out
198
+ assert captured.err == ""
199
+
200
+
201
+ @pytest.mark.script_launch_mode("inprocess")
195
202
  def test_corrupted(script_runner, tmp_path):
196
203
  output_dir = tmp_path / "test"
197
204
  ret = script_runner.run(
@@ -202,6 +209,14 @@ def test_corrupted(script_runner, tmp_path):
202
209
  assert "Index/Metadata.iwa: invalid" in ret.stderr
203
210
  assert ret.stdout == ""
204
211
 
212
+ ret = script_runner.run(
213
+ ["unpack-numbers", "--output", str(output_dir), "tests/data/invalid.numbers"],
214
+ print_result=False,
215
+ )
216
+ assert not ret.success
217
+ assert "invalid Numbers document (missing files)" in ret.stderr
218
+ assert ret.stdout == ""
219
+
205
220
 
206
221
  def test_debug(script_runner, tmp_path):
207
222
  output_dir = tmp_path / "test"