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.
# Cura is released under the terms of the LGPLv3 or higher.
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 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.InstanceContainer # To intercept the serialised data from the read() function.
import LegacyProfileReader as LegacyProfileReaderModule # To get the directory of the module.
from LegacyProfileReader import LegacyProfileReader # The module we're testing.
import plugins.LegacyProfileReader.LegacyProfileReader as LegacyProfileReaderModule
from plugins.LegacyProfileReader.LegacyProfileReader import LegacyProfileReader
@pytest.fixture
def legacy_profile_reader():
return LegacyProfileReader()
test_prepareDefaultsData = [
{
"defaults":

View file

@ -1,16 +1,17 @@
# Copyright (c) 2017 Ultimaker B.V.
# 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.
import pytest #To register tests with.
from plugins.VersionUpgrade.VersionUpgrade25to26 import VersionUpgrade25to26
import VersionUpgrade25to26 #The module we're testing.
## Creates an instance of the upgrader to test with.
@pytest.fixture
def upgrader():
return VersionUpgrade25to26.VersionUpgrade25to26()
test_cfg_version_good_data = [
{
"test_name": "Simple",
@ -60,6 +61,7 @@ setting_version = -3
}
]
## Tests the technique that gets the version number from CFG files.
#
# \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
# exception.
#
@ -155,6 +158,7 @@ foo = bar
}
]
## Tests whether the settings that should be removed are removed for the 2.6
# version of preferences.
@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
# version of instance containers.
@pytest.mark.parametrize("data", test_upgrade_instance_container_removed_settings_data)

View file

@ -1,15 +1,16 @@
# Copyright (c) 2017 Ultimaker B.V.
# 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.
import pytest #To register tests with.
from plugins.VersionUpgrade.VersionUpgrade26to27.VersionUpgrade26to27 import VersionUpgrade26to27
import VersionUpgrade26to27 #The module we're testing.
## Creates an instance of the upgrader to test with.
@pytest.fixture
def upgrader():
return VersionUpgrade26to27.VersionUpgrade26to27()
return VersionUpgrade26to27()
test_cfg_version_good_data = [
{

View file

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

View file

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