From 5f912dad165a516050adf3cb6ddff36962e80ab6 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 15 May 2022 22:42:26 +0200 Subject: [PATCH] Improve unit test performance. (Do not install library we do not use in the tests anyway.) (#92) --- .github/workflows/ansible-test.yml | 7 ------- tests/unit/plugins/modules/fake_api.py | 9 ++++++--- tests/unit/plugins/modules/test_api.py | 2 +- tests/unit/plugins/modules/test_api_facts.py | 2 +- tests/unit/requirements-stable-2.9.txt | 4 ---- tests/unit/requirements.txt | 3 --- 6 files changed, 8 insertions(+), 19 deletions(-) delete mode 100644 tests/unit/requirements-stable-2.9.txt diff --git a/.github/workflows/ansible-test.yml b/.github/workflows/ansible-test.yml index 6c1a30a..d423345 100644 --- a/.github/workflows/ansible-test.yml +++ b/.github/workflows/ansible-test.yml @@ -100,13 +100,6 @@ jobs: with: path: ansible_collections/community/routeros - - name: Overwrite unit test requirements (if applicable) - run: | - if [ -e tests/unit/requirements-${{ matrix.ansible }}.txt ]; then - cp tests/unit/requirements-${{ matrix.ansible }}.txt tests/unit/requirements.txt - fi - working-directory: ./ansible_collections/community/routeros - - name: Set up Python ${{ matrix.ansible }} uses: actions/setup-python@v3 with: diff --git a/tests/unit/plugins/modules/fake_api.py b/tests/unit/plugins/modules/fake_api.py index 03cb6d2..6b5805b 100644 --- a/tests/unit/plugins/modules/fake_api.py +++ b/tests/unit/plugins/modules/fake_api.py @@ -34,7 +34,8 @@ class fake_ros_api(object): def __init__(self, api, path): pass - def path(self, api, path): + @classmethod + def path(cls, api, path): fake_bridge = [{".id": "*DC", "name": "b2", "mtu": "auto", "actual-mtu": 1500, "l2mtu": 65535, "arp": "enabled", "arp-timeout": "auto", "mac-address": "3A:C1:90:D6:E8:44", "protocol-mode": "rstp", @@ -45,7 +46,8 @@ class fake_ros_api(object): "dhcp-snooping": "false", "running": "true", "disabled": "false"}] return fake_bridge - def arbitrary(self, api, path): + @classmethod + def arbitrary(cls, api, path): def retr(self, *args, **kwargs): if 'name' not in kwargs.keys(): raise TrapError(message="no such command") @@ -90,7 +92,8 @@ class fake_ros_api(object): else: return ["no results for 'interface bridge 'query' %s" % ' '.join(args)] - def select_where(self, api, path): + @classmethod + def select_where(cls, api, path): api_path = Where() return api_path diff --git a/tests/unit/plugins/modules/test_api.py b/tests/unit/plugins/modules/test_api.py index 98dcd8c..f3dd114 100644 --- a/tests/unit/plugins/modules/test_api.py +++ b/tests/unit/plugins/modules/test_api.py @@ -30,10 +30,10 @@ class TestRouterosApiModule(ModuleTestCase): def setUp(self): super(TestRouterosApiModule, self).setUp() - librouteros = pytest.importorskip("librouteros") self.module = api self.module.LibRouterosError = FakeLibRouterosError self.module.connect = MagicMock(new=fake_ros_api) + self.module.check_has_library = MagicMock() self.patch_create_api = patch('ansible_collections.community.routeros.plugins.modules.api.create_api', MagicMock(new=fake_ros_api)) self.patch_create_api.start() self.module.Key = MagicMock(new=Key) diff --git a/tests/unit/plugins/modules/test_api_facts.py b/tests/unit/plugins/modules/test_api_facts.py index 8c3eeac..0c41806 100644 --- a/tests/unit/plugins/modules/test_api_facts.py +++ b/tests/unit/plugins/modules/test_api_facts.py @@ -424,10 +424,10 @@ class TestRouterosApiFactsModule(ModuleTestCase): def setUp(self): super(TestRouterosApiFactsModule, self).setUp() - librouteros = pytest.importorskip('librouteros') self.module = api_facts self.module.LibRouterosError = FakeLibRouterosError self.module.connect = MagicMock(new=fake_ros_api) + self.module.check_has_library = MagicMock() self.patch_create_api = patch('ansible_collections.community.routeros.plugins.modules.api_facts.create_api', MagicMock(new=fake_ros_api)) self.patch_create_api.start() self.patch_query_path = patch('ansible_collections.community.routeros.plugins.modules.api_facts.FactsBase.query_path', self.query_path) diff --git a/tests/unit/requirements-stable-2.9.txt b/tests/unit/requirements-stable-2.9.txt deleted file mode 100644 index 1aa8523..0000000 --- a/tests/unit/requirements-stable-2.9.txt +++ /dev/null @@ -1,4 +0,0 @@ -unittest2 ; python_version <= '2.6' - -# requirements for api module -librouteros < 3.2.0 ; python_version >= '3.6' diff --git a/tests/unit/requirements.txt b/tests/unit/requirements.txt index eac8a96..f4f7b56 100644 --- a/tests/unit/requirements.txt +++ b/tests/unit/requirements.txt @@ -1,4 +1 @@ unittest2 ; python_version <= '2.6' - -# requirements for api module -librouteros ; python_version >= '3.6'