Skip to content

Commit

Permalink
Fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tanertopal committed Jun 16, 2024
1 parent b06d6cd commit 5f57946
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/py/flwr/server/superlink/ffs/disk_ffs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@

def write_dict_to_file(data_dict: Dict[str, str], file_path: str) -> None:
"""Write a Dict to a file in JSON format."""
with open(file_path, "w") as file:
with open(file_path, "w", encoding="utf-8") as file:
json.dump(data_dict, file)


def read_dict_from_file(file_path: str) -> Dict[str, str]:
"""Read a Dict from a JSON file."""
with open(file_path) as file:
data_dict = json.load(file)
with open(file_path, encoding="utf-8") as file:
data_dict: Dict[str, str] = json.load(file)
return data_dict


Expand Down
21 changes: 15 additions & 6 deletions src/py/flwr/server/superlink/ffs/ffs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import tempfile
import unittest
from abc import abstractmethod
from typing import Dict

from flwr.server.superlink.ffs import DiskFfs, Ffs

Expand All @@ -31,6 +32,8 @@ class FfsTest(unittest.TestCase):
# This is to True in each child class
__test__ = False

tmp_dir: tempfile.TemporaryDirectory # type: ignore

@abstractmethod
def ffs_factory(self) -> Ffs:
"""Provide Ffs implementation to test."""
Expand Down Expand Up @@ -60,13 +63,15 @@ def test_get(self) -> None:
ffs: Ffs = self.ffs_factory()
content_expected = b"content"
hash_expected = hashlib.sha256(content_expected).hexdigest()
meta_expected = {}
meta_expected: Dict[str, str] = {"meta_key": "meta_value"}

with open(os.path.join(self.tmp_dir.name, hash_expected), "wb") as file:
file.write(content_expected)

with open(
os.path.join(self.tmp_dir.name, f"{hash_expected}.META"), "w"
os.path.join(self.tmp_dir.name, f"{hash_expected}.META"),
"w",
encoding="utf-8",
) as file:
json.dump(meta_expected, file)

Expand All @@ -83,13 +88,15 @@ def test_delete(self) -> None:
ffs: Ffs = self.ffs_factory()
content_expected = b"content"
hash_expected = hashlib.sha256(content_expected).hexdigest()
meta_expected = {}
meta_expected: Dict[str, str] = {"meta_key": "meta_value"}

with open(os.path.join(self.tmp_dir.name, hash_expected), "wb") as file:
file.write(content_expected)

with open(
os.path.join(self.tmp_dir.name, f"{hash_expected}.META"), "w"
os.path.join(self.tmp_dir.name, f"{hash_expected}.META"),
"w",
encoding="utf-8",
) as file:
json.dump(meta_expected, file)

Expand All @@ -105,13 +112,15 @@ def test_list(self) -> None:
ffs: Ffs = self.ffs_factory()
content_expected = b"content"
hash_expected = hashlib.sha256(content_expected).hexdigest()
meta_expected = {}
meta_expected: Dict[str, str] = {"meta_key": "meta_value"}

with open(os.path.join(self.tmp_dir.name, hash_expected), "wb") as file:
file.write(content_expected)

with open(
os.path.join(self.tmp_dir.name, f"{hash_expected}.META"), "w"
os.path.join(self.tmp_dir.name, f"{hash_expected}.META"),
"w",
encoding="utf-8",
) as file:
json.dump(meta_expected, file)

Expand Down

0 comments on commit 5f57946

Please sign in to comment.