mirror of
https://github.com/SELinuxProject/setools
synced 2025-05-02 16:20:34 +00:00
Now that unit tests use pytest, validate_rule no longer needs to use "self" to do assertions. It no longer needs to be a mixin. Signed-off-by: Chris PeBenito <chpebeni@linux.microsoft.com>
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
"""Unit test mixin classes."""
|
|
# Copyright 2015, Tresys Technology, LLC
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
|
#
|
|
# pylint: disable=too-few-public-methods
|
|
import pytest
|
|
import setools
|
|
|
|
|
|
def validate_rule(rule: setools.policyrep.PolicyRule,
|
|
ruletype: setools.policyrep.PolicyEnum | str,
|
|
source: setools.policyrep.PolicySymbol | str,
|
|
target: setools.policyrep.PolicySymbol | str,
|
|
tclass: setools.ObjClass | str,
|
|
last_item: set[str] | setools.IoctlSet | setools.policyrep.PolicySymbol | str,
|
|
cond: str | None = None,
|
|
cond_block: bool | None = None,
|
|
xperm: str | None = None) -> None:
|
|
|
|
"""Validate a rule."""
|
|
assert ruletype == rule.ruletype
|
|
assert source == rule.source
|
|
assert target == rule.target
|
|
assert tclass == rule.tclass
|
|
|
|
try:
|
|
# This is the common case.
|
|
assert last_item == rule.perms
|
|
except (AttributeError, setools.exception.RuleUseError):
|
|
assert last_item == rule.default
|
|
|
|
if cond:
|
|
assert cond == rule.conditional
|
|
else:
|
|
with pytest.raises(setools.exception.RuleNotConditional):
|
|
rule.conditional
|
|
|
|
if cond_block is not None:
|
|
assert cond_block == rule.conditional_block
|
|
|
|
if xperm:
|
|
assert xperm == rule.xperm_type
|
|
assert rule.extended
|
|
else:
|
|
with pytest.raises(AttributeError):
|
|
rule.xperm_type
|
|
assert not rule.extended
|