From 55d571d095095310e362eab569ed5be3d423e2c3 Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 6 Dec 2024 12:31:37 +0100 Subject: [PATCH] tests --- tests/test_toppingmaker.py | 32 +++++++++++++++++++++++--------- tests/testdata/validConfig.ini | 7 +++++++ 2 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 tests/testdata/validConfig.ini diff --git a/tests/test_toppingmaker.py b/tests/test_toppingmaker.py index bc37645..5ce3c61 100644 --- a/tests/test_toppingmaker.py +++ b/tests/test_toppingmaker.py @@ -43,6 +43,9 @@ class ToppingMakerTest(unittest.TestCase): def setUpClass(cls): """Run before all tests.""" cls.basetestpath = tempfile.mkdtemp() + cls.testdata_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), "testdata" + ) cls.projecttopping_test_path = os.path.join(cls.basetestpath, "projecttopping") def test_target(self): @@ -143,9 +146,11 @@ def test_parse_project_with_mapthemes(self): # check variables variables = project_topping.variables # Anyway in practice no spaces should be used to be able to access them in the expressions like @first_variable - assert variables.get("First Variable") == "This is a test value." + assert variables.get("First Variable") + assert variables.get("First Variable")["value"] == "This is a test value." # QGIS is currently (3.29) not able to store structures in the project file. Still... - assert variables.get("Variable with Structure") == [ + assert variables.get("Variable with Structure") + assert variables.get("Variable with Structure")["value"] == [ "Not", "The", "Normal", @@ -416,11 +421,18 @@ def test_generate_files(self): "Case", ] foundVariableWithStructure = True + if variable_key == "Validation Path Variable": + assert ( + projecttopping_data["variables"][variable_key] + == "freddys_projects/this_specific_project/generic/freddys_validConfig.ini" + ) + foundVariableWithPath = True variable_count += 1 - assert variable_count == 2 + assert variable_count == 3 assert foundFirstVariable assert foundVariableWithStructure + assert foundVariableWithPath # check transaction mode with open(projecttopping_file_path) as yamlfile: @@ -471,12 +483,13 @@ def test_generate_files(self): countchecked = 0 - # there should be 21 toppingfiles: + # there should be 22 toppingfiles: # - one project topping # - 2 x 3 qlr files (two times since the layers are multiple times in the tree) # - 2 x 6 qml files (one layers with 3 styles, one layer with 2 styles and one layer with one style - and two times since the layers are multiple times in the tree) # - 2 qpt template files - assert len(target.toppingfileinfo_list) == 21 + # - 1 generic file (validation.ini) what is created by variable + assert len(target.toppingfileinfo_list) == 22 for toppingfileinfo in target.toppingfileinfo_list: self.print_info(toppingfileinfo["path"]) @@ -705,8 +718,8 @@ def _make_project_and_export_settings(self): ) QgsExpressionContextUtils.setProjectVariable( project, - "Path variable", - [os.path.join(self.projecttopping_test_path, "validconfig.ini")], + "Validation Path Variable", + os.path.join(self.testdata_path, "validConfig.ini"), ) # create layouts @@ -796,9 +809,10 @@ def _make_project_and_export_settings(self): export_settings.variables = [ "First Variable", "Variable with Structure", - "Path variable", + "Validation Path Variable", ] - export_settings.path_variables = ["Path variable"] + # content of this variable should be exported as toppingfile + export_settings.path_variables = ["Validation Path Variable"] # define the layouts to export export_settings.layouts = ["Layout One", "Layout Three"] diff --git a/tests/testdata/validConfig.ini b/tests/testdata/validConfig.ini new file mode 100644 index 0000000..1d2b550 --- /dev/null +++ b/tests/testdata/validConfig.ini @@ -0,0 +1,7 @@ +["PARAMETER"] +validation="on" +additionalModels="SH_ProjektdatenDB_Naturschutz_V1_0_AddChecks" + +["SH_ProjektdatenDB_Naturschutz_V1_0_AddChecks.SH_ProjektdatenDB_Naturschutz_V1_0_Validierung.v_Mitarbeitende.checkNameDuplikate"] +multiplicity="on" +type="on"