From 7024af28110e196a1cc4925b7c6280be8b108efc Mon Sep 17 00:00:00 2001 From: larsevj Date: Fri, 30 Aug 2024 15:27:45 +0200 Subject: [PATCH] Add more test cases for validation in Fault.add_record --- python/tests/rd_tests/test_faults.py | 144 ++++++++++++++++----------- 1 file changed, 86 insertions(+), 58 deletions(-) diff --git a/python/tests/rd_tests/test_faults.py b/python/tests/rd_tests/test_faults.py index abf5dab6a..a8e0f9627 100644 --- a/python/tests/rd_tests/test_faults.py +++ b/python/tests/rd_tests/test_faults.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -from unittest import skipIf -import time +import pytest + from resdata import util from resdata import ResDataType @@ -21,7 +21,7 @@ class FaultTest(ResdataTest): @classmethod def setUpClass(cls): - cls.grid = Grid.createRectangular((151, 100, 50), (1, 1, 1)) + cls.grid = Grid.create_rectangular((151, 100, 50), (1, 1, 1)) def setUp(self): self.faults1 = self.createTestPath("local/ECLIPSE/FAULTS/fault1.grdecl") @@ -31,13 +31,13 @@ def test_PolylineIJ(self): nx = 10 ny = 10 nz = 10 - grid = Grid.createRectangular((nx, ny, nz), (0.1, 0.1, 0.1)) + grid = Grid.create_rectangular((nx, ny, nz), (0.1, 0.1, 0.1)) f = Fault(grid, "F") - f.addRecord(0, 1, 0, 0, 0, 0, "Y-") - f.addRecord(2, 2, 0, 1, 0, 0, "X-") - f.addRecord(2, 2, 1, 1, 0, 0, "Y") + f.add_record(0, 1, 0, 0, 0, 0, "Y-") + f.add_record(2, 2, 0, 1, 0, 0, "X-") + f.add_record(2, 2, 1, 1, 0, 0, "Y") - pl = f.getIJPolyline(0) + pl = f.get_ij_polyline(0) self.assertEqual(pl, [(0, 0), (2, 0), (2, 2), (3, 2)]) def test_empty_collection(self): @@ -47,13 +47,13 @@ def test_empty_collection(self): self.assertFalse(faults.hasFault("FX")) with self.assertRaises(TypeError): - f = faults[[]] + _ = faults[[]] with self.assertRaises(KeyError): - f = faults["FX"] + _ = faults["FX"] with self.assertRaises(IndexError): - f = faults[0] + _ = faults[0] self.assertFalse("NAME" in faults) @@ -112,7 +112,7 @@ def test_faultLine_center(self): nx = 10 ny = 10 nz = 2 - grid = Grid.createRectangular((nx, ny, nz), (0.1, 0.1, 0.1)) + grid = Grid.create_rectangular((nx, ny, nz), (0.1, 0.1, 0.1)) fl = FaultLine(grid, 0) C1 = (nx + 1) * 5 + 3 C2 = C1 + 2 @@ -191,7 +191,7 @@ def test_load(self): faults.load(self.grid, "No/this/does/not/exist") def test_connect_faults(self): - grid = Grid.createRectangular((100, 100, 10), (1, 1, 1)) + grid = Grid.create_rectangular((100, 100, 10), (1, 1, 1)) # Fault1 Fault4 # | | @@ -209,10 +209,10 @@ def test_connect_faults(self): fault3 = Fault(grid, "Fault3") fault4 = Fault(grid, "Fault4") - fault1.addRecord(1, 1, 10, grid.getNY() - 1, 0, 0, "X") - fault2.addRecord(5, 10, 15, 15, 0, 0, "Y") - fault3.addRecord(5, 10, 5, 5, 0, 0, "Y") - fault4.addRecord(20, 20, 10, grid.getNY() - 1, 0, 0, "X") + fault1.add_record(1, 1, 10, grid.get_ny() - 1, 0, 0, "X") + fault2.add_record(5, 10, 15, 15, 0, 0, "Y") + fault3.add_record(5, 10, 5, 5, 0, 0, "Y") + fault4.add_record(20, 20, 10, grid.get_ny() - 1, 0, 0, "X") for other_fault in [fault2, fault3, fault4]: with self.assertRaises(ValueError): @@ -342,7 +342,7 @@ def test_intersect_intRays(self): self.assertEqual(join, [p1, p2]) def test_join_faults(self): - grid = Grid.createRectangular((100, 100, 10), (1, 1, 1)) + grid = Grid.create_rectangular((100, 100, 10), (1, 1, 1)) # Fault1 Fault4 # | | @@ -360,10 +360,10 @@ def test_join_faults(self): fault3 = Fault(grid, "Fault3") fault4 = Fault(grid, "Fault4") - fault1.addRecord(1, 1, 10, grid.getNY() - 1, 0, 0, "X") - fault2.addRecord(5, 10, 15, 15, 0, 0, "Y") - fault3.addRecord(5, 10, 5, 5, 0, 0, "Y") - fault4.addRecord(20, 20, 10, grid.getNY() - 1, 0, 0, "X") + fault1.add_record(1, 1, 10, grid.get_ny() - 1, 0, 0, "X") + fault2.add_record(5, 10, 15, 15, 0, 0, "Y") + fault3.add_record(5, 10, 5, 5, 0, 0, "Y") + fault4.add_record(20, 20, 10, grid.get_ny() - 1, 0, 0, "X") rays = fault1.getEndRays(0) self.assertEqual(rays[0], [(2, 10), (0, -1)]) @@ -373,7 +373,7 @@ def test_join_faults(self): self.assertEqual(extra, [(2, 10), (2, 6), (5, 6)]) def test_contact(self): - grid = Grid.createRectangular((100, 100, 10), (1, 1, 1)) + grid = Grid.create_rectangular((100, 100, 10), (1, 1, 1)) # Fault1 Fault4 # | | @@ -391,10 +391,10 @@ def test_contact(self): fault3 = Fault(grid, "Fault3") fault4 = Fault(grid, "Fault4") - fault1.addRecord(1, 1, 10, grid.getNY() - 1, 0, 0, "X") - fault2.addRecord(5, 30, 15, 15, 0, 0, "Y") - fault3.addRecord(2, 10, 9, 9, 0, 0, "Y") - fault4.addRecord(20, 20, 10, grid.getNY() - 1, 0, 0, "X") + fault1.add_record(1, 1, 10, grid.get_ny() - 1, 0, 0, "X") + fault2.add_record(5, 30, 15, 15, 0, 0, "Y") + fault3.add_record(2, 10, 9, 9, 0, 0, "Y") + fault4.add_record(20, 20, 10, grid.get_ny() - 1, 0, 0, "X") # self.assertFalse( fault1.intersectsFault(fault2 , 0) ) # self.assertFalse( fault2.intersectsFault(fault1 , 0) ) @@ -421,35 +421,63 @@ def test_iter(self): def test_fault(self): f = Fault(self.grid, "NAME") - with self.assertRaises(ValueError): + with pytest.raises(ValueError, match="Invalid face:F"): # Invalid face - f.addRecord(10, 10, 11, 11, 1, 43, "F") + f.add_record(10, 10, 11, 11, 1, 43, "F") - with self.assertRaises(ValueError): + with pytest.raises(ValueError, match="Invalid I1:-1"): # Invalid coordinates - f.addRecord(-1, 10, 11, 11, 1, 43, "X") + f.add_record(-1, 10, 11, 11, 1, 43, "X") - with self.assertRaises(ValueError): + with pytest.raises(ValueError, match="Invalid I1:10000"): # Invalid coordinates - f.addRecord(10000, 10, 11, 11, 1, 43, "X") + f.add_record(10000, 100000, 11, 11, 1, 43, "X") - with self.assertRaises(ValueError): + with pytest.raises(ValueError, match="Invalid I2:10002"): # Invalid coordinates - f.addRecord(10, 9, 11, 11, 1, 43, "X") + f.add_record(10, 10002, 11, 11, 1, 43, "X") - with self.assertRaises(ValueError): + with pytest.raises(ValueError, match="Invalid J1:-11"): # Invalid coordinates - f.addRecord(10, 9, 11, 11, 1, 43, "X") + f.add_record(10, 10, -11, 11, 1, 43, "X") - with self.assertRaises(ValueError): + with pytest.raises(ValueError, match="Invalid J2:11110"): + # Invalid coordinates + f.add_record(10, 10, 11, 11110, 1, 43, "X") + + with pytest.raises(ValueError, match="Invalid K1:-11"): + # Invalid coordinates + f.add_record(10, 10, 11, 11, -11, 43, "X") + + with pytest.raises(ValueError, match="Invalid K2:43000"): + # Invalid coordinates + f.add_record(10, 10, 11, 11, 1, 43000, "X") + + with pytest.raises(ValueError, match="Invalid I1 I2 indices"): + # Invalid coordinates + f.add_record(10, 9, 11, 11, 1, 43, "X") + + with pytest.raises(ValueError, match="Invalid J1 J2 indices"): + # Invalid coordinates + f.add_record(8, 9, 12, 11, 1, 43, "X") + + with pytest.raises(ValueError, match="Invalid K1 K2 indices"): + # Invalid coordinates + f.add_record(8, 9, 11, 11, 100, 43, "X") + + with pytest.raises(ValueError, match="For face:X we must have I1 == I2"): # Invalid coordinates/face combination - f.addRecord(10, 11, 11, 11, 1, 43, "X") + f.add_record(10, 11, 11, 11, 1, 43, "X") - with self.assertRaises(ValueError): + with pytest.raises(ValueError, match="For face:Y we must have J1 == J2"): + # Invalid coordinates/face combination + f.add_record(10, 11, 11, 12, 1, 43, "Y") + + with pytest.raises(ValueError, match="For face:K we must have K1 == K2"): # Invalid coordinates/face combination - f.addRecord(10, 11, 11, 12, 1, 43, "Y") + f.add_record(10, 11, 11, 12, 1, 43, "K") - f.addRecord(10, 10, 0, 10, 1, 10, "X") + f.add_record(10, 10, 0, 10, 1, 10, "X") def test_segment(self): s0 = FaultSegment(0, 10) @@ -471,7 +499,7 @@ def test_fault_line_order(self): nx = 120 ny = 60 nz = 43 - grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1)) + grid = Grid.create_rectangular((nx, ny, nz), (1, 1, 1)) with TestAreaContext("python/faults/line_order"): with open("faults.grdecl", "w") as f: f.write( @@ -509,7 +537,7 @@ def test_neighbour_cells(self): nx = 10 ny = 8 nz = 7 - grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1)) + grid = Grid.create_rectangular((nx, ny, nz), (1, 1, 1)) faults_file = self.createTestPath("local/ECLIPSE/FAULTS/faults_nb.grdecl") faults = FaultCollection(grid, faults_file) @@ -570,7 +598,7 @@ def test_neighbour_cells(self): self.assertListEqual(nb_cells1, true_nb_cells1) def test_polyline_intersection(self): - grid = Grid.createRectangular((100, 100, 10), (0.25, 0.25, 1)) + grid = Grid.create_rectangular((100, 100, 10), (0.25, 0.25, 1)) # Fault1 Fault4 # | | @@ -588,10 +616,10 @@ def test_polyline_intersection(self): fault3 = Fault(grid, "Fault3") fault4 = Fault(grid, "Fault4") - fault1.addRecord(1, 1, 10, grid.getNY() - 1, 0, 0, "X") - fault2.addRecord(5, 10, 15, 15, 0, 0, "Y") - fault3.addRecord(5, 10, 5, 5, 0, 0, "Y") - fault4.addRecord(20, 20, 10, grid.getNY() - 1, 0, 0, "X") + fault1.add_record(1, 1, 10, grid.get_ny() - 1, 0, 0, "X") + fault2.add_record(5, 10, 15, 15, 0, 0, "Y") + fault3.add_record(5, 10, 5, 5, 0, 0, "Y") + fault4.add_record(20, 20, 10, grid.get_ny() - 1, 0, 0, "X") polyline = Polyline(init_points=[(4, 4), (8, 4)]) self.assertTrue(fault4.intersectsPolyline(polyline, 0)) @@ -609,7 +637,7 @@ def test_num_linesegment(self): nx = 10 ny = 10 nz = 1 - grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1)) + grid = Grid.create_rectangular((nx, ny, nz), (1, 1, 1)) with TestAreaContext("python/faults/line_order"): with open("faults.grdecl", "w") as f: f.write( @@ -628,7 +656,7 @@ def test_num_linesegment(self): self.assertEqual(1, f2.numLines(0)) def test_extend_to_polyline(self): - grid = Grid.createRectangular((3, 3, 1), (1, 1, 1)) + grid = Grid.create_rectangular((3, 3, 1), (1, 1, 1)) # o o o o # @@ -640,8 +668,8 @@ def test_extend_to_polyline(self): fault1 = Fault(grid, "Fault") - fault1.addRecord(0, 0, 0, 0, 0, 0, "X-") - fault1.addRecord(0, 0, 0, 0, 0, 0, "Y") + fault1.add_record(0, 0, 0, 0, 0, 0, "X-") + fault1.add_record(0, 0, 0, 0, 0, 0, "Y") polyline = CPolyline(init_points=[(0, 2), (3, 2)]) points = fault1.extendToPolyline(polyline, 0) @@ -655,7 +683,7 @@ def test_extend_to_polyline(self): self.assertIsNone(end_join) def test_extend_polyline_on(self): - grid = Grid.createRectangular((3, 3, 1), (1, 1, 1)) + grid = Grid.create_rectangular((3, 3, 1), (1, 1, 1)) # o o o o # @@ -666,7 +694,7 @@ def test_extend_polyline_on(self): # o o o o fault1 = Fault(grid, "Fault") - fault1.addRecord(0, 2, 0, 0, 0, 0, "Y") + fault1.add_record(0, 2, 0, 0, 0, 0, "Y") polyline0 = CPolyline(init_points=[(0, 2)]) polyline1 = CPolyline(init_points=[(0, 2), (3, 2)]) @@ -686,13 +714,13 @@ def test_extend_polyline_on(self): self.assertIsNone(points) def test_stepped(self): - grid = Grid.createRectangular((6, 1, 4), (1, 1, 1)) + grid = Grid.create_rectangular((6, 1, 4), (1, 1, 1)) f = Fault(grid, "F") f.addRecord(4, 4, 0, 0, 0, 1, "X") f.addRecord(2, 2, 0, 0, 1, 1, "Z") f.addRecord(1, 1, 0, 0, 2, 3, "X") - block_kw = ResdataKW("FAULTBLK", grid.getGlobalSize(), ResDataType.RD_INT) + block_kw = ResdataKW("FAULTBLK", grid.get_global_size(), ResDataType.RD_INT) block_kw.assign(1) block_kw[5] = 2 block_kw[11] = 2 @@ -725,7 +753,7 @@ def test_stepped(self): self.assertFalse(layer3.cellContact((1, 0), (2, 0))) def test_connectWithPolyline(self): - grid = Grid.createRectangular((4, 4, 1), (1, 1, 1)) + grid = Grid.create_rectangular((4, 4, 1), (1, 1, 1)) # o o o o o #