Skip to content

Commit fd0728e

Browse files
committed
Small changes to make the code compàtible with python 3.10
1 parent 1479adf commit fd0728e

4 files changed

Lines changed: 18 additions & 10 deletions

File tree

simulaqron/settings/network_config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import socket
44
from contextlib import closing
55
from dataclasses import dataclass, field, fields
6-
from enum import StrEnum
76
from importlib import resources
87
from os import PathLike
98
from pathlib import Path
10-
from typing import Optional, Self, Dict, List, Tuple, Any
9+
from strenum import StrEnum
10+
from typing import Optional, Dict, List, Tuple, Any
11+
from typing_extensions import Self
1112

1213
from dataclasses_serialization.json import JSONSerializer, JSONSerializerMixin
1314

simulaqron/settings/simulaqron_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from enum import Enum
3636
from os import PathLike
3737
from pathlib import Path
38-
from typing import Self
38+
from typing_extensions import Self
3939

4040
from dataclasses_serialization.json import JSONSerializer
4141
from dataclasses_serialization.json import JSONSerializerMixin

tests/quick/settings/test_networks_settings.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ class TestNetworksSettings:
2121
def clean_settings(self):
2222
# Load the setting files in cwd and home, saved them in a temp file
2323
if cwd_network.is_file() and cwd_network.is_file():
24-
orig_cwd_network = NamedTemporaryFile(suffix=".json", mode="w", delete_on_close=False).__enter__()
24+
orig_cwd_network = NamedTemporaryFile(suffix=".json", mode="w", delete=False).__enter__()
2525
shutil.copyfile(cwd_network, orig_cwd_network.name)
2626
cwd_network.unlink()
2727
else:
2828
orig_cwd_network = None
2929
if home_network.is_file() and home_network.is_file():
30-
orig_home_network = NamedTemporaryFile(suffix=".json", mode="w", delete_on_close=False).__enter__()
30+
orig_home_network = NamedTemporaryFile(suffix=".json", mode="w", delete=False).__enter__()
3131
shutil.copyfile(home_network, orig_home_network.name)
3232
home_network.unlink()
3333
else:
@@ -39,10 +39,12 @@ def clean_settings(self):
3939
cwd_network.touch()
4040
shutil.copyfile(orig_cwd_network.name, cwd_network)
4141
orig_cwd_network.__exit__(None, None, None)
42+
Path(orig_cwd_network.name).unlink()
4243
if orig_home_network is not None:
4344
home_network.touch()
4445
shutil.copyfile(orig_home_network.name, home_network)
4546
orig_home_network.__exit__(None, None, None)
47+
Path(orig_home_network.name).unlink()
4648

4749
files_to_check = [cwd_network, home_network]
4850
for file in files_to_check:
@@ -243,27 +245,29 @@ def test_serialize_network_config(self, reset_net_cfg):
243245

244246
expected_network_config = TestNetworksSettings._build_expected_config(alice_ports, bob_ports)
245247

246-
with NamedTemporaryFile(mode="wt", delete_on_close=False) as temp_file:
248+
with NamedTemporaryFile(mode="wt", delete=False) as temp_file:
247249
network_config.write_to_file(temp_file.name)
248250
temp_file.flush()
249251

250252
serialized_content = Path(temp_file.name).read_text()
251253
assert serialized_content == expected_network_config
254+
Path(temp_file.name).unlink()
252255

253256
def test_deserialize_network_config(self, reset_net_cfg):
254257
raw_config = TestNetworksSettings._build_expected_config([8020, 8021, 8022], [8050, 8051, 8052])
255-
with NamedTemporaryFile(mode="wt", delete_on_close=False) as temp_file:
258+
with NamedTemporaryFile(mode="wt", delete=False) as temp_file:
256259
temp_file.write(raw_config)
257260
temp_file.flush()
258261

259262
network_config.read_from_file(temp_file.name)
260263
assert json.dumps(JSONSerializer.serialize(network_config), indent=4) == raw_config
264+
Path(temp_file.name).unlink()
261265

262266
def test_load_old_json_format(self):
263267
this_file_folder = Path(__file__).parent
264268
old_json_config_path = this_file_folder / "resources" / "old_format.json"
265269

266-
with NamedTemporaryFile(mode="wt", delete_on_close=False) as temp_file:
270+
with NamedTemporaryFile(mode="wt", delete=False) as temp_file:
267271
# We copy the content of the resource into a temp file, so we don't
268272
# overwrite the resource for future test sessions
269273
shutil.copy(old_json_config_path, temp_file.name)
@@ -294,3 +298,4 @@ def test_load_old_json_format(self):
294298
assert network_config.nodes[1].qnodeos_port == 8832
295299
assert network_config.nodes[1].vnode_hostname == "localhost"
296300
assert network_config.nodes[1].vnode_port == 8833
301+
Path(temp_file.name).unlink()

tests/quick/settings/test_simulaqron_settings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ class TestSettings:
1919
def clean_settings(self):
2020
# Load the setting files in cwd and home, saved them in a temp file
2121
if cwd_settings.exists() and cwd_settings.is_file():
22-
orig_cwd_settings = NamedTemporaryFile(suffix=".json", mode="w", delete_on_close=False).__enter__()
22+
orig_cwd_settings = NamedTemporaryFile(suffix=".json", mode="w", delete=False).__enter__()
2323
shutil.copyfile(cwd_settings, orig_cwd_settings.name)
2424
cwd_settings.unlink()
2525
else:
2626
orig_cwd_settings = None
2727
if home_settings.exists() and home_settings.is_file():
28-
orig_home_settings = NamedTemporaryFile(suffix=".json", mode="w", delete_on_close=False).__enter__()
28+
orig_home_settings = NamedTemporaryFile(suffix=".json", mode="w", delete=False).__enter__()
2929
shutil.copyfile(home_settings, orig_home_settings.name)
3030
home_settings.unlink()
3131
else:
@@ -37,10 +37,12 @@ def clean_settings(self):
3737
cwd_settings.touch()
3838
shutil.copyfile(orig_cwd_settings.name, cwd_settings)
3939
orig_cwd_settings.__exit__(None, None, None)
40+
Path(orig_cwd_settings.name).unlink()
4041
if orig_home_settings is not None:
4142
home_settings.touch()
4243
shutil.copyfile(orig_home_settings.name, home_settings)
4344
orig_home_settings.__exit__(None, None, None)
45+
Path(orig_home_settings.name).unlink()
4446

4547
@staticmethod
4648
def _cleanup_config_files():

0 commit comments

Comments
 (0)