xref: /trunk/test/aoo-test/tests/odf/test_twins.py (revision 2cb6d6f119bbe2f78742f1c5c8538cb0d4e72ede)
1*2cb6d6f1SJim Jagielski################################################################
2*2cb6d6f1SJim Jagielski#
3*2cb6d6f1SJim Jagielski#  Licensed to the Apache Software Foundation (ASF) under one
4*2cb6d6f1SJim Jagielski#  or more contributor license agreements.  See the NOTICE file
5*2cb6d6f1SJim Jagielski#  distributed with this work for additional information
6*2cb6d6f1SJim Jagielski#  regarding copyright ownership.  The ASF licenses this file
7*2cb6d6f1SJim Jagielski#  to you under the Apache License, Version 2.0 (the
8*2cb6d6f1SJim Jagielski#  "License"); you may not use this file except in compliance
9*2cb6d6f1SJim Jagielski#  with the License.  You may obtain a copy of the License at
10*2cb6d6f1SJim Jagielski#
11*2cb6d6f1SJim Jagielski#    http://www.apache.org/licenses/LICENSE-2.0
12*2cb6d6f1SJim Jagielski#
13*2cb6d6f1SJim Jagielski#  Unless required by applicable law or agreed to in writing,
14*2cb6d6f1SJim Jagielski#  software distributed under the License is distributed on an
15*2cb6d6f1SJim Jagielski#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2cb6d6f1SJim Jagielski#  KIND, either express or implied.  See the License for the
17*2cb6d6f1SJim Jagielski#  specific language governing permissions and limitations
18*2cb6d6f1SJim Jagielski#  under the License.
19*2cb6d6f1SJim Jagielski
20*2cb6d6f1SJim Jagielski"""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
21*2cb6d6f1SJim Jagielskiplain and the extended flavour. Every document must load, and the two members of a pair must import alike. Two controls show
22*2cb6d6f1SJim Jagielskithat the comparison can fail: an unchanged copy compares equal and a copy with one word changed compares different.
23*2cb6d6f1SJim Jagielski
24*2cb6d6f1SJim JagielskiNeeds a corpus (--twin-corpus or AOO_TWIN_CORPUS); without one the items skip. Differences that are understood are rows
25*2cb6d6f1SJim Jagielskiin data/expect/twins.tsv."""
26*2cb6d6f1SJim Jagielskiimport os
27*2cb6d6f1SJim Jagielski
28*2cb6d6f1SJim Jagielskiimport pytest
29*2cb6d6f1SJim Jagielski
30*2cb6d6f1SJim Jagielskifrom aootest import twins
31*2cb6d6f1SJim Jagielski
32*2cb6d6f1SJim Jagielskipytestmark = pytest.mark.slow
33*2cb6d6f1SJim Jagielski
34*2cb6d6f1SJim Jagielski
35*2cb6d6f1SJim Jagielskidef _root(config):
36*2cb6d6f1SJim Jagielski    return config.getoption("--twin-corpus") or os.environ.get("AOO_TWIN_CORPUS")
37*2cb6d6f1SJim Jagielski
38*2cb6d6f1SJim Jagielski
39*2cb6d6f1SJim Jagielskidef pytest_generate_tests(metafunc):
40*2cb6d6f1SJim Jagielski    root = _root(metafunc.config)
41*2cb6d6f1SJim Jagielski    usable = root and twins.corpus_problem(root) is None
42*2cb6d6f1SJim Jagielski    names = twins.document_names(root) if usable else ["-"]
43*2cb6d6f1SJim Jagielski    if "name" in metafunc.fixturenames:
44*2cb6d6f1SJim Jagielski        if "pair" in metafunc.fixturenames:
45*2cb6d6f1SJim Jagielski            params = [(p, n) for p in twins.PAIRS for n in names]
46*2cb6d6f1SJim Jagielski            ids = ["%s-%s|%s" % (p[0], p[1], n) for p, n in params]
47*2cb6d6f1SJim Jagielski            metafunc.parametrize("pair,name", params, ids=ids)
48*2cb6d6f1SJim Jagielski        elif "mode" in metafunc.fixturenames:
49*2cb6d6f1SJim Jagielski            params = [(m, n) for m in twins.MODES for n in names]
50*2cb6d6f1SJim Jagielski            metafunc.parametrize("mode,name", params, ids=["%s|%s" % x for x in params])
51*2cb6d6f1SJim Jagielski
52*2cb6d6f1SJim Jagielski
53*2cb6d6f1SJim Jagielskidef test_document_loads(twin_run, mode, name):
54*2cb6d6f1SJim Jagielski    d = twin_run.load(mode, name)
55*2cb6d6f1SJim Jagielski    assert not d.get("error") and not d.get("body_error"), d.get("error") or d.get("body_error")
56*2cb6d6f1SJim Jagielski
57*2cb6d6f1SJim Jagielski
58*2cb6d6f1SJim Jagielskidef test_twins_import_alike(twin_run, pair, name):
59*2cb6d6f1SJim Jagielski    r = twin_run.diff(pair)[name]
60*2cb6d6f1SJim Jagielski    assert r["ndiff"] == 0, "%d paths differ, first: %s" % (r["ndiff"], r["diffs"][0][:3])
61*2cb6d6f1SJim Jagielski
62*2cb6d6f1SJim Jagielski
63*2cb6d6f1SJim Jagielskidef test_control_unchanged_copy_compares_equal(twin_run):
64*2cb6d6f1SJim Jagielski    res, what = twin_run.controls()
65*2cb6d6f1SJim Jagielski    assert res is not None, what
66*2cb6d6f1SJim Jagielski    assert res["same"] == 0, "an unchanged copy of %s compares different (%d paths)" % (what, res["same"])
67*2cb6d6f1SJim Jagielski
68*2cb6d6f1SJim Jagielski
69*2cb6d6f1SJim Jagielskidef test_control_changed_word_compares_different(twin_run):
70*2cb6d6f1SJim Jagielski    res, what = twin_run.controls()
71*2cb6d6f1SJim Jagielski    assert res is not None, what
72*2cb6d6f1SJim Jagielski    assert res["mutated"] > 0, "a copy of %s with a changed word compares equal: the comparison cannot fail" % what
73