plugin_info_test.py 1.43 KB
Newer Older
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 64 65 66
import sys

import pytest
from io import StringIO
from pathlib import Path
from errbot.plugin_info import PluginInfo

plugfile_base = Path(__file__).absolute().parent / 'config_plugin'
plugfile_path = plugfile_base / 'config.plug'


def test_load_from_plugfile_path():
    pi = PluginInfo.load(plugfile_path)
    assert pi.name == 'Config'
    assert pi.module == 'config'
    assert pi.doc is None
    assert pi.python_version == (3, 0, 0)
    assert pi.errbot_minversion is None
    assert pi.errbot_maxversion is None


@pytest.mark.parametrize('test_input,expected', [
    ('2', (2, 0, 0)),
    ('2+', (3, 0, 0)),
    ('3', (3, 0, 0)),
    ('1.2.3', (1, 2, 3)),
    ('1.2.3-beta', (1, 2, 3)),
])
def test_python_version_parse(test_input, expected):
    f = StringIO("""
    [Core]
    Name = Config
    Module = config

    [Python]
    Version = %s
    """ % test_input)

    assert PluginInfo.load_file(f, None).python_version == expected


def test_doc():
    f = StringIO("""
    [Core]
    Name = Config
    Module = config

    [Documentation]
    Description = something
    """)

    assert PluginInfo.load_file(f, None).doc == 'something'


def test_errbot_version():
    f = StringIO("""
    [Core]
    Name = Config
    Module = config
    [Errbot]
    Min = 1.2.3
    Max = 4.5.6-beta
    """)
    info = PluginInfo.load_file(f, None)
    assert info.errbot_minversion == (1, 2, 3, sys.maxsize)
    assert info.errbot_maxversion == (4, 5, 6, 0)