Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Dec 6, 2024
1 parent e938bac commit 55d571d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
32 changes: 23 additions & 9 deletions tests/test_toppingmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down
7 changes: 7 additions & 0 deletions tests/testdata/validConfig.ini
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 55d571d

Please sign in to comment.