Skip to content

Commit a618e53

Browse files
committed
doc: modified more test files
1 parent 406421f commit a618e53

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

tests/test_code_docstrings.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,44 +28,43 @@
2828

2929
import doctest
3030
import os
31-
import pathlib
31+
from pathlib import Path
3232

3333
import pytest
3434

3535

3636
@pytest.mark.skipif(True, reason="examples are created for windows")
3737
def test_doctest_allfiles():
3838
directory = r"../ansys/dpf/core"
39-
actual_path = pathlib.Path(__file__).parent.absolute()
40-
# actual_path = os.getcwd()
39+
actual_path = Path(__file__).parent.absolute()
4140
print(actual_path)
42-
for filename in os.listdir(os.path.join(actual_path, directory)):
41+
for filename in os.listdir(actual_path / directory):
4342
if filename.endswith(".py"):
44-
path = os.path.join(directory, filename)
43+
path = Path(directory) / filename
4544
print(path)
46-
doctest.testfile(path, verbose=True, raise_on_error=True)
45+
doctest.testfile(str(path), verbose=True, raise_on_error=True)
4746
else:
4847
continue
4948

5049

5150
@pytest.mark.skipif(True, reason="examples are created for windows")
5251
def test_doctest_allexamples():
5352
directory = r"../examples"
54-
actual_path = pathlib.Path(__file__).parent.absolute()
53+
actual_path = Path(__file__).parent.absolute()
5554
handled_files = []
56-
for root, subdirectories, files in os.walk(os.path.join(actual_path, directory)):
55+
for root, subdirectories, files in os.walk(actual_path / directory):
5756
for subdirectory in subdirectories:
58-
subdir = os.path.join(root, subdirectory)
57+
subdir = Path(root) / subdirectory
5958
print(subdir)
6059
for filename in os.listdir(subdir):
6160
if filename.endswith(".py"):
62-
path = os.path.join(subdir, filename)
63-
if ".ipynb_checkpoints" in path:
61+
path = subdir / filename
62+
if ".ipynb_checkpoints" in str(path):
6463
continue
6564
print(path)
66-
handled_files.append(path)
65+
handled_files.append(str(path))
6766
exec(
68-
open(path, mode="r", encoding="utf8").read(),
67+
path.read_text(encoding="utf-8"),
6968
globals(),
7069
globals(),
7170
)

tests/test_codegeneration.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import os
2525
import copy
2626
import tempfile
27+
from pathlib import Path
2728

2829
import ansys.grpc.dpf
2930
import numpy as np
@@ -153,7 +154,7 @@ def test_operator_any_input(allkindofcomplexity):
153154
serialization.inputs.any_input3.connect(u.outputs)
154155

155156
# create a temporary file at the default temp directory
156-
path = os.path.join(tempfile.gettempdir(), "dpf_temp_ser.txt")
157+
path = str(Path(tempfile.gettempdir()) / "dpf_temp_ser.txt")
157158
if not core.SERVER.local_server:
158159
core.upload_file_in_tmp_folder(examples.find_static_rst(return_local_path=True))
159160
path = core.path_utilities.join(core.make_tmp_dir_server(), "dpf_temp_ser.txt")
@@ -171,8 +172,9 @@ def test_operator_any_input(allkindofcomplexity):
171172

172173
assert hasattr(fc, "outputs") == False
173174

174-
if os.path.exists(path):
175-
os.remove(path)
175+
path = Path(path)
176+
if path.exists():
177+
path.unlink()
176178

177179

178180
def test_create_op_with_inputs(plate_msup):

tests/test_data_tree.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import os
2525
import pytest
2626
import conftest
27+
from pathlib import Path
2728

2829

2930
@conftest.raises_for_servers_version_under("4.0")
@@ -174,16 +175,16 @@ def test_write_to_file_data_tree(tmpdir, server_type):
174175
to_fill.list_int = [1, 2]
175176
to_fill.list_double = [1.5, 2.5]
176177
to_fill.list_string = ["hello", "bye"]
177-
data_tree.write_to_txt(os.path.join(tmpdir, "file.txt"))
178-
data_tree = dpf.DataTree.read_from_txt(os.path.join(tmpdir, "file.txt"), server=server_type)
178+
data_tree.write_to_txt(str(Path(tmpdir) / "file.txt"))
179+
data_tree = dpf.DataTree.read_from_txt(str(Path(tmpdir) / "file.txt"), server=server_type)
179180
assert data_tree.has("int")
180181
assert data_tree.has("double")
181182
assert data_tree.has("string")
182183
assert data_tree.has("list_int")
183184
assert data_tree.has("list_double")
184185
assert data_tree.has("list_string")
185-
data_tree.write_to_json(os.path.join(tmpdir, "file.json"))
186-
data_tree = dpf.DataTree.read_from_json(os.path.join(tmpdir, "file.json"), server=server_type)
186+
data_tree.write_to_json(str(Path(tmpdir) / "file.json"))
187+
data_tree = dpf.DataTree.read_from_json(str(Path(tmpdir) / "file.json"), server=server_type)
187188
assert data_tree.has("int")
188189
assert data_tree.has("double")
189190
assert data_tree.has("string")
@@ -207,19 +208,19 @@ def test_write_to_file_remote_data_tree(tmpdir, server_clayer_remote_process):
207208
to_fill.list_int = [1, 2]
208209
to_fill.list_double = [1.5, 2.5]
209210
to_fill.list_string = ["hello", "bye"]
210-
data_tree.write_to_txt(os.path.join(tmpdir, "file.txt"))
211+
data_tree.write_to_txt(str(Path(tmpdir) / "file.txt"))
211212
data_tree = dpf.DataTree.read_from_txt(
212-
os.path.join(tmpdir, "file.txt"), server=server_connected
213+
str(Path(tmpdir) / "file.txt"), server=server_connected
213214
)
214215
assert data_tree.has("int")
215216
assert data_tree.has("double")
216217
assert data_tree.has("string")
217218
assert data_tree.has("list_int")
218219
assert data_tree.has("list_double")
219220
assert data_tree.has("list_string")
220-
data_tree.write_to_json(os.path.join(tmpdir, "file.json"))
221+
data_tree.write_to_json(str(Path(tmpdir) / "file.json"))
221222
data_tree = dpf.DataTree.read_from_json(
222-
os.path.join(tmpdir, "file.json"), server=server_connected
223+
str(Path(tmpdir) / "file.json"), server=server_connected
223224
)
224225
assert data_tree.has("int")
225226
assert data_tree.has("double")

0 commit comments

Comments
 (0)