Skip to content

Commit

Permalink
Remove unnecessary copy operations
Browse files Browse the repository at this point in the history
There is no need to copy "case_dict" inside serialization test
functions in test_metadata_serialization.py when we are testing
invalid arguments.
These dictionaries are not be used after calling "from_dict" and
it doesn't matter if they are empty afterward.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
  • Loading branch information
MVrachev committed Feb 10, 2022
1 parent 2be5743 commit ccce48e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tests/test_metadata_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_invalid_signatures_serialization(self, test_data: str) -> None:
def test_invalid_signed_serialization(self, test_case_data: str) -> None:
case_dict = json.loads(test_case_data)
with self.assertRaises((KeyError, ValueError, TypeError)):
Snapshot.from_dict(copy.deepcopy(case_dict))
Snapshot.from_dict(case_dict)

valid_keys: utils.DataSet = {
"all": '{"keytype": "rsa", "scheme": "rsassa-pss-sha256", \
Expand Down Expand Up @@ -170,7 +170,7 @@ def test_invalid_key_serialization(self, test_case_data: str) -> None:
case_dict = json.loads(test_case_data)
with self.assertRaises((TypeError, KeyError)):
keyid = case_dict.pop("keyid")
Key.from_dict(keyid, copy.copy(case_dict))
Key.from_dict(keyid, case_dict)

invalid_roles: utils.DataSet = {
"no threshold": '{"keyids": ["keyid"]}',
Expand All @@ -184,7 +184,7 @@ def test_invalid_key_serialization(self, test_case_data: str) -> None:
def test_invalid_role_serialization(self, test_case_data: str) -> None:
case_dict = json.loads(test_case_data)
with self.assertRaises((KeyError, TypeError, ValueError)):
Role.from_dict(copy.deepcopy(case_dict))
Role.from_dict(case_dict)

valid_roles: utils.DataSet = {
"all": '{"keyids": ["keyid"], "threshold": 3}',
Expand Down Expand Up @@ -291,7 +291,7 @@ def test_root_serialization(self, test_case_data: str) -> None:
def test_invalid_root_serialization(self, test_case_data: str) -> None:
case_dict = json.loads(test_case_data)
with self.assertRaises(ValueError):
Root.from_dict(copy.deepcopy(case_dict))
Root.from_dict(case_dict)

invalid_metafiles: utils.DataSet = {
"wrong length type": '{"version": 1, "length": "a", "hashes": {"sha256" : "abc"}}',
Expand All @@ -307,7 +307,7 @@ def test_invalid_root_serialization(self, test_case_data: str) -> None:
def test_invalid_metafile_serialization(self, test_case_data: str) -> None:
case_dict = json.loads(test_case_data)
with self.assertRaises((TypeError, ValueError, AttributeError)):
MetaFile.from_dict(copy.deepcopy(case_dict))
MetaFile.from_dict(case_dict)

valid_metafiles: utils.DataSet = {
"all": '{"hashes": {"sha256" : "abc"}, "length": 12, "version": 1}',
Expand All @@ -331,7 +331,7 @@ def test_metafile_serialization(self, test_case_data: str) -> None:
def test_invalid_timestamp_serialization(self, test_case_data: str) -> None:
case_dict = json.loads(test_case_data)
with self.assertRaises((ValueError, KeyError)):
Timestamp.from_dict(copy.deepcopy(case_dict))
Timestamp.from_dict(case_dict)

valid_timestamps: utils.DataSet = {
"all": '{ "_type": "timestamp", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
Expand Down Expand Up @@ -407,7 +407,7 @@ def test_invalid_delegated_role_serialization(
) -> None:
case_dict = json.loads(test_case_data)
with self.assertRaises(ValueError):
DelegatedRole.from_dict(copy.copy(case_dict))
DelegatedRole.from_dict(case_dict)

invalid_delegations: utils.DataSet = {
"empty delegations": "{}",
Expand Down Expand Up @@ -468,7 +468,7 @@ def test_invalid_delegation_serialization(
) -> None:
case_dict = json.loads(test_case_data)
with self.assertRaises((ValueError, KeyError, AttributeError)):
Delegations.from_dict(copy.deepcopy(case_dict))
Delegations.from_dict(case_dict)

valid_delegations: utils.DataSet = {
"all": '{"keys": { \
Expand Down Expand Up @@ -505,7 +505,7 @@ def test_invalid_targetfile_serialization(
) -> None:
case_dict = json.loads(test_case_data)
with self.assertRaises(KeyError):
TargetFile.from_dict(copy.deepcopy(case_dict), "file1.txt")
TargetFile.from_dict(case_dict, "file1.txt")

valid_targetfiles: utils.DataSet = {
"all": '{"length": 12, "hashes": {"sha256" : "abc"}, \
Expand Down

0 comments on commit ccce48e

Please sign in to comment.