1################################################################ 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance 9# with the License. You may obtain a copy of the License at 10# 11# http://www.apache.org/licenses/LICENSE-2.0 12# 13# Unless required by applicable law or agreed to in writing, 14# software distributed under the License is distributed on an 15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16# KIND, either express or implied. See the License for the 17# specific language governing permissions and limitations 18# under the License. 19 20"""aootest.odfversion: the declared versions of a package, and which packages are formula documents.""" 21import zipfile 22 23import pytest 24 25from aootest import odfversion 26 27pytestmark = pytest.mark.selftest 28 29MANIFEST = '<manifest:manifest xmlns:manifest="x" manifest:version="1.2"/>' 30 31 32def package(path, mimetype, content): 33 with zipfile.ZipFile(path, "w") as z: 34 z.writestr("mimetype", mimetype) 35 z.writestr("content.xml", content) 36 z.writestr("META-INF/manifest.xml", MANIFEST) 37 return str(path) 38 39 40def test_a_text_document_declares_its_version_in_content_and_manifest(tmp_path): 41 p = package(tmp_path / "a.odt", "application/vnd.oasis.opendocument.text", '<office:document-content office:version="1.2"/>') 42 assert odfversion.odf_versions(p) == ("1.2", "1.2") 43 assert not odfversion.is_formula(p) 44 45 46def test_a_formula_document_has_a_mathml_root_without_a_version(tmp_path): 47 p = package(tmp_path / "a.odf", "application/vnd.oasis.opendocument.formula", '<math xmlns="http://www.w3.org/1998/Math/MathML"/>') 48 assert odfversion.odf_versions(p) == (None, "1.2") 49 assert odfversion.is_formula(p) 50