Skip to content

Commit 79a3be1

Browse files
committed
refactor: move fault dip display tests to a new file and update structure
1 parent 21b82ab commit 79a3be1

File tree

2 files changed

+147
-164
lines changed

2 files changed

+147
-164
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#! python3
2+
3+
"""Test fault dip display in the Geological Features panel.
4+
5+
Usage from the repo root folder:
6+
7+
.. code-block:: bash
8+
# for whole tests
9+
python -m pytest tests/qgis/test_fault_dip_display.py
10+
# for specific test
11+
python -m pytest tests/qgis/test_fault_dip_display.py::test_dip_from_stored_data
12+
"""
13+
14+
import unittest
15+
from unittest.mock import MagicMock, Mock
16+
import pandas as pd
17+
import numpy as np
18+
19+
20+
class TestFaultDipDisplay(unittest.TestCase):
21+
"""Test fault dip retrieval and display."""
22+
23+
def setUp(self):
24+
"""Set up mock objects for testing."""
25+
# Mock the fault object
26+
self.mock_fault = Mock()
27+
self.mock_fault.name = "TestFault"
28+
self.mock_fault.displacement = 100
29+
self.mock_fault.fault_major_axis = 500
30+
self.mock_fault.fault_minor_axis = 300
31+
self.mock_fault.fault_intermediate_axis = 400
32+
33+
# Mock fault_normal_vector that would give a dip of 90 (vertical fault)
34+
self.mock_fault.fault_normal_vector = np.array([1.0, 0.0, 0.0])
35+
36+
# Mock the model manager
37+
self.mock_model_manager = Mock()
38+
self.mock_model_manager.faults = {}
39+
40+
def test_dip_from_stored_data(self):
41+
"""Test that dip is retrieved from stored fault data when available."""
42+
# Create fault data with a dip of 45 degrees
43+
fault_data = pd.DataFrame({
44+
'X': [0, 1, 2],
45+
'Y': [0, 1, 2],
46+
'Z': [0, 0, 0],
47+
'dip': [45, 45, 45]
48+
})
49+
50+
self.mock_model_manager.faults['TestFault'] = {'data': fault_data}
51+
52+
from loopstructural.gui.modelling.geological_model_tab.feature_details_panel import (
53+
FaultFeatureDetailsPanel
54+
)
55+
56+
# Create the panel - this should retrieve dip from stored data
57+
panel = FaultFeatureDetailsPanel(
58+
parent=None,
59+
fault=self.mock_fault,
60+
model_manager=self.mock_model_manager,
61+
data_manager=None
62+
)
63+
64+
# Check that the dip was retrieved from stored data (45 degrees)
65+
# not from the normal vector calculation (which would be 90 degrees)
66+
self.assertEqual(panel.fault_parameters['dip'], 45)
67+
68+
def test_dip_fallback_to_normal_vector(self):
69+
"""Test that dip falls back to normal vector calculation when not in stored data."""
70+
# No stored dip data
71+
fault_data = pd.DataFrame({
72+
'X': [0, 1, 2],
73+
'Y': [0, 1, 2],
74+
'Z': [0, 0, 0]
75+
})
76+
77+
self.mock_model_manager.faults['TestFault'] = {'data': fault_data}
78+
79+
from loopstructural.gui.modelling.geological_model_tab.feature_details_panel import (
80+
FaultFeatureDetailsPanel
81+
)
82+
from LoopStructural.utils import normal_vector_to_strike_and_dip
83+
84+
# Calculate expected dip from normal vector
85+
expected_dip = normal_vector_to_strike_and_dip(self.mock_fault.fault_normal_vector)[0, 1]
86+
87+
panel = FaultFeatureDetailsPanel(
88+
parent=None,
89+
fault=self.mock_fault,
90+
model_manager=self.mock_model_manager,
91+
data_manager=None
92+
)
93+
94+
# Should fall back to calculating from normal vector
95+
self.assertEqual(panel.fault_parameters['dip'], expected_dip)
96+
97+
def test_dip_default_when_no_data(self):
98+
"""Test that dip defaults to 90 when no fault data exists."""
99+
# No fault data at all
100+
self.mock_model_manager.faults = {}
101+
102+
from loopstructural.gui.modelling.geological_model_tab.feature_details_panel import (
103+
FaultFeatureDetailsPanel
104+
)
105+
106+
panel = FaultFeatureDetailsPanel(
107+
parent=None,
108+
fault=self.mock_fault,
109+
model_manager=self.mock_model_manager,
110+
data_manager=None
111+
)
112+
113+
# Should use a reasonable default or calculate from normal vector
114+
self.assertIsInstance(panel.fault_parameters['dip'], (int, float))
115+
self.assertGreaterEqual(panel.fault_parameters['dip'], 0)
116+
self.assertLessEqual(panel.fault_parameters['dip'], 90)
117+
118+
def test_pitch_from_stored_data(self):
119+
"""Test that pitch is also retrieved from stored fault data when available."""
120+
# Create fault data with pitch
121+
fault_data = pd.DataFrame({
122+
'X': [0, 1, 2],
123+
'Y': [0, 1, 2],
124+
'Z': [0, 0, 0],
125+
'dip': [45, 45, 45],
126+
'pitch': [30, 30, 30]
127+
})
128+
129+
self.mock_model_manager.faults['TestFault'] = {'data': fault_data}
130+
131+
from loopstructural.gui.modelling.geological_model_tab.feature_details_panel import (
132+
FaultFeatureDetailsPanel
133+
)
134+
135+
panel = FaultFeatureDetailsPanel(
136+
parent=None,
137+
fault=self.mock_fault,
138+
model_manager=self.mock_model_manager,
139+
data_manager=None
140+
)
141+
142+
# Check that pitch was retrieved from stored data
143+
self.assertEqual(panel.fault_parameters['pitch'], 30)
144+
145+
146+
if __name__ == "__main__":
147+
unittest.main()

tests/unit/test_fault_dip_display.py

Lines changed: 0 additions & 164 deletions
This file was deleted.

0 commit comments

Comments
 (0)