File: test_plugin.py

package info (click to toggle)
sphinxcontrib-bibtex 2.6.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,140 kB
  • sloc: python: 4,668; makefile: 245
file content (63 lines) | stat: -rw-r--r-- 1,704 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import pytest

from sphinxcontrib.bibtex.plugin import find_plugin, register_plugin


def test_plugin_bad_group() -> None:
    with pytest.raises(ImportError, match="plugin group blablabla not found"):
        find_plugin("blablabla", "boo")
    with pytest.raises(ImportError, match="plugin group blablabla not found"):
        register_plugin("blablabla", "boo", type(None))


def test_plugin_register_not_forced() -> None:
    class Plugin:
        pass

    assert not register_plugin(
        "sphinxcontrib.bibtex.style.referencing", "label", Plugin
    )
    assert find_plugin("sphinxcontrib.bibtex.style.referencing", "label") is not Plugin


def test_plugin_register_forced() -> None:
    class PluginOld:
        pass

    class PluginNew:
        pass

    assert register_plugin(
        "sphinxcontrib.bibtex.style.referencing",
        "xxx_test_plugin_register_forced",
        PluginOld,
    )
    assert (
        find_plugin(
            "sphinxcontrib.bibtex.style.referencing", "xxx_test_plugin_register_forced"
        )
        is PluginOld
    )
    assert not register_plugin(
        "sphinxcontrib.bibtex.style.referencing",
        "xxx_test_plugin_register_forced",
        PluginNew,
    )
    assert (
        find_plugin(
            "sphinxcontrib.bibtex.style.referencing", "xxx_test_plugin_register_forced"
        )
        is PluginOld
    )
    assert register_plugin(
        "sphinxcontrib.bibtex.style.referencing",
        "xxx_test_plugin_register_forced",
        PluginNew,
        force=True,
    )
    assert (
        find_plugin(
            "sphinxcontrib.bibtex.style.referencing", "xxx_test_plugin_register_forced"
        )
        is PluginNew
    )