floodmodeller-api 0.4.2.post1__py3-none-any.whl → 0.4.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. floodmodeller_api/__init__.py +8 -9
  2. floodmodeller_api/_base.py +184 -176
  3. floodmodeller_api/backup.py +273 -273
  4. floodmodeller_api/dat.py +909 -831
  5. floodmodeller_api/diff.py +136 -119
  6. floodmodeller_api/ied.py +307 -306
  7. floodmodeller_api/ief.py +647 -637
  8. floodmodeller_api/ief_flags.py +253 -253
  9. floodmodeller_api/inp.py +266 -266
  10. floodmodeller_api/libs/libifcoremd.dll +0 -0
  11. floodmodeller_api/libs/libifcoremt.so.5 +0 -0
  12. floodmodeller_api/libs/libifport.so.5 +0 -0
  13. floodmodeller_api/{libmmd.dll → libs/libimf.so} +0 -0
  14. floodmodeller_api/libs/libintlc.so.5 +0 -0
  15. floodmodeller_api/libs/libmmd.dll +0 -0
  16. floodmodeller_api/libs/libsvml.so +0 -0
  17. floodmodeller_api/libs/libzzn_read.so +0 -0
  18. floodmodeller_api/libs/zzn_read.dll +0 -0
  19. floodmodeller_api/logs/__init__.py +2 -2
  20. floodmodeller_api/logs/lf.py +320 -312
  21. floodmodeller_api/logs/lf_helpers.py +354 -352
  22. floodmodeller_api/logs/lf_params.py +643 -529
  23. floodmodeller_api/mapping.py +84 -0
  24. floodmodeller_api/test/__init__.py +4 -4
  25. floodmodeller_api/test/conftest.py +9 -8
  26. floodmodeller_api/test/test_backup.py +117 -117
  27. floodmodeller_api/test/test_dat.py +221 -92
  28. floodmodeller_api/test/test_data/All Units 4_6.DAT +1081 -1081
  29. floodmodeller_api/test/test_data/All Units 4_6.feb +1081 -1081
  30. floodmodeller_api/test/test_data/BRIDGE.DAT +926 -926
  31. floodmodeller_api/test/test_data/Culvert_Inlet_Outlet.dat +36 -36
  32. floodmodeller_api/test/test_data/Culvert_Inlet_Outlet.feb +36 -36
  33. floodmodeller_api/test/test_data/DamBreakADI.xml +52 -52
  34. floodmodeller_api/test/test_data/DamBreakFAST.xml +58 -58
  35. floodmodeller_api/test/test_data/DamBreakFAST_dy.xml +53 -53
  36. floodmodeller_api/test/test_data/DamBreakTVD.xml +55 -55
  37. floodmodeller_api/test/test_data/DefenceBreach.xml +53 -53
  38. floodmodeller_api/test/test_data/DefenceBreachFAST.xml +60 -60
  39. floodmodeller_api/test/test_data/DefenceBreachFAST_dy.xml +55 -55
  40. floodmodeller_api/test/test_data/Domain1+2_QH.xml +76 -76
  41. floodmodeller_api/test/test_data/Domain1_H.xml +41 -41
  42. floodmodeller_api/test/test_data/Domain1_Q.xml +41 -41
  43. floodmodeller_api/test/test_data/Domain1_Q_FAST.xml +48 -48
  44. floodmodeller_api/test/test_data/Domain1_Q_FAST_dy.xml +48 -48
  45. floodmodeller_api/test/test_data/Domain1_Q_xml_expected.json +263 -0
  46. floodmodeller_api/test/test_data/Domain1_W.xml +41 -41
  47. floodmodeller_api/test/test_data/EX1.DAT +321 -321
  48. floodmodeller_api/test/test_data/EX1.ext +107 -107
  49. floodmodeller_api/test/test_data/EX1.feb +320 -320
  50. floodmodeller_api/test/test_data/EX1.gxy +107 -107
  51. floodmodeller_api/test/test_data/EX17.DAT +421 -422
  52. floodmodeller_api/test/test_data/EX17.ext +213 -213
  53. floodmodeller_api/test/test_data/EX17.feb +422 -422
  54. floodmodeller_api/test/test_data/EX18.DAT +375 -375
  55. floodmodeller_api/test/test_data/EX18_DAT_expected.json +3876 -0
  56. floodmodeller_api/test/test_data/EX2.DAT +302 -302
  57. floodmodeller_api/test/test_data/EX3.DAT +926 -926
  58. floodmodeller_api/test/test_data/EX3_DAT_expected.json +16235 -0
  59. floodmodeller_api/test/test_data/EX3_IEF_expected.json +61 -0
  60. floodmodeller_api/test/test_data/EX6.DAT +2084 -2084
  61. floodmodeller_api/test/test_data/EX6.ext +532 -532
  62. floodmodeller_api/test/test_data/EX6.feb +2084 -2084
  63. floodmodeller_api/test/test_data/EX6_DAT_expected.json +31647 -0
  64. floodmodeller_api/test/test_data/Event Data Example.DAT +336 -336
  65. floodmodeller_api/test/test_data/Event Data Example.ext +107 -107
  66. floodmodeller_api/test/test_data/Event Data Example.feb +336 -336
  67. floodmodeller_api/test/test_data/Linked1D2D.xml +52 -52
  68. floodmodeller_api/test/test_data/Linked1D2DFAST.xml +53 -53
  69. floodmodeller_api/test/test_data/Linked1D2DFAST_dy.xml +48 -48
  70. floodmodeller_api/test/test_data/Linked1D2D_xml_expected.json +313 -0
  71. floodmodeller_api/test/test_data/blockage.dat +50 -50
  72. floodmodeller_api/test/test_data/blockage.ext +45 -45
  73. floodmodeller_api/test/test_data/blockage.feb +9 -9
  74. floodmodeller_api/test/test_data/blockage.gxy +71 -71
  75. floodmodeller_api/test/test_data/defaultUnits.dat +127 -127
  76. floodmodeller_api/test/test_data/defaultUnits.ext +45 -45
  77. floodmodeller_api/test/test_data/defaultUnits.feb +9 -9
  78. floodmodeller_api/test/test_data/defaultUnits.fmpx +58 -58
  79. floodmodeller_api/test/test_data/defaultUnits.gxy +85 -85
  80. floodmodeller_api/test/test_data/ex3.ief +20 -20
  81. floodmodeller_api/test/test_data/ex3.lf1 +2800 -2800
  82. floodmodeller_api/test/test_data/ex4.DAT +1374 -1374
  83. floodmodeller_api/test/test_data/ex4_changed.DAT +1374 -1374
  84. floodmodeller_api/test/test_data/example1.inp +329 -329
  85. floodmodeller_api/test/test_data/example2.inp +158 -158
  86. floodmodeller_api/test/test_data/example3.inp +297 -297
  87. floodmodeller_api/test/test_data/example4.inp +388 -388
  88. floodmodeller_api/test/test_data/example5.inp +147 -147
  89. floodmodeller_api/test/test_data/example6.inp +154 -154
  90. floodmodeller_api/test/test_data/jump.dat +176 -176
  91. floodmodeller_api/test/test_data/network.dat +1374 -1374
  92. floodmodeller_api/test/test_data/network.ext +45 -45
  93. floodmodeller_api/test/test_data/network.exy +1 -1
  94. floodmodeller_api/test/test_data/network.feb +45 -45
  95. floodmodeller_api/test/test_data/network.ied +45 -45
  96. floodmodeller_api/test/test_data/network.ief +20 -20
  97. floodmodeller_api/test/test_data/network.inp +147 -147
  98. floodmodeller_api/test/test_data/network.pxy +57 -57
  99. floodmodeller_api/test/test_data/network.zzd +122 -122
  100. floodmodeller_api/test/test_data/network_dat_expected.json +21837 -0
  101. floodmodeller_api/test/test_data/network_from_tabularCSV.csv +87 -87
  102. floodmodeller_api/test/test_data/network_ied_expected.json +287 -0
  103. floodmodeller_api/test/test_data/rnweir.dat +9 -9
  104. floodmodeller_api/test/test_data/rnweir.ext +45 -45
  105. floodmodeller_api/test/test_data/rnweir.feb +9 -9
  106. floodmodeller_api/test/test_data/rnweir.gxy +45 -45
  107. floodmodeller_api/test/test_data/rnweir_default.dat +74 -74
  108. floodmodeller_api/test/test_data/rnweir_default.ext +45 -45
  109. floodmodeller_api/test/test_data/rnweir_default.feb +9 -9
  110. floodmodeller_api/test/test_data/rnweir_default.fmpx +58 -58
  111. floodmodeller_api/test/test_data/rnweir_default.gxy +53 -53
  112. floodmodeller_api/test/test_data/unit checks.dat +16 -16
  113. floodmodeller_api/test/test_ied.py +29 -29
  114. floodmodeller_api/test/test_ief.py +125 -24
  115. floodmodeller_api/test/test_inp.py +47 -48
  116. floodmodeller_api/test/test_json.py +114 -0
  117. floodmodeller_api/test/test_logs_lf.py +48 -51
  118. floodmodeller_api/test/test_tool.py +165 -152
  119. floodmodeller_api/test/test_toolbox_structure_log.py +234 -239
  120. floodmodeller_api/test/test_xml2d.py +151 -156
  121. floodmodeller_api/test/test_zzn.py +36 -34
  122. floodmodeller_api/to_from_json.py +218 -0
  123. floodmodeller_api/tool.py +332 -329
  124. floodmodeller_api/toolbox/__init__.py +5 -5
  125. floodmodeller_api/toolbox/example_tool.py +45 -45
  126. floodmodeller_api/toolbox/model_build/__init__.py +2 -2
  127. floodmodeller_api/toolbox/model_build/add_siltation_definition.py +100 -98
  128. floodmodeller_api/toolbox/model_build/structure_log/__init__.py +1 -1
  129. floodmodeller_api/toolbox/model_build/structure_log/structure_log.py +287 -289
  130. floodmodeller_api/toolbox/model_build/structure_log_definition.py +76 -76
  131. floodmodeller_api/units/__init__.py +10 -10
  132. floodmodeller_api/units/_base.py +214 -212
  133. floodmodeller_api/units/boundaries.py +467 -467
  134. floodmodeller_api/units/comment.py +52 -55
  135. floodmodeller_api/units/conduits.py +382 -402
  136. floodmodeller_api/units/helpers.py +123 -131
  137. floodmodeller_api/units/iic.py +107 -101
  138. floodmodeller_api/units/losses.py +305 -306
  139. floodmodeller_api/units/sections.py +444 -446
  140. floodmodeller_api/units/structures.py +1690 -1683
  141. floodmodeller_api/units/units.py +93 -104
  142. floodmodeller_api/units/unsupported.py +44 -44
  143. floodmodeller_api/units/variables.py +87 -89
  144. floodmodeller_api/urban1d/__init__.py +11 -11
  145. floodmodeller_api/urban1d/_base.py +188 -179
  146. floodmodeller_api/urban1d/conduits.py +93 -85
  147. floodmodeller_api/urban1d/general_parameters.py +58 -58
  148. floodmodeller_api/urban1d/junctions.py +81 -79
  149. floodmodeller_api/urban1d/losses.py +81 -74
  150. floodmodeller_api/urban1d/outfalls.py +114 -110
  151. floodmodeller_api/urban1d/raingauges.py +111 -111
  152. floodmodeller_api/urban1d/subsections.py +92 -98
  153. floodmodeller_api/urban1d/xsections.py +147 -144
  154. floodmodeller_api/util.py +77 -21
  155. floodmodeller_api/validation/parameters.py +660 -660
  156. floodmodeller_api/validation/urban_parameters.py +388 -404
  157. floodmodeller_api/validation/validation.py +110 -108
  158. floodmodeller_api/version.py +1 -1
  159. floodmodeller_api/xml2d.py +688 -673
  160. floodmodeller_api/xml2d_template.py +37 -37
  161. floodmodeller_api/zzn.py +387 -363
  162. {floodmodeller_api-0.4.2.post1.dist-info → floodmodeller_api-0.4.3.dist-info}/LICENSE.txt +13 -13
  163. {floodmodeller_api-0.4.2.post1.dist-info → floodmodeller_api-0.4.3.dist-info}/METADATA +82 -82
  164. floodmodeller_api-0.4.3.dist-info/RECORD +179 -0
  165. {floodmodeller_api-0.4.2.post1.dist-info → floodmodeller_api-0.4.3.dist-info}/WHEEL +1 -1
  166. floodmodeller_api/libifcoremd.dll +0 -0
  167. floodmodeller_api/test/test_data/EX3.bmp +0 -0
  168. floodmodeller_api/test/test_data/test_output.csv +0 -87
  169. floodmodeller_api/zzn_read.dll +0 -0
  170. floodmodeller_api-0.4.2.post1.dist-info/RECORD +0 -164
  171. {floodmodeller_api-0.4.2.post1.dist-info → floodmodeller_api-0.4.3.dist-info}/entry_points.txt +0 -0
  172. {floodmodeller_api-0.4.2.post1.dist-info → floodmodeller_api-0.4.3.dist-info}/top_level.txt +0 -0
@@ -1,152 +1,165 @@
1
- import tkinter as tk
2
- from unittest.mock import MagicMock, patch
3
-
4
- import pytest
5
-
6
- from floodmodeller_api.tool import FMTool, Gui, Parameter
7
-
8
-
9
- # ------ Define function ----- #
10
- def my_sum(a: float, b: float):
11
- ab = a + b
12
- print(ab)
13
- return ab
14
-
15
-
16
- class SumTool(FMTool):
17
- # Define the name
18
- name = "Sum tool"
19
- description = "A basic tool to add two numbers together"
20
- parameters = [
21
- Parameter(
22
- name="a",
23
- dtype=float,
24
- description="the first number",
25
- help_text="",
26
- required=True,
27
- ),
28
- Parameter(
29
- name="b",
30
- dtype=float,
31
- description="the second number",
32
- help_text="",
33
- required=True,
34
- ),
35
- ]
36
- tool_function = my_sum
37
-
38
-
39
- @pytest.fixture
40
- def tool():
41
- return SumTool()
42
-
43
-
44
- # FMTool ---------
45
-
46
-
47
- def test_check_parameters():
48
- # Test that the check_parameters method raises an exception when two parameters have the same name
49
- class MyTool(FMTool):
50
- name = ""
51
- description = ""
52
- tool_function = print
53
- parameters = [
54
- Parameter(
55
- name="param1",
56
- dtype=str,
57
- description="Description 1",
58
- help_text="Help text 1",
59
- ),
60
- Parameter(
61
- name="param1",
62
- dtype=str,
63
- description="Description 2",
64
- help_text="Help text 2",
65
- ),
66
- ]
67
-
68
- with pytest.raises(ValueError):
69
- MyTool()
70
-
71
-
72
- def test_run():
73
- # Test that the run method calls the tool_function method with the correct arguments
74
- class MyTool(FMTool):
75
- @classmethod
76
- def tool_function(cls, param1, param2):
77
- assert param1 == "value1"
78
- assert param2 == "value2"
79
-
80
- MyTool.run(param1="value1", param2="value2")
81
-
82
-
83
- def test_run_tool_from_class(tool):
84
- assert tool.run(a=1, b=2) == 3
85
-
86
-
87
- def test_run_from_command_line():
88
- # Test that the run_from_command_line method parses the command line arguments correctly
89
- class MyTool(FMTool):
90
- name = "My Tool"
91
- description = "My Tools Description"
92
- parameters = [Parameter("param1", str), Parameter("param2", str)]
93
-
94
- @classmethod
95
- def tool_function(cls, param1, param2):
96
- assert param1 == "value1"
97
- assert param2 == "value2"
98
-
99
- with patch(
100
- "sys.argv",
101
- [
102
- "floodmodeller_api/test/test_tools.py",
103
- "--param1",
104
- "value1",
105
- "--param2",
106
- "value2",
107
- ],
108
- ):
109
- MyTool().run_from_command_line()
110
-
111
-
112
- # def GUI ----------------
113
- def test_gui_input_widgets(tool):
114
- tool.generate_gui()
115
- assert [param.name for param in tool.parameters] == list(tool.app.root_entries.keys())
116
-
117
-
118
- def test_gui_run_callback(tool):
119
- tool.generate_gui()
120
- tool.app.root_entries["a"].get = MagicMock(return_value=2)
121
- tool.app.root_entries["b"].get = MagicMock(return_value=5)
122
- assert tool.app.run_gui_callback() == 7
123
-
124
-
125
- def test_gui_without_fm_tool():
126
- parameters = [
127
- Parameter(
128
- name="a",
129
- dtype=float,
130
- description="the first number",
131
- help_text="",
132
- required=True,
133
- ),
134
- Parameter(
135
- name="b",
136
- dtype=float,
137
- description="the second number",
138
- help_text="",
139
- required=True,
140
- ),
141
- ]
142
- my_gui = Gui(
143
- master=tk.Tk(),
144
- title="My App",
145
- description="My Description",
146
- parameters=parameters,
147
- run_function=my_sum,
148
- )
149
- my_gui.root_entries["a"].get = MagicMock(return_value=2)
150
- my_gui.root_entries["b"].get = MagicMock(return_value=5)
151
-
152
- assert my_gui.run_gui_callback() == 7
1
+ import tkinter as tk
2
+ from functools import wraps
3
+ from unittest.mock import MagicMock, patch
4
+
5
+ import pytest
6
+
7
+ from floodmodeller_api.tool import FMTool, Gui, Parameter
8
+ from floodmodeller_api.util import is_windows
9
+
10
+
11
+ def my_sum(a: float, b: float):
12
+ ab = a + b
13
+ print(ab)
14
+ return ab
15
+
16
+
17
+ class SumTool(FMTool):
18
+ # Define the name
19
+ name = "Sum tool"
20
+ description = "A basic tool to add two numbers together"
21
+ parameters = [
22
+ Parameter(
23
+ name="a",
24
+ dtype=float,
25
+ description="the first number",
26
+ help_text="",
27
+ required=True,
28
+ ),
29
+ Parameter(
30
+ name="b",
31
+ dtype=float,
32
+ description="the second number",
33
+ help_text="",
34
+ required=True,
35
+ ),
36
+ ]
37
+ tool_function = my_sum
38
+
39
+
40
+ @pytest.fixture
41
+ def tool():
42
+ return SumTool()
43
+
44
+
45
+ def test_check_parameters():
46
+ """Test that the check_parameters method raises an exception when two parameters have the same name."""
47
+
48
+ class MyTool(FMTool):
49
+ name = ""
50
+ description = ""
51
+ tool_function = print
52
+ parameters = [
53
+ Parameter(
54
+ name="param1",
55
+ dtype=str,
56
+ description="Description 1",
57
+ help_text="Help text 1",
58
+ ),
59
+ Parameter(
60
+ name="param1",
61
+ dtype=str,
62
+ description="Description 2",
63
+ help_text="Help text 2",
64
+ ),
65
+ ]
66
+
67
+ with pytest.raises(ValueError):
68
+ MyTool()
69
+
70
+
71
+ def test_run():
72
+ """Test that the run method calls the tool_function method with the correct arguments."""
73
+
74
+ class MyTool(FMTool):
75
+ @classmethod
76
+ def tool_function(cls, param1, param2):
77
+ assert param1 == "value1"
78
+ assert param2 == "value2"
79
+
80
+ MyTool.run(param1="value1", param2="value2")
81
+
82
+
83
+ def test_run_tool_from_class(tool):
84
+ assert tool.run(a=1, b=2) == 3
85
+
86
+
87
+ def test_run_from_command_line():
88
+ """Test that the run_from_command_line method parses the command line arguments correctly."""
89
+
90
+ class MyTool(FMTool):
91
+ name = "My Tool"
92
+ description = "My Tools Description"
93
+ parameters = [Parameter("param1", str), Parameter("param2", str)]
94
+
95
+ @classmethod
96
+ def tool_function(cls, param1, param2):
97
+ assert param1 == "value1"
98
+ assert param2 == "value2"
99
+
100
+ with patch(
101
+ "sys.argv",
102
+ [
103
+ "floodmodeller_api/test/test_tools.py",
104
+ "--param1",
105
+ "value1",
106
+ "--param2",
107
+ "value2",
108
+ ],
109
+ ):
110
+ MyTool().run_from_command_line()
111
+
112
+
113
+ def gui_test(func):
114
+ @wraps(func)
115
+ def wrapper(*args, **kwargs):
116
+ if not is_windows():
117
+ pytest.skip("Skipping GUI test because no display is available")
118
+ return func(*args, **kwargs)
119
+
120
+ return wrapper
121
+
122
+
123
+ @gui_test
124
+ def test_gui_input_widgets(tool):
125
+ tool.generate_gui()
126
+ assert [param.name for param in tool.parameters] == list(tool.app.root_entries.keys())
127
+
128
+
129
+ @gui_test
130
+ def test_gui_run_callback(tool):
131
+ tool.generate_gui()
132
+ tool.app.root_entries["a"].get = MagicMock(return_value=2)
133
+ tool.app.root_entries["b"].get = MagicMock(return_value=5)
134
+ assert tool.app.run_gui_callback() == 7
135
+
136
+
137
+ @gui_test
138
+ def test_gui_without_fm_tool():
139
+ parameters = [
140
+ Parameter(
141
+ name="a",
142
+ dtype=float,
143
+ description="the first number",
144
+ help_text="",
145
+ required=True,
146
+ ),
147
+ Parameter(
148
+ name="b",
149
+ dtype=float,
150
+ description="the second number",
151
+ help_text="",
152
+ required=True,
153
+ ),
154
+ ]
155
+ my_gui = Gui(
156
+ master=tk.Tk(),
157
+ title="My App",
158
+ description="My Description",
159
+ parameters=parameters,
160
+ run_function=my_sum,
161
+ )
162
+ my_gui.root_entries["a"].get = MagicMock(return_value=2)
163
+ my_gui.root_entries["b"].get = MagicMock(return_value=5)
164
+
165
+ assert my_gui.run_gui_callback() == 7