From a9e65732f21e0e9c3cf22c8123d832cdf5f1b777 Mon Sep 17 00:00:00 2001 From: Chris PeBenito Date: Mon, 28 Oct 2024 11:35:20 -0400 Subject: [PATCH 1/3] Type: Stabilize attribute and alias output in statements. Sort attributes and aliases in Type.statement(). Signed-off-by: Chris PeBenito --- setools/policyrep/typeattr.pxi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setools/policyrep/typeattr.pxi b/setools/policyrep/typeattr.pxi index 93485910..835d5ed8 100644 --- a/setools/policyrep/typeattr.pxi +++ b/setools/policyrep/typeattr.pxi @@ -107,11 +107,11 @@ cdef class Type(BaseType): stmt = f"type {self.name}" if count > 1: - stmt += f" alias {{ {' '.join(self._aliases)} }}" + stmt += f" alias {{ {' '.join(sorted(self._aliases))} }}" elif count == 1: stmt += f" alias {self._aliases[0]}" - for attr in self._attrs: - stmt += f", {attr}" + if self._attrs: + stmt += f", {', '.join(a.name for a in sorted(self._attrs))}" stmt += ";" return stmt From 4fa7e3ded8bdc5bca0ef635bb0c7cf7ffe791c64 Mon Sep 17 00:00:00 2001 From: Chris PeBenito Date: Mon, 28 Oct 2024 11:46:50 -0400 Subject: [PATCH 2/3] tests/conftest.py: Add assertions to fix mypy errors. Signed-off-by: Chris PeBenito --- tests/conftest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index ce123dc9..ee55cddd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -225,6 +225,7 @@ def compiled_policy(request: pytest.FixtureRequest) -> Iterable[setools.SELinuxP args = marker.args if marker else () kwargs = marker.kwargs if marker else {} + assert len(args) == 1 source_file = args[0] with tempfile.NamedTemporaryFile("w") as fd: @@ -240,6 +241,7 @@ def policy_pair(request: pytest.FixtureRequest) -> \ args = marker.args if marker else () kwargs = marker.kwargs if marker else {} + assert len(args) == 2 source_file_left = args[0] source_file_right = args[1] From 0a713c64b360d6d882726994d0612274f0005971 Mon Sep 17 00:00:00 2001 From: Chris PeBenito Date: Mon, 28 Oct 2024 11:48:41 -0400 Subject: [PATCH 3/3] tests/conftest.py: Work around apparent mypy issue. Assertion on tuple length doesn't work? Signed-off-by: Chris PeBenito --- tests/conftest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index ee55cddd..a03b6e07 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -226,7 +226,7 @@ def compiled_policy(request: pytest.FixtureRequest) -> Iterable[setools.SELinuxP kwargs = marker.kwargs if marker else {} assert len(args) == 1 - source_file = args[0] + source_file = args[0] # type: ignore with tempfile.NamedTemporaryFile("w") as fd: yield _do_compile(source_file, fd.name, mls=kwargs.get("mls", True), @@ -242,8 +242,8 @@ def policy_pair(request: pytest.FixtureRequest) -> \ kwargs = marker.kwargs if marker else {} assert len(args) == 2 - source_file_left = args[0] - source_file_right = args[1] + source_file_left = args[0] # type: ignore + source_file_right = args[1] # type: ignore with tempfile.NamedTemporaryFile("w") as fd_left: with tempfile.NamedTemporaryFile("w") as fd_right: