Fix running tests in plugin using pytest

This commit is contained in:
ChrisTerBeke 2018-11-19 13:42:28 +01:00
parent 951a21ead7
commit f8f133d2ef
5 changed files with 28 additions and 19 deletions

View file

@ -1,8 +1,7 @@
# Copyright (c) 2018 Ultimaker B.V. # Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
import configparser # An input for some functions we're testing. import configparser # An input for some functions we're testing.
import os.path # To find the integration test .ini files. import os # To find the integration test .ini files.
import pytest # To register tests with. import pytest # To register tests with.
import unittest.mock # To mock the application, plug-in and container registry out. import unittest.mock # To mock the application, plug-in and container registry out.
@ -11,13 +10,15 @@ import UM.PluginRegistry # To mock the plug-in registry out.
import UM.Settings.ContainerRegistry # To mock the container registry out. import UM.Settings.ContainerRegistry # To mock the container registry out.
import UM.Settings.InstanceContainer # To intercept the serialised data from the read() function. import UM.Settings.InstanceContainer # To intercept the serialised data from the read() function.
import LegacyProfileReader as LegacyProfileReaderModule # To get the directory of the module. import plugins.LegacyProfileReader.LegacyProfileReader as LegacyProfileReaderModule
from LegacyProfileReader import LegacyProfileReader # The module we're testing. from plugins.LegacyProfileReader.LegacyProfileReader import LegacyProfileReader
@pytest.fixture @pytest.fixture
def legacy_profile_reader(): def legacy_profile_reader():
return LegacyProfileReader() return LegacyProfileReader()
test_prepareDefaultsData = [ test_prepareDefaultsData = [
{ {
"defaults": "defaults":

View file

@ -1,16 +1,17 @@
# Copyright (c) 2017 Ultimaker B.V. # Copyright (c) 2017 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
import configparser
import pytest
import configparser #To check whether the appropriate exceptions are raised. from plugins.VersionUpgrade.VersionUpgrade25to26 import VersionUpgrade25to26
import pytest #To register tests with.
import VersionUpgrade25to26 #The module we're testing.
## Creates an instance of the upgrader to test with. ## Creates an instance of the upgrader to test with.
@pytest.fixture @pytest.fixture
def upgrader(): def upgrader():
return VersionUpgrade25to26.VersionUpgrade25to26() return VersionUpgrade25to26.VersionUpgrade25to26()
test_cfg_version_good_data = [ test_cfg_version_good_data = [
{ {
"test_name": "Simple", "test_name": "Simple",
@ -60,6 +61,7 @@ setting_version = -3
} }
] ]
## Tests the technique that gets the version number from CFG files. ## Tests the technique that gets the version number from CFG files.
# #
# \param data The parametrised data to test with. It contains a test name # \param data The parametrised data to test with. It contains a test name
@ -116,6 +118,7 @@ version = 1.2
} }
] ]
## Tests whether getting a version number from bad CFG files gives an ## Tests whether getting a version number from bad CFG files gives an
# exception. # exception.
# #
@ -155,6 +158,7 @@ foo = bar
} }
] ]
## Tests whether the settings that should be removed are removed for the 2.6 ## Tests whether the settings that should be removed are removed for the 2.6
# version of preferences. # version of preferences.
@pytest.mark.parametrize("data", test_upgrade_preferences_removed_settings_data) @pytest.mark.parametrize("data", test_upgrade_preferences_removed_settings_data)
@ -200,6 +204,7 @@ type = instance_container
} }
] ]
## Tests whether the settings that should be removed are removed for the 2.6 ## Tests whether the settings that should be removed are removed for the 2.6
# version of instance containers. # version of instance containers.
@pytest.mark.parametrize("data", test_upgrade_instance_container_removed_settings_data) @pytest.mark.parametrize("data", test_upgrade_instance_container_removed_settings_data)

View file

@ -1,15 +1,16 @@
# Copyright (c) 2017 Ultimaker B.V. # Copyright (c) 2017 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
import configparser
import pytest
import configparser #To check whether the appropriate exceptions are raised. from plugins.VersionUpgrade.VersionUpgrade26to27.VersionUpgrade26to27 import VersionUpgrade26to27
import pytest #To register tests with.
import VersionUpgrade26to27 #The module we're testing.
## Creates an instance of the upgrader to test with. ## Creates an instance of the upgrader to test with.
@pytest.fixture @pytest.fixture
def upgrader(): def upgrader():
return VersionUpgrade26to27.VersionUpgrade26to27() return VersionUpgrade26to27()
test_cfg_version_good_data = [ test_cfg_version_good_data = [
{ {

View file

@ -1,15 +1,15 @@
# Copyright (c) 2017 Ultimaker B.V. # Copyright (c) 2017 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
import configparser
import pytest
import configparser #To parse the resulting config files. from plugins.VersionUpgrade.VersionUpgrade27to30.VersionUpgrade27to30 import VersionUpgrade27to30
import pytest #To register tests with.
import VersionUpgrade27to30 #The module we're testing.
## Creates an instance of the upgrader to test with. ## Creates an instance of the upgrader to test with.
@pytest.fixture @pytest.fixture
def upgrader(): def upgrader():
return VersionUpgrade27to30.VersionUpgrade27to30() return VersionUpgrade27to30()
test_cfg_version_good_data = [ test_cfg_version_good_data = [
{ {

View file

@ -1,15 +1,16 @@
# Copyright (c) 2018 Ultimaker B.V. # Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
import configparser
import pytest
import configparser #To parse the resulting config files. from plugins.VersionUpgrade.VersionUpgrade34to35.VersionUpgrade34to35 import VersionUpgrade34to35
import pytest #To register tests with.
import VersionUpgrade34to35 #The module we're testing.
## Creates an instance of the upgrader to test with. ## Creates an instance of the upgrader to test with.
@pytest.fixture @pytest.fixture
def upgrader(): def upgrader():
return VersionUpgrade34to35.VersionUpgrade34to35() return VersionUpgrade34to35()
test_upgrade_version_nr_data = [ test_upgrade_version_nr_data = [
("Empty config file", ("Empty config file",
@ -25,6 +26,7 @@ test_upgrade_version_nr_data = [
) )
] ]
## Tests whether the version numbers are updated. ## Tests whether the version numbers are updated.
@pytest.mark.parametrize("test_name, file_data", test_upgrade_version_nr_data) @pytest.mark.parametrize("test_name, file_data", test_upgrade_version_nr_data)
def test_upgradeVersionNr(test_name, file_data, upgrader): def test_upgradeVersionNr(test_name, file_data, upgrader):