|
4 | 4 |
|
5 | 5 | import pytest |
6 | 6 | from bs4 import BeautifulSoup |
| 7 | +from sphinx.environment import BuildEnvironment |
7 | 8 | from sphinx.testing.util import SphinxTestApp |
8 | 9 |
|
| 10 | +from oembedpy.adapters import sphinx as T |
| 11 | +from oembedpy.types import Link |
| 12 | + |
9 | 13 |
|
10 | 14 | @pytest.fixture(scope="module") |
11 | 15 | def rootdir(): |
@@ -61,3 +65,48 @@ def test_use_caches(app: SphinxTestApp): # noqa |
61 | 65 | @pytest.mark.sphinx("html", testroot="parallel", parallel=2) |
62 | 66 | def test_build_parallel(app: SphinxTestApp, status): # noqa |
63 | 67 | app.build() |
| 68 | + |
| 69 | + |
| 70 | +class TestFor_OembedDomain__merge_domaindata: |
| 71 | + CACHE_KEY = ("http://example.com", 1, 1) |
| 72 | + |
| 73 | + @pytest.mark.sphinx("html", testroot="default") |
| 74 | + def test_difference_items(self, app: SphinxTestApp): |
| 75 | + domain1 = T.OembedDomain(app.env) |
| 76 | + domain1.caches[self.CACHE_KEY] = Link(type="link", version="1.0", _extra={}) |
| 77 | + domain2 = T.OembedDomain(BuildEnvironment(app)) |
| 78 | + domain2.caches[("http://example.com", 1, 2)] = Link( |
| 79 | + type="link", version="1.0", _extra={} |
| 80 | + ) |
| 81 | + domain1.merge_domaindata([], domain2.data) |
| 82 | + assert len(domain1.caches) == 2 |
| 83 | + |
| 84 | + @pytest.mark.sphinx("html", testroot="default") |
| 85 | + def test_keep_main_domain(self, app: SphinxTestApp): |
| 86 | + domain1 = T.OembedDomain(app.env) |
| 87 | + domain1.caches[self.CACHE_KEY] = Link( |
| 88 | + type="link", version="1.0", title="Hello", _extra={} |
| 89 | + ) |
| 90 | + domain2 = T.OembedDomain(BuildEnvironment(app)) |
| 91 | + domain2.caches[self.CACHE_KEY] = Link( |
| 92 | + type="link", version="1.0", title="World", _extra={} |
| 93 | + ) |
| 94 | + print(domain1.caches) |
| 95 | + domain1.merge_domaindata([], domain2.data) |
| 96 | + assert len(domain1.caches) == 1 |
| 97 | + print(domain1.caches) |
| 98 | + assert domain1.caches[self.CACHE_KEY].title == "Hello" |
| 99 | + |
| 100 | + @pytest.mark.sphinx("html", testroot="default") |
| 101 | + def test_keep_overrides(self, app: SphinxTestApp): |
| 102 | + domain1 = T.OembedDomain(app.env) |
| 103 | + link1 = Link(type="link", version="1.0", title="Hello", _extra={}) |
| 104 | + link1._expired = 3600 |
| 105 | + domain1.caches[self.CACHE_KEY] = link1 |
| 106 | + domain2 = T.OembedDomain(BuildEnvironment(app)) |
| 107 | + link2 = Link(type="link", version="1.0", title="World", _extra={}) |
| 108 | + link2._expired = 3601 |
| 109 | + domain2.caches[self.CACHE_KEY] = link2 |
| 110 | + domain1.merge_domaindata([], domain2.data) |
| 111 | + assert len(domain1.caches) == 1 |
| 112 | + assert domain1.caches[("http://example.com", 1, 1)].title == "World" |
0 commit comments