Skip to content

Commit 36eaffa

Browse files
committed
Add TestTargetCase dataclass
Use a dataclass for a better visual representation of the test case data set. Signed-off-by: Teodora Sechkova <[email protected]>
1 parent d10c8e9 commit 36eaffa

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

tests/test_updater_delegation_graphs.py

+27-16
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import tempfile
1212
import unittest
1313
from dataclasses import astuple, dataclass, field
14-
from typing import Iterable, List, Optional, Tuple
14+
from typing import Iterable, List, Optional
1515

1616
from tests import utils
1717
from tests.repository_simulator import RepositorySimulator
@@ -53,6 +53,13 @@ class DelegationsTestCase:
5353
visited_order: List[str] = field(default_factory=list)
5454

5555

56+
@dataclass
57+
class TargetTestCase:
58+
targetpath: str
59+
found: bool
60+
visited_order: List[str] = field(default_factory=list)
61+
62+
5663
class TestDelegations(unittest.TestCase):
5764
"""Base class for delegation tests"""
5865

@@ -358,35 +365,39 @@ def setUp(self) -> None:
358365

359366
# fmt: off
360367
targets: utils.DataSet = {
361-
"target found, no delegations": ("targetfile", True, []),
362-
"targetpath matches wildcard": ("README.md", True, ["A"]),
363-
"targetpath with separators x": ("releases/x/x_v1", True, ["B", "C"]),
364-
"targetpath with separators y": ("releases/y/y_v1.zip", True, ["B", "D"]),
365-
"target exists, path is not delegated": ("releases/z/z_v1.zip", False, ["B"]),
368+
"no delegations":
369+
TargetTestCase("targetfile", True, []),
370+
"targetpath matches wildcard":
371+
TargetTestCase("README.md", True, ["A"]),
372+
"targetpath with separators x":
373+
TargetTestCase("releases/x/x_v1", True, ["B", "C"]),
374+
"targetpath with separators y":
375+
TargetTestCase("releases/y/y_v1.zip", True, ["B", "D"]),
376+
"targetpath is not delegated by all roles in the chain":
377+
TargetTestCase("releases/z/z_v1.zip", False, ["B"]),
366378
}
367379
# fmt: on
368380

369381
@utils.run_sub_tests_with_dataset(targets)
370-
def test_targetfile_search(
371-
self, test_data: Tuple[str, bool, List[str]]
372-
) -> None:
382+
def test_targetfile_search(self, test_data: TargetTestCase) -> None:
373383
try:
374384
self.setup_subtest()
375-
targetpath, found, visited_order = test_data
376-
exp_files = [*TOP_LEVEL_ROLE_NAMES, *visited_order]
377-
exp_calls = [(role, 1) for role in visited_order]
385+
# targetpath, found, visited_order = test_data
386+
exp_files = [*TOP_LEVEL_ROLE_NAMES, *test_data.visited_order]
387+
exp_calls = [(role, 1) for role in test_data.visited_order]
388+
exp_target = self.sim.target_files[test_data.targetpath].target_file
389+
378390
updater = self._init_updater()
379391
# Call explicitly refresh to simplify the expected_calls list
380392
updater.refresh()
381393
self.sim.fetch_tracker.metadata.clear()
382-
target = updater.get_targetinfo(targetpath)
394+
target = updater.get_targetinfo(test_data.targetpath)
383395
if target is not None:
384396
# Confirm that the expected TargetFile is found
385-
self.assertTrue(found)
386-
exp_target = self.sim.target_files[targetpath].target_file
397+
self.assertTrue(test_data.found)
387398
self.assertDictEqual(target.to_dict(), exp_target.to_dict())
388399
else:
389-
self.assertFalse(found)
400+
self.assertFalse(test_data.found)
390401
# Check that the delegated roles were visited in the expected
391402
# order and the corresponding metadata files were persisted
392403
self.assertListEqual(self.sim.fetch_tracker.metadata, exp_calls)

0 commit comments

Comments
 (0)