Skip to content

Commit

Permalink
Merge pull request #470 from adityasaky/fix-lint-file-encoding
Browse files Browse the repository at this point in the history
Add explicit utf8 encoding to "open" calls
  • Loading branch information
adityasaky committed Aug 31, 2021
2 parents 6f19eb7 + 2e26ab3 commit 904a246
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion in_toto/models/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def load(path):
object.
"""
with open(path, "r") as fp:
with open(path, "r", encoding="utf8") as fp:
data = json.load(fp)

signatures = data.get("signatures", [])
Expand Down
11 changes: 7 additions & 4 deletions tests/test_runlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def setUpClass(self):
"subdir/foosub2", "subdir/subsubdir/foosubsub"]

for path in self.full_file_path_list:
with open(path, "w") as fp:
with open(path, "w", encoding="utf8") as fp:
fp.write(path)


Expand Down Expand Up @@ -789,7 +789,8 @@ def test_replace_unfinished_metadata(self):
in_toto_record_start(self.step_name, [], self.key)
in_toto_record_stop(self.step_name, [], self.key)
with self.assertRaises(IOError):
open(self.link_name_unfinished, "r") # pylint: disable=consider-using-with
# pylint: disable-next=consider-using-with
open(self.link_name_unfinished, "r", encoding="utf8")
self.assertTrue(os.path.isfile(self.link_name))
os.remove(self.link_name)

Expand All @@ -798,7 +799,8 @@ def test_missing_unfinished_file(self):
with self.assertRaises(IOError):
in_toto_record_stop(self.step_name, [], self.key)
with self.assertRaises(IOError):
open(self.link_name, "r") # pylint: disable=consider-using-with
# pylint: disable-next=consider-using-with
open(self.link_name, "r", encoding="utf8")

def test_wrong_signature_in_unfinished_metadata(self):
"""Test record stop exits on wrong signature, no link recorded. """
Expand All @@ -811,7 +813,8 @@ def test_wrong_signature_in_unfinished_metadata(self):
with self.assertRaises(SignatureVerificationError):
in_toto_record_stop(self.step_name, [], self.key2)
with self.assertRaises(IOError):
open(self.link_name, "r") # pylint: disable=consider-using-with
# pylint: disable-next=consider-using-with
open(self.link_name, "r", encoding="utf8")
os.rename(changed_link_name, link_name)
os.remove(self.link_name_unfinished)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_verifylib.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def setUpClass(self):

# Create directory where the verification will take place
self.set_up_test_dir()
with open("foo", "w") as f:
with open("foo", "w", encoding="utf8") as f:
f.write("foo")

@classmethod
Expand All @@ -123,7 +123,7 @@ def test_inpsection_artifacts_with_base_path_ignored(self):
"""Create new dummy test dir and set as base path, must ignore. """
ignore_dir = os.path.realpath(tempfile.mkdtemp())
ignore_foo = os.path.join(ignore_dir, "ignore_foo")
with open(ignore_foo, "w") as f:
with open(ignore_foo, "w", encoding="utf8") as f:
f.write("ignore foo")
in_toto.settings.ARTIFACT_BASE_PATH = ignore_dir

Expand Down

0 comments on commit 904a246

Please sign in to comment.