Merge branch 'workaround-python3.10' into 'master'

Make two versions of a test to work around a difference in Python 3.10

See merge request openlp/openlp!399
This commit is contained in:
Tim Bentley 2022-02-03 19:28:39 +00:00
commit bbb55dc3d1

View File

@ -22,9 +22,12 @@
Functional tests to test the AppLocation class and related methods. Functional tests to test the AppLocation class and related methods.
""" """
import os import os
import sys
from pathlib import Path from pathlib import Path
from unittest.mock import patch from unittest.mock import patch
import pytest
from openlp.core.common import get_frozen_path from openlp.core.common import get_frozen_path
from openlp.core.common.applocation import AppLocation from openlp.core.common.applocation import AppLocation
@ -141,11 +144,35 @@ def test_get_directory_for_app_dir(mocked_get_frozen_path):
assert directory == Path.cwd() / Path('app', 'dir'), 'Directory should be "app/dir"' assert directory == Path.cwd() / Path('app', 'dir'), 'Directory should be "app/dir"'
@pytest.mark.skipif(sys.version_info < (3, 10), reason="Python 3.10 version of this test")
@patch('openlp.core.common.applocation.get_frozen_path') @patch('openlp.core.common.applocation.get_frozen_path')
@patch('openlp.core.common.applocation.os.path.abspath') @patch('openlp.core.common.applocation.os.path.abspath')
@patch('openlp.core.common.applocation.os.path.split') @patch('openlp.core.common.applocation.os.path.split')
@patch('openlp.core.common.applocation.sys') @patch('openlp.core.common.applocation.sys')
def test_get_directory_for_plugins_dir(mocked_sys, mocked_split, mocked_abspath, mocked_get_frozen_path): def test_get_directory_for_plugins_dir_py310(mocked_sys, mocked_split, mocked_abspath, mocked_get_frozen_path):
"""
Test the AppLocation.get_directory() method for AppLocation.PluginsDir
"""
# GIVEN: _get_frozen_path, abspath, split and sys are mocked out
mocked_abspath.return_value = os.path.join('dir', 'plugins')
mocked_split.return_value = ['openlp']
mocked_get_frozen_path.return_value = Path('dir')
mocked_sys.frozen = 1
mocked_sys.argv = ['openlp']
# WHEN: We call AppLocation.get_directory
directory = AppLocation.get_directory(AppLocation.PluginsDir)
# THEN: The correct directory should be returned
assert directory == Path('dir', 'plugins'), 'Directory should be "dir/plugins"'
@pytest.mark.skipif(sys.version_info >= (3, 10), reason="Python 3.9 version of this test")
@patch('openlp.core.common.applocation.get_frozen_path')
@patch('openlp.core.common.applocation.os.path.abspath')
@patch('openlp.core.common.applocation.os.path.split')
@patch('openlp.core.common.applocation.sys')
def test_get_directory_for_plugins_dir_py39(mocked_sys, mocked_split, mocked_abspath, mocked_get_frozen_path):
""" """
Test the AppLocation.get_directory() method for AppLocation.PluginsDir Test the AppLocation.get_directory() method for AppLocation.PluginsDir
""" """