Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py27 compats no longer needed #1045

Merged
merged 4 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed tests/unit/compat/__init__.py
Empty file.
28 changes: 0 additions & 28 deletions tests/unit/compat/mock.py

This file was deleted.

41 changes: 0 additions & 41 deletions tests/unit/compat/unittest.py

This file was deleted.

9 changes: 6 additions & 3 deletions tests/unit/mock/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@


__metaclass__ = type
from ansible.utils.path import unfrackpath
from unittest.mock import MagicMock

from ansible_collections.cisco.ios.tests.unit.compat.mock import MagicMock
from ansible.utils.path import unfrackpath


mock_unfrackpath_noop = MagicMock(spec_set=unfrackpath, side_effect=lambda x, *args, **kwargs: x)
mock_unfrackpath_noop = MagicMock(
spec_set=unfrackpath,
side_effect=lambda x, *args, **kwargs: x,
)
10 changes: 6 additions & 4 deletions tests/unit/mock/procenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@

from contextlib import contextmanager
from io import BytesIO, StringIO
from unittest import TestCase

from ansible.module_utils._text import to_bytes
from ansible.module_utils.six import PY3

from ansible_collections.cisco.ios.tests.unit.compat import unittest


@contextmanager
def swap_stdin_and_argv(stdin_data="", argv_data=tuple()):
Expand Down Expand Up @@ -78,10 +77,13 @@ def swap_stdout():
sys.stdout = old_stdout


class ModuleTestCase(unittest.TestCase):
class ModuleTestCase(TestCase):
def setUp(self, module_args=None):
if module_args is None:
module_args = {"_ansible_remote_tmp": "/tmp", "_ansible_keep_remote_files": False}
module_args = {
"_ansible_remote_tmp": "/tmp",
"_ansible_keep_remote_files": False,
}

args = json.dumps(dict(ANSIBLE_MODULE_ARGS=module_args))

Expand Down
3 changes: 1 addition & 2 deletions tests/unit/modules/network/ios/test_ios_acl_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@


__metaclass__ = type

from textwrap import dedent
from unittest.mock import patch

from ansible_collections.cisco.ios.plugins.modules import ios_acl_interfaces
from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args

from .ios_module import TestIosModule
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/modules/network/ios/test_ios_acls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@


__metaclass__ = type

from textwrap import dedent
from unittest.mock import patch

from ansible_collections.cisco.ios.plugins.modules import ios_acls
from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args

from .ios_module import TestIosModule
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/modules/network/ios/test_ios_banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@


__metaclass__ = type
from unittest.mock import patch

from ansible_collections.cisco.ios.plugins.modules import ios_banner
from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args

from .ios_module import TestIosModule, load_fixture
Expand Down Expand Up @@ -77,7 +77,11 @@ def test_ios_banner_idemp(self):
def test_ios_banner_create_delimiter(self):
for banner_type in ("login", "motd", "exec", "incoming", "slip-ppp"):
set_module_args(
dict(banner=banner_type, text="test\nbanner\nstring", multiline_delimiter="c"),
dict(
banner=banner_type,
text="test\nbanner\nstring",
multiline_delimiter="c",
),
)
commands = ["banner {0} c\ntest\nbanner\nstring\nc".format(banner_type)]
self.execute_module(changed=True, commands=commands)
Expand Down
65 changes: 49 additions & 16 deletions tests/unit/modules/network/ios/test_ios_bgp_address_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@


__metaclass__ = type

from textwrap import dedent
from unittest.mock import patch

from ansible_collections.cisco.ios.plugins.modules import ios_bgp_address_family
from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args

from .ios_module import TestIosModule
Expand Down Expand Up @@ -119,16 +118,22 @@ def test_ios_bgp_address_family_merged(self):
dict(
neighbor_address="198.51.100.1",
remote_as="65.11",
route_maps=[dict(name="test-route-out", out="true")],
prefix_lists=[dict(name="AS65100-PREFIX-OUT", out="true")],
route_maps=[
dict(name="test-route-out", out="true"),
],
prefix_lists=[
dict(name="AS65100-PREFIX-OUT", out="true"),
],
),
],
),
dict(
afi="nsap",
bgp=dict(aggregate_timer=20, dmzlink_bw=True, scan_time=10),
default_metric=10,
networks=[dict(address="192.0.1.1", route_map="test_route")],
networks=[
dict(address="192.0.1.1", route_map="test_route"),
],
),
],
),
Expand Down Expand Up @@ -317,18 +322,25 @@ def test_ios_bgp_address_family_merged_idempotent(self):
"send": {
"cost_community": {
"id": 100,
"poi": {"igp_cost": True, "transitive": True},
"poi": {
"igp_cost": True,
"transitive": True,
},
},
},
},
"local_as": {"number": "10.64760", "set": True},
"neighbor_address": "198.51.100.1",
"nexthop_self": {"all": True},
"prefix_lists": [{"name": "AS65100-PREFIX-OUT", "out": True}],
"prefix_lists": [
{"name": "AS65100-PREFIX-OUT", "out": True},
],
"remote_as": 10,
"route_maps": [{"name": "test-out", "out": True}],
"route_server_client": True,
"slow_peer_options": {"detection": {"threshold": 150}},
"slow_peer_options": {
"detection": {"threshold": 150},
},
},
],
"networks": [
Expand Down Expand Up @@ -426,7 +438,9 @@ def test_ios_bgp_address_family_replaced(self):
address="198.51.110.1",
activate=True,
remote_as=200,
route_maps=[dict(name="test-replaced-route", out=True)],
route_maps=[
dict(name="test-replaced-route", out=True),
],
),
],
),
Expand Down Expand Up @@ -534,12 +548,17 @@ def test_ios_bgp_address_family_replaced_idempotent(self):
send=dict(
cost_community=dict(
id=100,
poi=dict(igp_cost=True, transitive=True),
poi=dict(
igp_cost=True,
transitive=True,
),
),
),
),
nexthop_self=dict(all=True),
prefix_lists=[dict(name="AS65100-PREFIX-OUT", out="true")],
prefix_lists=[
dict(name="AS65100-PREFIX-OUT", out="true"),
],
slow_peer=[dict(detection=dict(threshold=150))],
remote_as=10,
local_as=dict(number=20),
Expand Down Expand Up @@ -709,12 +728,17 @@ def test_ios_bgp_address_family_overridden_idempotent(self):
send=dict(
cost_community=dict(
id=100,
poi=dict(igp_cost=True, transitive=True),
poi=dict(
igp_cost=True,
transitive=True,
),
),
),
),
nexthop_self=dict(all=True),
prefix_lists=[dict(name="AS65100-PREFIX-OUT", out="true")],
prefix_lists=[
dict(name="AS65100-PREFIX-OUT", out="true"),
],
slow_peer=[dict(detection=dict(threshold=150))],
remote_as=10,
local_as=dict(number=20),
Expand Down Expand Up @@ -937,7 +961,10 @@ def test_ios_bgp_address_family_rendered(self):
send=dict(
cost_community=dict(
id=100,
poi=dict(igp_cost=True, transitive=True),
poi=dict(
igp_cost=True,
transitive=True,
),
),
),
),
Expand Down Expand Up @@ -1152,7 +1179,11 @@ def test_ios_bgp_address_family_parsed(self):
},
},
"networks": [
{"address": "198.51.110.10", "mask": "255.255.255.255", "backdoor": True},
{
"address": "198.51.110.10",
"mask": "255.255.255.255",
"backdoor": True,
},
],
"aggregate_addresses": [
{
Expand All @@ -1177,7 +1208,9 @@ def test_ios_bgp_address_family_parsed(self):
},
},
"route_server_client": True,
"prefix_lists": [{"name": "AS65100-PREFIX-OUT", "out": True}],
"prefix_lists": [
{"name": "AS65100-PREFIX-OUT", "out": True},
],
"slow_peer_options": {"detection": {"threshold": 150}},
"route_maps": [{"name": "test-out", "out": True}],
},
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/modules/network/ios/test_ios_bgp_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@


__metaclass__ = type

from textwrap import dedent
from unittest.mock import patch

from ansible_collections.cisco.ios.plugins.modules import ios_bgp_global
from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import AnsibleFailJson, set_module_args

from .ios_module import TestIosModule
Expand Down
19 changes: 14 additions & 5 deletions tests/unit/modules/network/ios/test_ios_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@


__metaclass__ = type

import json

from unittest.mock import patch

from ansible_collections.cisco.ios.plugins.modules import ios_command
from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args

from .ios_module import TestIosModule, load_fixture
Expand Down Expand Up @@ -97,17 +97,26 @@ def test_ios_command_retries_0(self):
self.assertEqual(self.run_commands.call_count, 1)

def test_ios_command_match_any(self):
wait_for = ['result[0] contains "Cisco IOS"', 'result[0] contains "test string"']
wait_for = [
'result[0] contains "Cisco IOS"',
'result[0] contains "test string"',
]
set_module_args(dict(commands=["show version"], wait_for=wait_for, match="any"))
self.execute_module()

def test_ios_command_match_all(self):
wait_for = ['result[0] contains "Cisco IOS"', 'result[0] contains "IOSv Software"']
wait_for = [
'result[0] contains "Cisco IOS"',
'result[0] contains "IOSv Software"',
]
set_module_args(dict(commands=["show version"], wait_for=wait_for, match="all"))
self.execute_module()

def test_ios_command_match_all_failure(self):
wait_for = ['result[0] contains "Cisco IOS"', 'result[0] contains "test string"']
wait_for = [
'result[0] contains "Cisco IOS"',
'result[0] contains "test string"',
]
commands = ["show version", "show version"]
set_module_args(dict(commands=commands, wait_for=wait_for, match="all"))
self.execute_module(failed=True)
Expand Down
Loading
Loading