forked from WaterFutures/EPANET-PLUS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_load_inp_from_buffer.py
More file actions
59 lines (44 loc) · 1.95 KB
/
Copy pathtest_load_inp_from_buffer.py
File metadata and controls
59 lines (44 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
This module tests the EPANET-PLUS function for loading an .inp file from a buffer.
"""
import os
import tempfile
import epanet
from epanet_plus import EpanetConstants, EPyT
def test_load_from_buffer():
inp_buffer = ""
with open(os.path.join("tests", "net2-cl2.inp"), "rt") as f_in:
inp_buffer = "".join(f_in.readlines())
assert epanet.ENopenfrombuffer(inp_buffer, os.path.join("tests", "net2-cl2.inp"),
os.path.join("tests", "net2-cl2.rpt"), "") == (0,)
assert epanet.ENgettitle() == (0, "EPANET Example Network 2", "", "")
assert epanet.ENgetcount(EpanetConstants.EN_NODECOUNT)[1] > 0
epanet.ENclose()
def test_epyt_load_from_buffer():
def __test_code(epanet_api: EPyT):
epanet_api.openH()
epanet_api.initH(EpanetConstants.EN_NOSAVE)
epanet_api.openQ()
epanet_api.initQ(EpanetConstants.EN_NOSAVE)
tstep = 1
while tstep > 0:
epanet_api.runH()
epanet_api.runQ()
assert len(epanet_api.getnodevalues(EpanetConstants.EN_PRESSURE)) > 0
assert len(epanet_api.getlinkvalues(EpanetConstants.EN_FLOW)) > 0
assert len(epanet_api.getnodevalues(EpanetConstants.EN_QUALITY)) > 0
assert len(epanet_api.getlinkvalues(EpanetConstants.EN_QUALITY)) > 0
tstep = epanet_api.nextH()
epanet_api.nextQ()
epanet_api.closeQ()
epanet_api.closeH()
# Load .inp file into buffer
inp_buffer = ""
with open(os.path.join("tests", "net2-cl2.inp"), "rt") as f_in:
inp_buffer = "".join(f_in.readlines())
# Load .inp buffer into EPANET via EPyT
with EPyT(os.path.join(tempfile.gettempdir(), "net2-cl2.inp"), inp_buffer=inp_buffer) as epanet_api:
__test_code(epanet_api)
with EPyT(os.path.join(tempfile.gettempdir(), "net2-cl2.inp"), use_project=True,
inp_buffer=inp_buffer) as epanet_api:
__test_code(epanet_api)