File: test_version.py

package info (click to toggle)
fiona 1.10.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,632 kB
  • sloc: python: 12,616; makefile: 214; sh: 45
file content (71 lines) | stat: -rw-r--r-- 2,366 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
64
65
66
67
68
69
70
71
import fiona
import platform
import re
import os
import sys
from tests.conftest import travis_only
from fiona._env import GDALVersion, get_gdal_release_name


def test_version_tuple():
    version = fiona.gdal_version
    assert version.major >= 1 and isinstance(version.major, int)
    assert version.minor >= 0 and isinstance(version.minor, int)
    assert version.revision >= 0 and isinstance(version.revision, int)


def test_version_comparison():
    # version against version
    assert GDALVersion(4, 0, 0) > GDALVersion(3, 2, 1)
    assert GDALVersion(2, 0, 0) < GDALVersion(3, 2, 1)
    assert GDALVersion(3, 2, 2) > GDALVersion(3, 2, 1)
    assert GDALVersion(3, 2, 0) < GDALVersion(3, 2, 1)

    # tuple against version
    assert (4, 0, 0) > GDALVersion(3, 2, 1)
    assert (2, 0, 0) < GDALVersion(3, 2, 1)
    assert (3, 2, 2) > GDALVersion(3, 2, 1)
    assert (3, 2, 0) < GDALVersion(3, 2, 1)


@travis_only
def test_show_versions(capsys):
    version_pattern = re.compile(r"(\d+).(\d+).(\d+)")

    os_info = f"{platform.system()} {platform.release()}"
    python_version = platform.python_version()
    python_exec = sys.executable

    msg = ("Fiona version: {fiona_version}"
           "\nGDAL version: {gdal_release_name}"
           "\nPROJ version: {proj_version}"
           "\n"
           "\nOS: {os_info}"
           "\nPython: {python_version}"
           "\nPython executable: '{python_exec}'"
           "\n"
           )

    if fiona.gdal_version < GDALVersion(3, 0, 1):
        proj_version = "Proj version not available"
    else:
        proj_version = os.getenv("PROJVERSION")
        proj_version = re.match(version_pattern, proj_version).group(0)

    gdal_version = os.getenv("GDALVERSION")
    if not gdal_version == "master":
        gdal_version = re.match(version_pattern, gdal_version).group(0)
    else:
        gdal_version = get_gdal_release_name()

    msg_formatted = msg.format(fiona_version=fiona.__version__,
                               gdal_release_name=gdal_version,
                               proj_version=proj_version,
                               os_info=os_info,
                               python_version=python_version,
                               python_exec=python_exec)

    fiona.show_versions()
    captured = capsys.readouterr()

    assert captured.out.strip() == msg_formatted.strip()