Files
powertrain-build/tests/powertrain_build/test_environmentcheck.py
olindgre 2ece01e1d7 Make powertrain-build not overlap with pybuild in site-packages
Change-Id: I7b59f3f04f0f787d35db0b9389f295bf1ad24f56
2024-09-17 10:25:04 +02:00

60 lines
2.3 KiB
Python

# Copyright 2024 Volvo Car Corporation
# Licensed under Apache 2.0.
"""Tests for pybuild environment check module.
Run from project: py -3 -m pytest ./powertrain_build/test/test_environmentcheck.py
"""
import unittest
from unittest.mock import patch
from powertrain_build import environmentcheck
class TestpybuildEnvironmentCheck(unittest.TestCase):
"""Unit tests for environmentcheck module."""
@patch('sys.version_info', (3, 5))
def test_check_python_string_too_low_version_major_only(self):
"""Test for version 3.5, requiring a version higher than or equal to 3.6."""
with self.assertRaises(RuntimeError):
environmentcheck.check_python_string('3.6')
@patch('sys.version_info', (3, 5))
def test_check_python_string_too_low_version_major_minor(self):
"""Test for version 3.5, requiring exactly version 3.6."""
with self.assertRaises(RuntimeError):
environmentcheck.check_python_string('3.6', '3.6')
@staticmethod
@patch('sys.version_info', (3, 8))
def test_check_python_string_higher_version_major_only():
"""Test for version 3.8, requiring a version higher than or equal to 3.6."""
environmentcheck.check_python_string('3.6')
@staticmethod
@patch('sys.version_info', (3, 7))
def test_check_python_string_version_between_limits_major_only():
"""Test for version 3.7, requiring a version higher than or equal to 3.6 and lower or equal to 3.8."""
environmentcheck.check_python_string('3.6', '3.8')
@patch('sys.version_info', (3, 8))
def test_check_python_string_too_high_version_major_minor_identical(self):
"""Test for version 3.8, requiring exactly version 3.6."""
with self.assertRaises(RuntimeError):
environmentcheck.check_python_string('3.6', '3.6')
@patch('sys.version_info', (3, 8))
def test_check_python_string_too_high_version_major_minor(self):
"""Test for version 3.8, requiring a version between 3.6 to 3.7."""
with self.assertRaises(RuntimeError):
environmentcheck.check_python_string('3.6', '3.7')
@staticmethod
@patch('sys.version_info', (3, 6))
def test_check_python_string_version_upper_lower_identical():
"""Test for version 3.6, requiring exactly version 3.6."""
environmentcheck.check_python_string('3.6', '3.6')