diff --git a/openlp/core/version.py b/openlp/core/version.py index 49b5ada06..5e1a86036 100644 --- a/openlp/core/version.py +++ b/openlp/core/version.py @@ -162,11 +162,23 @@ def get_version(): except OSError: log.exception('Error in version file.') full_version = '0.0.0' - bits = full_version.split('.dev') + + if '.dev' in full_version: + # Old way of doing build numbers, but also how hatch does them + version_number, build_number = full_version.split('.dev', 1) + build_number = build_number.split('+', 1)[1] + elif '+' in full_version: + # Current way of doing build numbers, may be replaced by hatch later + version_number, build_number = full_version.split('+', 1) + else: + # If this is a release, there is no build number + version_number = full_version + build_number = None + APPLICATION_VERSION = { 'full': full_version, - 'version': bits[0], - 'build': full_version.split('+')[1] if '+' in full_version else None + 'version': version_number, + 'build': build_number } if APPLICATION_VERSION['build']: log.info('OpenLP version {version} build {build}'.format(version=APPLICATION_VERSION['version'], diff --git a/tests/openlp_core/test_version.py b/tests/openlp_core/test_version.py index 71bc1d669..65835840d 100644 --- a/tests/openlp_core/test_version.py +++ b/tests/openlp_core/test_version.py @@ -21,10 +21,10 @@ """ Package to test the openlp.core.version package. """ -import sys from datetime import date from unittest.mock import MagicMock, patch +import pytest from requests.exceptions import ConnectionError from openlp.core.version import VersionWorker, check_for_update, get_version, update_check_date @@ -251,15 +251,25 @@ def test_check_for_update_skipped(mocked_run_thread, mock_settings): assert mocked_run_thread.call_count == 0 -def test_get_version_dev_version(): +@pytest.mark.parametrize('in_version, out_version', [ + ('3.1.1', {'full': '3.1.1', 'version': '3.1.1', 'build': None}), + ('3.0.2+git.cb1db9f43', {'full': '3.0.2+git.cb1db9f43', 'version': '3.0.2', 'build': 'git.cb1db9f43'}), + ('3.1.2.dev15+gff6b05ed3', {'full': '3.1.2.dev15+gff6b05ed3', 'version': '3.1.2', 'build': 'gff6b05ed3'}) +]) +@patch('openlp.core.version.AppLocation.get_directory') +def test_get_version(mocked_get_directory: MagicMock, in_version: str, out_version: dict): """ Test the get_version() function """ - # GIVEN: We're in dev mode - with patch.object(sys, 'argv', ['--dev-version']), \ - patch('openlp.core.version.APPLICATION_VERSION', None): - # WHEN: get_version() is run + # GIVEN: Some mocks and predefined versions + mocked_path = MagicMock() + mocked_path.__truediv__.return_value = mocked_path + mocked_path.read_text.return_value = in_version + mocked_get_directory.return_value = mocked_path + + # WHEN: get_version() is run + with patch('openlp.core.version.APPLICATION_VERSION', None): version = get_version() # THEN: version is something - assert version + assert version == out_version