Пример #1
0
def test_major_minor_version():
    version = Version(49, 52)
    assert version.major == 49
    assert version.minor == 52
    assert version.patch is None
    assert version.prerelease is None
    assert version.build is None
Пример #2
0
def test_define_basic_version():
    version = Version(1, 0, 2)
    assert version.major == 1
    assert version.minor == 0
    assert version.patch == 2
    assert version.prerelease is None
    assert version.build is None
Пример #3
0
def test_full_version():
    version = Version(49, 52, 0, "rc.5", "eg5f6d")
    assert version.major == 49
    assert version.minor == 52
    assert version.patch == 0
    assert version.prerelease == "rc.5"
    assert version.build == "eg5f6d"
Пример #4
0
def test_major_version():
    version = Version(10)
    assert version.major == 10
    assert version.minor is None
    assert version.patch is None
    assert version.prerelease is None
    assert version.build is None
Пример #5
0
def test_compare_version_with_major_minor():
    version = Version(1, 0)
    assert version > (0, 1)
    assert version < (1, 1)
    #  assert version == (1, 0)
    assert version != (1, 0, 0)
    assert version < (2, )
    assert version > (0, )
    assert version > (0, 1, 10, "rc2", "build-455")
Пример #6
0
JAVA_13_J9 = (
    b'openjdk version "13.0.1" 2019-10-15\n'
    b"OpenJDK Runtime Environment AdoptOpenJDK (build 13.0.1+9)\n"
    b"Eclipse OpenJ9 VM AdoptOpenJDK (build openj9-0.17.0, JRE 13 Linux amd64-64-Bit "
    b"Compressed References 20191021_96 (JIT enabled, AOT enabled)\n"
    b"OpenJ9   - 77c1cf708\n"
    b"OMR      - 20db4fbc\n"
    b"JCL      - 74a8738189 based on jdk-13.0.1+9)\n")

JAVA_14_PRE = (
    b'openjdk version "14-ea" 2020-03-17\n'
    b"OpenJDK Runtime Environment (build 14-ea+20-879)\n"
    b"OpenJDK 64-Bit Server VM (build 14-ea+20-879, mixed mode, sharing)")

JAVA_PARAMETERS = [
    pytest.param(JAVA_5, "1.5.0_29", Version(1, 5, 29)),
    pytest.param(JAVA_6, "1.6.0-119", Version(1, 6, 0,
                                              "119")),  # wrong parsing here
    pytest.param(JAVA_7, "1.7.0_55", Version(1, 7, 55)),
    pytest.param(JAVA_8, "1.8.0_151", Version(1, 8, 151)),
    pytest.param(JAVA_11, "11.0.5", Version(11, 0, 5)),
    pytest.param(JAVA_12, "12.0.2", Version(12, 0, 2)),
    pytest.param(JAVA_13_J9, "13.0.1", Version(13, 0, 1)),
    pytest.param(JAVA_14_PRE, "14-ea", Version(14, None, None, "ea", None)),
]

JAVA_HOME = Path.home() / "java"


class TestJava(BasicMockedPopen):
    """Test the Java version"""
Пример #7
0
"""Test the semver parser."""

import pytest

from universions import Version, parse_semver
from universions.error import InvalidVersionFormatError


@pytest.mark.parametrize(
    "version, expected",
    [
        ("1.0.0", Version(1, 0, 0)),
        (
            "1.2.3-alpha.1.2+build.11.e0f985a",
            Version(1, 2, 3, "alpha.1.2", "build.11.e0f985a"),
        ),
        ("3.4.5-pre.2+build.4", Version(3, 4, 5, "pre.2", "build.4")),
    ],
)
def test_default_semver_parser(version, expected):
    """Test parsefull version."""
    assert parse_semver(version) == expected


@pytest.mark.parametrize("version", ["1", "1.2", "v1.0.0"])
def test_default_semver_parser_failing_cases(version):
    """Test default sermver parser fails for invalid version."""
    with pytest.raises(InvalidVersionFormatError):
        parse_semver(version)

Пример #8
0
PY_2_5_1 = b"Python 2.5.1"
PY_2_7_17 = b"Python 2.7.17rc1"
PY_3_0 = b"Python 3.0"
PY_3_6_9 = b"Python 3.6.9"
PY_3_7_5 = b"Python 3.7.5rc1"
PY_3_8_0 = b"Python 3.8.0b2+"
PY_3_9_DEV = b"Python 3.9.0a0"

PYPY_3_6_9 = (
    b"Python 3.6.9 (5da45ced70e515f94686be0df47c59abd1348ebc, Oct 17 2019, 22:59:56)\n"
    b"[PyPy 7.2.0 with GCC 8.2.0]")

JYTHON = b"Jython 2.5.4rc1"

VERSIONS = [
    pytest.param(PY_2_5_1, Version(2, 5, 1)),
    pytest.param(PY_2_7_17, Version(2, 7, 17, "rc1")),
    pytest.param(PY_3_0, Version(3, 0, 0)),
    pytest.param(PY_3_6_9, Version(3, 6, 9)),
    pytest.param(PY_3_7_5, Version(3, 7, 5, "rc1")),
    pytest.param(PY_3_8_0, Version(3, 8, 0, "b2+")),
    pytest.param(PY_3_9_DEV, Version(3, 9, 0, "a0")),
    pytest.param(PYPY_3_6_9, Version(3, 6, 9)),
    pytest.param(JYTHON, Version(2, 5, 4, "rc1")),
]


class TestPython(BasicMockedPopen):
    """Test the Python version."""
    @pytest.mark.parametrize("command,version", VERSIONS)
    def test_default_python_version(self, command: bytes, version: Version):
Пример #9
0
import pytest

from universions import Version
from universions.node import get_node_version

from .mock_popen import BasicMockedPopen

ARGON = b"v4.9.1\n"
BORON = b"v6.17.1\n"
CARBON = b"v8.16.2\n"
DUBNIUM = b"v10.17.0\n"
ERBIUM = b"v12.13.0\n"

VERSIONS = [
    pytest.param(ARGON, Version(4, 9, 1)),
    pytest.param(BORON, Version(6, 17, 1)),
    pytest.param(CARBON, Version(8, 16, 2)),
    pytest.param(DUBNIUM, Version(10, 17, 0)),
    pytest.param(ERBIUM, Version(12, 13, 0)),
]


class TestNode(BasicMockedPopen):
    """Test the node version."""
    @pytest.mark.parametrize("command,version", VERSIONS)
    def test_default_node_version(self, command: bytes, version: Version):
        """Test that the correct version is returned."""
        self.popen.set_command("node --version", stderr=command)
        assert get_node_version() == version
Пример #10
0
from pathlib import Path

import pytest

from universions import Version
from universions.pip import get_pip_version

from .mock_popen import BasicMockedPopen

PIP_19_3_1 = b"pip 19.3.1 from /path/python3.7/site-packages/pip (python 3.7)"
PIP_10_0_0B2 = b"pip 10.0.0b2 from /path/lib/python2.7/site-packages/pip (python 2.7)"
PIP_18_1 = b"pip 18.1 from /path/lib/python3.6/site-packages/pip (python 3.6)"

VERSIONS = [
    pytest.param(PIP_19_3_1, Version(19, 3, 1)),
    pytest.param(PIP_10_0_0B2, Version(10, 0, 0, "b2")),
    pytest.param(PIP_18_1, Version(18, 1, 0)),
]


class TestPip(BasicMockedPopen):
    """Test the Pip version."""

    @pytest.mark.parametrize("command,version", VERSIONS)
    def test_default_pip_version(self, command: bytes, version: Version):
        """Test that the correct version is returned."""
        self.popen.set_command("pip --version", stderr=command)
        assert get_pip_version() == version

    @pytest.mark.parametrize("command,version", VERSIONS)
Пример #11
0
 def test_with_custom_path(self):
     """Tests that if accepts a custom path to git binary."""
     git_path = Path.home() / "super_git" / "git.bin"
     self.popen.set_command(f"{git_path} --version", stdout=UNIX_GIT)
     assert get_git_version(git_path=git_path) == Version(2, 23, 0)
Пример #12
0
import pytest

from universions import Version
from universions.git import get_git_version

from .mock_popen import BasicMockedPopen

MAC_GIT = b"git version 2.10.1 (Apple Git-78)"
UNIX_GIT = b"git version 2.23.0"
OLD_GIT = b"git version 1.7.7.3"
WINDOWS_GIT = b"git version 2.24.0.windows.1"
CYGWIN_GIT = b"git version 1.9.5.msysgit.0"

GIT_VERSIONS = [
    pytest.param(MAC_GIT, Version(2, 10, 1, None, "Apple Git-78")),
    pytest.param(UNIX_GIT, Version(2, 23, 0)),
    pytest.param(OLD_GIT, Version(1, 7, 7, None, "3")),
    pytest.param(WINDOWS_GIT, Version(2, 24, 0, None, "windows.1")),
    pytest.param(CYGWIN_GIT, Version(1, 9, 5, None, "msysgit.0")),
]


class TestGit(BasicMockedPopen):
    """Test the Git version"""

    @pytest.mark.parametrize("command,version", GIT_VERSIONS)
    def test_git_vesion(self, command: bytes, version: Version):
        """Test that the correct version is returned."""
        self.popen.set_command("git --version", stdout=command)
        assert get_git_version() == version
Пример #13
0
 def test_npm_version_with_path(self):
     """Test that the correct version is returned when specifying path."""
     path = str(Path.home() / "npm-here" / "bin" / "npm.bin")
     self.popen.set_command(f"{path} --version", stdout=LINUX_OUT)
     assert get_npm_version(npm_path=path) == Version(6, 4, 1)
Пример #14
0
"""Test the npm version."""

from pathlib import Path

import pytest

from universions import Version
from universions.npm import get_npm_version

from .mock_popen import BasicMockedPopen

MAC_OUT = b"5.0.4"
LINUX_OUT = b"6.4.1"

VERSIONS = [
    pytest.param(MAC_OUT, Version(5, 0, 4)),
    pytest.param(LINUX_OUT, Version(6, 4, 1)),
]


class TestNpm(BasicMockedPopen):
    """Test the Npm version."""
    @pytest.mark.parametrize("output,version", VERSIONS)
    def test_default_npm_version(self, output: bytes, version: Version):
        """Test that the correct version is returned."""
        self.popen.set_command("npm --version", stdout=output)
        assert get_npm_version() == version

    def test_npm_version_with_path(self):
        """Test that the correct version is returned when specifying path."""
        path = str(Path.home() / "npm-here" / "bin" / "npm.bin")