summaryrefslogtreecommitdiff
path: root/test/test_version.py
blob: 08bebe1ca2558abdfcf02280aa6f9c62adda4f88 (plain)
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
"""Test version"""

import re
import pytest


@pytest.fixture(scope='module')
def expected_version(yadm):
    """
    Expected semantic version number. This is taken directly out of yadm,
    searching for the VERSION= string.
    """
    yadm_version = re.findall(
        r'VERSION=([^\n]+)',
        open(yadm).read())
    if yadm_version:
        return yadm_version[0]
    pytest.fail(f'version not found in {yadm}')
    return 'not found'


def test_semantic_version(expected_version):
    """Version is semantic"""
    # semantic version conforms to MAJOR.MINOR.PATCH
    assert re.search(r'^\d+\.\d+\.\d+$', expected_version), (
        'does not conform to MAJOR.MINOR.PATCH')


@pytest.mark.parametrize('cmd', ['--version', 'version'])
def test_reported_version(
        runner, yadm_cmd, cmd, expected_version):
    """Report correct version"""
    run = runner(command=yadm_cmd(cmd))
    assert run.success
    assert run.err == ''
    assert run.out == f'yadm {expected_version}\n'