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"""Import twins (see aootest.twins): documents saved as ODF 1.2 and as ODF 1.3 from the same source by another producer, in the 21plain and the extended flavour. Every document must load, and the two members of a pair must import alike. Two controls show 22that the comparison can fail: an unchanged copy compares equal and a copy with one word changed compares different. 23 24Needs a corpus (--twin-corpus or AOO_TWIN_CORPUS); without one the items skip. Differences that are understood are rows 25in data/expect/twins.tsv.""" 26import os 27 28import pytest 29 30from aootest import twins 31 32pytestmark = pytest.mark.slow 33 34 35def _root(config): 36 return config.getoption("--twin-corpus") or os.environ.get("AOO_TWIN_CORPUS") 37 38 39def pytest_generate_tests(metafunc): 40 root = _root(metafunc.config) 41 usable = root and twins.corpus_problem(root) is None 42 names = twins.document_names(root) if usable else ["-"] 43 if "name" in metafunc.fixturenames: 44 if "pair" in metafunc.fixturenames: 45 params = [(p, n) for p in twins.PAIRS for n in names] 46 ids = ["%s-%s|%s" % (p[0], p[1], n) for p, n in params] 47 metafunc.parametrize("pair,name", params, ids=ids) 48 elif "mode" in metafunc.fixturenames: 49 params = [(m, n) for m in twins.MODES for n in names] 50 metafunc.parametrize("mode,name", params, ids=["%s|%s" % x for x in params]) 51 52 53def test_document_loads(twin_run, mode, name): 54 d = twin_run.load(mode, name) 55 assert not d.get("error") and not d.get("body_error"), d.get("error") or d.get("body_error") 56 57 58def test_twins_import_alike(twin_run, pair, name): 59 r = twin_run.diff(pair)[name] 60 assert r["ndiff"] == 0, "%d paths differ, first: %s" % (r["ndiff"], r["diffs"][0][:3]) 61 62 63def test_control_unchanged_copy_compares_equal(twin_run): 64 res, what = twin_run.controls() 65 assert res is not None, what 66 assert res["same"] == 0, "an unchanged copy of %s compares different (%d paths)" % (what, res["same"]) 67 68 69def test_control_changed_word_compares_different(twin_run): 70 res, what = twin_run.controls() 71 assert res is not None, what 72 assert res["mutated"] > 0, "a copy of %s with a changed word compares equal: the comparison cannot fail" % what 73