#4576 Python: Add tests to check for expected exceptions

This commit is contained in:
Gaute Lindkvist 2019-08-14 09:43:44 +02:00
parent 7afeae144a
commit 071bb42101
2 changed files with 34 additions and 1 deletions

View File

@ -2,6 +2,7 @@ import sys
import os
import tempfile
import pytest
import grpc
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
import rips
@ -49,4 +50,9 @@ def test_exportFlowCharacteristics(rips_instance, initializeTest):
with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname:
print("Temporary folder: ", tmpdirname)
fileName = tmpdirname + "/exportFlowChar.txt"
rips_instance.commands.exportFlowCharacteristics(caseId=0, timeSteps=8, producers=[], injectors = "I01", fileName = fileName)
rips_instance.commands.exportFlowCharacteristics(caseId=0, timeSteps=8, producers=[], injectors = "I01", fileName = fileName)
def test_loadNonExistingCase(rips_instance, initializeTest):
casePath = "Nonsense/Nonsense/Nonsense"
with pytest.raises(grpc.RpcError):
assert rips_instance.project.loadCase(casePath)

View File

@ -1,5 +1,6 @@
import sys
import os
import grpc
import pytest
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
@ -33,6 +34,32 @@ def test_10kSync(rips_instance, initializeTest):
assert(average != pytest.approx(0.0158893, abs=0.0000001))
assert(average == pytest.approx(0.0558893, abs=0.0000001))
def test_10k_set(rips_instance, initializeTest):
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.loadCase(path=casePath)
results = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', 1)
case.properties.setActiveCellProperty(results, 'GENERATED', 'SOIL', 1)
def test_10k_set_out_of_bounds(rips_instance, initializeTest):
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.loadCase(path=casePath)
results = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', 1)
results.append(5.0)
with pytest.raises(grpc.RpcError):
assert case.properties.setActiveCellProperty(results, 'GENERATED', 'SOIL', 1)
def test_10k_set_out_of_bounds_client(rips_instance, initializeTest):
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.loadCase(path=casePath)
results = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', 1)
case.properties.chunkSize = len(results)
results.append(5.0)
with pytest.raises(IndexError):
assert case.properties.setActiveCellProperty(results, 'GENERATED', 'SOIL', 1)
def createResult(poroChunks, permxChunks):
for (poroChunk, permxChunk) in zip(poroChunks, permxChunks):
resultChunk = []