sampledoc 0.1.0__tar.gz → 0.2.0__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 (35) hide show
  1. {sampledoc-0.1.0 → sampledoc-0.2.0}/CHANGELOG.md +9 -1
  2. {sampledoc-0.1.0 → sampledoc-0.2.0}/PKG-INFO +19 -1
  3. {sampledoc-0.1.0 → sampledoc-0.2.0}/README.md +18 -0
  4. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/__init__.py +1 -1
  5. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/odf.py +28 -2
  6. {sampledoc-0.1.0 → sampledoc-0.2.0}/tests/golden.json +15 -15
  7. {sampledoc-0.1.0 → sampledoc-0.2.0}/tests/test_samples.py +21 -0
  8. {sampledoc-0.1.0 → sampledoc-0.2.0}/.gitignore +0 -0
  9. {sampledoc-0.1.0 → sampledoc-0.2.0}/LICENSE +0 -0
  10. {sampledoc-0.1.0 → sampledoc-0.2.0}/pyproject.toml +0 -0
  11. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/__main__.py +0 -0
  12. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/_language.py +0 -0
  13. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/_table.py +0 -0
  14. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/cli.py +0 -0
  15. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/languages/cs.json +0 -0
  16. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/languages/de.json +0 -0
  17. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/languages/en.json +0 -0
  18. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/languages/es.json +0 -0
  19. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/languages/et.json +0 -0
  20. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/languages/fr.json +0 -0
  21. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/languages/hi.json +0 -0
  22. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/languages/it.json +0 -0
  23. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/languages/ja.json +0 -0
  24. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/languages/pl.json +0 -0
  25. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/languages/pt-BR.json +0 -0
  26. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/languages/ru.json +0 -0
  27. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/languages/sv.json +0 -0
  28. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/languages/tr.json +0 -0
  29. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/languages/zh.json +0 -0
  30. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/names.py +0 -0
  31. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/ooxml.py +0 -0
  32. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/pdf.py +0 -0
  33. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/plain.py +0 -0
  34. {sampledoc-0.1.0 → sampledoc-0.2.0}/src/sampledoc/py.typed +0 -0
  35. {sampledoc-0.1.0 → sampledoc-0.2.0}/tests/fingerprint.py +0 -0
@@ -7,6 +7,13 @@ generated sample is listed, because it changes every screenshot taken of it.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.2.0] - 2026-12-06
11
+
12
+ ### Changed
13
+
14
+ - The budget's totals are formulas, so editing a figure updates them. They
15
+ show the same numbers as before.
16
+
10
17
  ## [0.1.0] - 2026-11-14
11
18
 
12
19
  First release, extracted from the `make-screenshot-documents.py` scripts of
@@ -33,5 +40,6 @@ OpenDocument.droid and OpenDocument.ios.
33
40
  - `screenshot-names.json` now always nests languages under `"languages"` (the
34
41
  Android layout). The iOS script wrote them at the top level.
35
42
 
36
- [Unreleased]: https://github.com/opendocument-app/sampledoc/compare/v0.1.0...HEAD
43
+ [Unreleased]: https://github.com/opendocument-app/sampledoc/compare/v0.2.0...HEAD
44
+ [0.2.0]: https://github.com/opendocument-app/sampledoc/compare/v0.1.0...v0.2.0
37
45
  [0.1.0]: https://github.com/opendocument-app/sampledoc/releases/tag/v0.1.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: sampledoc
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Small, localized, byte-for-byte reproducible sample office documents (ODF, OOXML, PDF, CSV, TXT).
5
5
  Project-URL: Homepage, https://opendocument.app/
6
6
  Project-URL: Source, https://github.com/opendocument-app/sampledoc
@@ -46,6 +46,24 @@ It was built to give app-store screenshots of
46
46
  in the language of each store listing, and is just as useful as test fixtures
47
47
  for anything that opens office files.
48
48
 
49
+ <table>
50
+ <tr>
51
+ <td align="center"><img src="https://raw.githubusercontent.com/opendocument-app/sampledoc/main/docs/images/sample-text-en.png" width="200" alt="The quarterly report, sample-text-en.odt"></td>
52
+ <td align="center"><img src="https://raw.githubusercontent.com/opendocument-app/sampledoc/main/docs/images/sample-sheet-en.png" width="200" alt="The budget spreadsheet, sample-sheet-en.ods"></td>
53
+ <td align="center"><img src="https://raw.githubusercontent.com/opendocument-app/sampledoc/main/docs/images/sample-word-de.png" width="200" alt="The service agreement in German, sample-word-de.docx"></td>
54
+ <td align="center"><img src="https://raw.githubusercontent.com/opendocument-app/sampledoc/main/docs/images/sample-paper-en.png" width="200" alt="The invoice, sample-paper-en.pdf"></td>
55
+ </tr>
56
+ <tr>
57
+ <td align="center"><code>sample-text-en.odt</code></td>
58
+ <td align="center"><code>sample-sheet-en.ods</code></td>
59
+ <td align="center"><code>sample-word-de.docx</code></td>
60
+ <td align="center"><code>sample-paper-en.pdf</code></td>
61
+ </tr>
62
+ </table>
63
+
64
+ <sub>First pages as rendered by LibreOffice. Regenerate with
65
+ <code>scripts/render-readme-images.sh</code>.</sub>
66
+
49
67
  ## Install
50
68
 
51
69
  ```sh
@@ -17,6 +17,24 @@ It was built to give app-store screenshots of
17
17
  in the language of each store listing, and is just as useful as test fixtures
18
18
  for anything that opens office files.
19
19
 
20
+ <table>
21
+ <tr>
22
+ <td align="center"><img src="https://raw.githubusercontent.com/opendocument-app/sampledoc/main/docs/images/sample-text-en.png" width="200" alt="The quarterly report, sample-text-en.odt"></td>
23
+ <td align="center"><img src="https://raw.githubusercontent.com/opendocument-app/sampledoc/main/docs/images/sample-sheet-en.png" width="200" alt="The budget spreadsheet, sample-sheet-en.ods"></td>
24
+ <td align="center"><img src="https://raw.githubusercontent.com/opendocument-app/sampledoc/main/docs/images/sample-word-de.png" width="200" alt="The service agreement in German, sample-word-de.docx"></td>
25
+ <td align="center"><img src="https://raw.githubusercontent.com/opendocument-app/sampledoc/main/docs/images/sample-paper-en.png" width="200" alt="The invoice, sample-paper-en.pdf"></td>
26
+ </tr>
27
+ <tr>
28
+ <td align="center"><code>sample-text-en.odt</code></td>
29
+ <td align="center"><code>sample-sheet-en.ods</code></td>
30
+ <td align="center"><code>sample-word-de.docx</code></td>
31
+ <td align="center"><code>sample-paper-en.pdf</code></td>
32
+ </tr>
33
+ </table>
34
+
35
+ <sub>First pages as rendered by LibreOffice. Regenerate with
36
+ <code>scripts/render-readme-images.sh</code>.</sub>
37
+
20
38
  ## Install
21
39
 
22
40
  ```sh
@@ -30,7 +30,7 @@ __all__ = [
30
30
  "query",
31
31
  ]
32
32
 
33
- __version__ = "0.1.0"
33
+ __version__ = "0.2.0"
34
34
 
35
35
 
36
36
  class Sample(NamedTuple):
@@ -6,6 +6,8 @@ from xml.sax.saxutils import escape
6
6
 
7
7
  from ._table import ACCENT, RULE, table, zipped
8
8
 
9
+ COLUMNS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
10
+
9
11
  NAMESPACES = " ".join(
10
12
  [
11
13
  'xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"',
@@ -86,6 +88,15 @@ def paragraph_style(
86
88
  </style:style>"""
87
89
 
88
90
 
91
+ class Sum(int):
92
+ """A total the sheet computes: SUM over a range, cached as the figure it adds up to."""
93
+
94
+ def __new__(cls, value: int, cells: str):
95
+ total = super().__new__(cls, value)
96
+ total.cells = cells
97
+ return total
98
+
99
+
89
100
  def odf_row(cells: list, style: str | None = None) -> str:
90
101
  """One row of an ODF table, as the report and the sheet both write it.
91
102
 
@@ -95,7 +106,13 @@ def odf_row(cells: list, style: str | None = None) -> str:
95
106
  marked = f' table:style-name="{style}"' if style else ""
96
107
  out = [" <table:table-row>"]
97
108
  for cell in cells:
98
- if isinstance(cell, int):
109
+ if isinstance(cell, Sum):
110
+ out.append(
111
+ f' <table:table-cell{marked} table:formula="of:=SUM([.{cell.cells}])"'
112
+ f' office:value-type="float" office:value="{cell}">'
113
+ f"<text:p>{cell}</text:p></table:table-cell>"
114
+ )
115
+ elif isinstance(cell, int):
99
116
  out.append(
100
117
  f' <table:table-cell{marked} office:value-type="float" office:value="{cell}">'
101
118
  f"<text:p>{cell}</text:p></table:table-cell>"
@@ -196,9 +213,18 @@ def sheet(words: dict) -> str:
196
213
 
197
214
  head, body, foot = table(words, columns=6)
198
215
 
216
+ # the totals are formulas, so an edit above them moves them; the cached values
217
+ # are the figures they always showed
218
+ last = COLUMNS[len(head) - 2]
219
+ body = [line[:-1] + [Sum(line[-1], f"B{row}:.{last}{row}")] for row, line in enumerate(body, 2)]
220
+ end = len(body) + 1
221
+ foot = [foot[0]] + [
222
+ Sum(value, f"{COLUMNS[at]}2:.{COLUMNS[at]}{end}") for at, value in enumerate(foot[1:], 1)
223
+ ]
224
+
199
225
  overview = [odf_row(head, "ceHead")] + [odf_row(line) for line in body] + [odf_row(foot, "ceTotal")]
200
226
  costs = [odf_row([words["item"], words["total"]], "ceHead")]
201
- costs += [odf_row([line[0], line[-1]]) for line in body]
227
+ costs += [odf_row([line[0], int(line[-1])]) for line in body]
202
228
 
203
229
  tables = []
204
230
  for name, rows, columns in (
@@ -74,21 +74,21 @@
74
74
  "sample-rows-sv.csv": "f86a4a55f29f801eafb60a81e1502d15316e33c72eba29151076d60a73612b51",
75
75
  "sample-rows-tr.csv": "48ed712cdd4c730b0c4db72166efb0431ccdc1e7690b301f87e14d04fa4c3615",
76
76
  "sample-rows-zh.csv": "0ffdd92a3057d99ec203e26e6c4dbd8e26be7fc225ede043ace7b9b90909e716",
77
- "sample-sheet-cs.ods": "zip:811436aecba605790d9c67e17951229ca5c97870f64df87fbc9d50393b9a86aa",
78
- "sample-sheet-de.ods": "zip:72f7532a19693484ef1253afae9e448909201b15937ad6447f2c8757a5c4e944",
79
- "sample-sheet-en.ods": "zip:c99bdd6b20e000be2a2cc7fab3eadd10ed7d4bebcd2678ebf85c385692adc7c9",
80
- "sample-sheet-es.ods": "zip:0cff47892184f25aa5087f48aeb089845c321c7aaf821d20c9c52a7edfb01825",
81
- "sample-sheet-et.ods": "zip:b0140db46348814a09a581660a1a74af6374848da9bc6e89d49d6175e2dd8a85",
82
- "sample-sheet-fr.ods": "zip:84714ead30f4829485b90c23d5cbfcc03866c0be2933267e13eb46920e822426",
83
- "sample-sheet-hi.ods": "zip:0e7537d9df12f120365616530ee0508f641774e47567f4ff2882ec42d31f9397",
84
- "sample-sheet-it.ods": "zip:1a04ef1fa45087a690d3c8af9e60023095777c0487748cdd0d8cfcb2c015ff84",
85
- "sample-sheet-ja.ods": "zip:eb16b885ac96d139b9d9b842f49b2cc50ea41eac5351139f512cdcbebbf788ca",
86
- "sample-sheet-pl.ods": "zip:e921a54b3b6f7b75353189fb23a1d9df9e2330b20620c8ed439e27884c5e698c",
87
- "sample-sheet-pt-BR.ods": "zip:f90c0a3cb311b70fba2f095fde68b81e805f4935a4b267cb2c7e87fe633d41e3",
88
- "sample-sheet-ru.ods": "zip:d6cfe7c2065aa77bd708032a3c177bd78909f89f4e28cde9d87f4284c7509950",
89
- "sample-sheet-sv.ods": "zip:4f1ea9609ccd4ff647aaaf9da2fec590e7fcd0c93992fb03ed2a98d83c8446d0",
90
- "sample-sheet-tr.ods": "zip:93e720eb72030e76ff852984e31c3366dd98dcb70654656f2018275e07d5a716",
91
- "sample-sheet-zh.ods": "zip:f68c4bf2e391070d41513c54df56ed6849147fce0100b5f13084cef106cef4a2",
77
+ "sample-sheet-cs.ods": "zip:9994be44567c16ded329105f13cfb961d54c70e835f3d43114644b429c314e17",
78
+ "sample-sheet-de.ods": "zip:2ac0e901e97e50f08c1f80408ea67dc8c0d0dedbfddcca54a57a9fffdb7d0fb7",
79
+ "sample-sheet-en.ods": "zip:65f7262c992ac5dcd8e51ad8e8d0f7174fd4c54e49d80014356671894c363410",
80
+ "sample-sheet-es.ods": "zip:62ee81b4e9af14af7dc630bd8110af3c691d241b1243bfbca497344a4f6c0a8f",
81
+ "sample-sheet-et.ods": "zip:788e81c83fd80c0ab9b22e3137257ab2996bae7caaf9971e91152a6b673c7ff9",
82
+ "sample-sheet-fr.ods": "zip:b88f75ae2d654ea72ec48ab505710fb3965a4e896cdc3489ff9821bb55d08ef4",
83
+ "sample-sheet-hi.ods": "zip:52caa0fd3b5899d15ea0a69a13e112dcea0bdfe9e5326f7de466e2df4135fd8d",
84
+ "sample-sheet-it.ods": "zip:8048c84e04057fe38fcad4cf1def3fa54b70b59750ce9917fcfa993729f6faaa",
85
+ "sample-sheet-ja.ods": "zip:93f36c37fe07d78856d9931ec3f76ba844dc1ee8c0543d4b22a7ff1dc8c8247d",
86
+ "sample-sheet-pl.ods": "zip:b8500a170524d52d40bf5b9f6db08324fd01dcb1ebff2ae99432b19718ad5501",
87
+ "sample-sheet-pt-BR.ods": "zip:9bbf0cdfe749e0b8a7620b72563fa74b45123a50a11a0714c52568ced2d5fee5",
88
+ "sample-sheet-ru.ods": "zip:edc07822de2d469c2e2f1c24f1485501522a2b95e9d299cf7e6c6cbd812f15dc",
89
+ "sample-sheet-sv.ods": "zip:20802bfdab26bac68cfb43156a693033b560839aab54419803d97dd253e0f73b",
90
+ "sample-sheet-tr.ods": "zip:235ec058cfee51afcf123c28dc3520b2cb3aa7ea37fc71739bb07f110e9239c0",
91
+ "sample-sheet-zh.ods": "zip:dfb0dd84c2e539795e3fdcb316858a048b3e0038c7f4a8071e6fb7a62ea5e26c",
92
92
  "sample-slides-cs.odp": "zip:bb0967ae58b16ca73928bfe5bc5ebfe8346f3b9794a1eb057357252412768ea3",
93
93
  "sample-slides-de.odp": "zip:5d37a74eae5e6f3fe01f1e80e4ad4d04d2f0165aafd4c683d8691d134c4dfe6a",
94
94
  "sample-slides-en.odp": "zip:3b20fd96c7eb282c6937fa29c0fdca5442aa576b23ba843deb0ab30c8bf9c842",
@@ -56,6 +56,27 @@ def test_odf_package(sample, language):
56
56
  ElementTree.fromstring(archive.read(name))
57
57
 
58
58
 
59
+ def test_sheet_totals_are_sums_of_what_they_show():
60
+ """The budget's totals are formulas, cached as the figures they add up to."""
61
+ table = "{urn:oasis:names:tc:opendocument:xmlns:table:1.0}"
62
+ office = "{urn:oasis:names:tc:opendocument:xmlns:office:1.0}"
63
+ with zipfile.ZipFile(io.BytesIO(document("sheet", "en"))) as archive:
64
+ overview, costs = ElementTree.fromstring(archive.read("content.xml")).iter(f"{table}table")
65
+
66
+ grid = [
67
+ [(cell.get(f"{table}formula"), cell.get(f"{office}value")) for cell in row.iter(f"{table}table-cell")]
68
+ for row in overview.iter(f"{table}table-row")
69
+ ]
70
+ value = lambda column, row: float(grid[row - 1][column][1]) # noqa: E731
71
+ for row in range(2, len(grid)):
72
+ assert grid[row - 1][-1][0] == f"of:=SUM([.B{row}:.G{row}])"
73
+ assert value(7, row) == sum(value(column, row) for column in range(1, 7))
74
+ for column, letter in enumerate("BCDEFGH", 1):
75
+ assert grid[-1][column][0] == f"of:=SUM([.{letter}2:.{letter}{len(grid) - 1}])"
76
+ assert value(column, len(grid)) == sum(value(column, row) for row in range(2, len(grid)))
77
+ assert not any(cell.get(f"{table}formula") for cell in costs.iter(f"{table}table-cell"))
78
+
79
+
59
80
  @pytest.mark.parametrize("language", languages())
60
81
  @pytest.mark.parametrize("sample", ["word", "cells", "deck"])
61
82
  def test_ooxml_package(sample, language):
File without changes
File without changes
File without changes