Skip to content

Commit fbd6aa5

Browse files
committed
[ENH] Getting verify to open windows pycharm
1 parent bfb8a5b commit fbd6aa5

File tree

2 files changed

+40
-23
lines changed

2 files changed

+40
-23
lines changed

test/test_modules/test_serialize_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
def test_generate_horizontal_stratigraphic_model():
1212
model: gp.data.GeoModel = gp.generate_example_model(ExampleModel.HORIZONTAL_STRAT, compute_model=False)
13-
model_json = model.model_dump_json(by_alias=True)
13+
model_json = model.model_dump_json(by_alias=True, indent=4)
1414

1515
# Write the JSON to disk
1616
file_path = os.path.join("temp", "horizontal_stratigraphic_model.json")
@@ -34,7 +34,7 @@ def test_generate_horizontal_stratigraphic_model():
3434
assert model_deserialized.__str__() == model.__str__()
3535

3636
# # Validate json against schema
37-
if False:
37+
if True:
3838
# Ensure the 'verify/' directory exists
3939
os.makedirs("verify", exist_ok=True)
4040
verify_json(model_json, name="verify/Horizontal Stratigraphic Model serialization")

test/verify_helper.py

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,56 @@
1+
import subprocess
2+
13
import numpy as np
24
from approvaltests.core import Comparator
35
from approvaltests.namer import NamerFactory
46

7+
import json
8+
from approvaltests import verify, Options
9+
from approvaltests.namer import NamerFactory
10+
from approvaltests.reporters import GenericDiffReporter, GenericDiffReporterConfig
11+
12+
13+
class WSLWindowsDiffReporter(GenericDiffReporter):
14+
def get_command(self, received, approved):
15+
# Convert WSL paths to Windows paths
16+
win_received = subprocess.check_output(['wslpath', '-w', received]).decode().strip()
17+
win_approved = subprocess.check_output(['wslpath', '-w', approved]).decode().strip()
18+
19+
cmd = [self.path] + self.extra_args + [win_received, win_approved]
20+
return cmd
21+
22+
def verify_json(item, name: str):
23+
24+
config = GenericDiffReporterConfig(
25+
name="custom",
26+
path=r"pycharm",
27+
extra_args= ["diff"]
28+
)
29+
30+
parameters: Options = NamerFactory \
31+
.with_parameters(name) \
32+
.with_reporter(
33+
reporter=(WSLWindowsDiffReporter(config))
34+
)
35+
36+
verify(item, options=parameters)
37+
538

639
def gempy_verify_array(item, name: str, rtol: float = 1e-5, atol: float = 1e-5, ):
740
# ! You will have to set the path to your diff tool
841
reporter = GenericDiffReporter.create(
942
diff_tool_path=r"/usr/bin/meld"
1043
)
11-
44+
1245
parameters: Options = NamerFactory \
1346
.with_parameters(name) \
1447
.with_comparator(
15-
comparator=ArrayComparator(atol=atol, rtol=rtol)
16-
).with_reporter(
17-
reporter=reporter
48+
comparator=ArrayComparator(atol=atol, rtol=rtol)
49+
).with_reporter(
50+
reporter=reporter
1851
)
19-
20-
21-
verify(np.asarray(item), options=parameters)
2252

23-
def verify_json(item, name: str):
24-
parameters: Options = NamerFactory \
25-
.with_parameters(name) \
26-
.with_reporter(
27-
reporter=GenericDiffReporter.create(
28-
diff_tool_path=r"/usr/bin/meld"
29-
)
30-
)
31-
32-
verify(item, options=parameters)
53+
verify(np.asarray(item), options=parameters)
3354

3455

3556
class ArrayComparator(Comparator):
@@ -66,10 +87,6 @@ def compare(self, received_path: str, approved_path: str) -> bool:
6687
return allclose
6788
except BaseException:
6889
return False
69-
import json
70-
from approvaltests import verify, Options
71-
from approvaltests.namer import NamerFactory
72-
from approvaltests.reporters import GenericDiffReporter
7390

7491
class JsonSerializer:
7592
"""Serializer that writes JSON with an indent and declares its own extension."""

0 commit comments

Comments
 (0)