Skip to content

Commit

Permalink
Low-hanging unit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Qalthos committed Feb 27, 2023
1 parent e34c0b6 commit a0d630b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
3 changes: 0 additions & 3 deletions plugins/sub_plugins/cli_parser/pyats_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

from ansible.module_utils._text import to_native
from ansible.module_utils.basic import missing_required_lib
from ansible.module_utils.six import PY3
from ansible_collections.ansible.utils.plugins.plugin_utils.base.cli_parser import (
CliParserBase,
)
Expand Down Expand Up @@ -77,8 +76,6 @@ def _check_reqs():
:return dict: A dict with a list of errors
"""
errors = []
if not PY3:
errors.append("Pyats and Genie require Python 3")
if not HAS_GENIE:
errors.append(missing_required_lib("genie"))
if not HAS_PYATS:
Expand Down
4 changes: 0 additions & 4 deletions tests/unit/module_utils/network/common/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,3 @@ def test_key_value_instance_variable_assignment(self):

def test_conditionals_w_not_keyword(self):
assert c1(test_results) and c2(test_results) and c3(test_results)


if __name__ == "__main__":
unittest.main()
19 changes: 5 additions & 14 deletions tests/unit/plugins/connection/test_netconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

__metaclass__ = type

import sys
from unittest.mock import MagicMock, PropertyMock, patch

import pytest
Expand All @@ -28,19 +27,11 @@ def import_mock(name, *args):
return builtin_import(name, *args)


PY3 = sys.version_info[0] == 3
if PY3:
with patch("builtins.__import__", side_effect=import_mock):
from ansible.plugins.loader import connection_loader
from ansible_collections.ansible.netcommon.plugins.connection import (
netconf,
)
else:
with patch("__builtin__.__import__", side_effect=import_mock):
from ansible.plugins.loader import connection_loader
from ansible_collections.ansible.netcommon.plugins.connection import (
netconf,
)
with patch("builtins.__import__", side_effect=import_mock):
from ansible.plugins.loader import connection_loader
from ansible_collections.ansible.netcommon.plugins.connection import (
netconf,
)


def test_netconf_init():
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/plugins/plugin_utils/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# (c) 2023 Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

from __future__ import absolute_import, division, print_function

__metaclass__ = type

import tempfile

import pytest
from ansible_collections.ansible.netcommon.plugins.plugin_utils.version import (
Version,
)


@pytest.mark.parametrize("left", ["6.0.0", 6, 6.0])
@pytest.mark.parametrize("right", ["4.0.0", 4, 4.0])
def test_versions_different(left, right):
assert Version(str(left)) > right


@pytest.mark.parametrize("value", ["6.0.0", 6, 6.0])
def test_versions_same(value):
assert Version(str(value)) == value


def test_version_error():
with pytest.raises(TypeError):
Version("1.2.3") < [1, 2, 3]

# with pytest.raises(TypeError):
Version("1.2.3") == [1, 2, 3]

0 comments on commit a0d630b

Please sign in to comment.