Skip to content

Commit

Permalink
Disable some sentiel tests in Python 3.6 - it doesn't play nice with …
Browse files Browse the repository at this point in the history
…deepcopy
  • Loading branch information
tremble committed Nov 11, 2022
1 parent b9009df commit b97b7f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion plugins/modules/ec2_security_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,8 @@ def get_target_from_rule(module, client, rule, name, group, groups, vpc_id):

def _strip_rule(rule):
"""
Strips the Target/Source and Port information from a rule
Returns a copy of the rule with the Target/Source and Port information
from a rule stripped out.
This can then be combined with the expanded information
"""
stripped_rule = deepcopy(rule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

import pytest
import sys
from unittest.mock import sentinel

import ansible_collections.amazon.aws.plugins.modules.ec2_security_group as ec2_security_group_module
Expand Down Expand Up @@ -173,6 +174,9 @@ def test_expand_ports_list(rule, expected):
assert ec2_security_group_module.expand_ports_list(rule) == expected


@pytest.mark.skipif(
sys.version_info < (3, 7), reason="requires Python 3.7 or higher - sentinel doesn't behave well with deepcopy in Python 3.6"
)
@pytest.mark.parametrize("source_type", sorted(ec2_security_group_module.SOURCE_TYPES_ALL))
def test_strip_rule_source(source_type):
rule = {source_type: sentinel.SOURCE_VALUE}
Expand All @@ -184,8 +188,11 @@ def test_strip_rule_source(source_type):
assert rule == {source_type: sentinel.SOURCE_VALUE, "sentinel": sentinel.SENTINEL_VALUE}


@pytest.mark.skipif(
sys.version_info < (3, 7), reason="requires Python 3.7 or higher - sentinel doesn't behave well with deepcopy in Python 3.6"
)
@pytest.mark.parametrize("port_type", sorted(ec2_security_group_module.PORT_TYPES_ALL))
def test_strip_rule_source(port_type):
def test_strip_rule_port(port_type):
rule = {port_type: sentinel.PORT_VALUE}
assert ec2_security_group_module._strip_rule(rule) == {}
assert rule == {port_type: sentinel.PORT_VALUE}
Expand All @@ -195,6 +202,9 @@ def test_strip_rule_source(port_type):
assert rule == {port_type: sentinel.PORT_VALUE, "sentinel": sentinel.SENTINEL_VALUE}


@pytest.mark.skipif(
sys.version_info < (3, 7), reason="requires Python 3.7 or higher - sentinel doesn't behave well with deepcopy in Python 3.6"
)
@pytest.mark.parametrize("rule, expected", RULE_EXPANSION)
def test_rule_expand(rule, expected):
assert ec2_security_group_module.expand_rule(rule) == expected
Expand Down

0 comments on commit b97b7f7

Please sign in to comment.