From f44e586424dd5fb8cb5de0616ca6ee65f4988863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20B=C5=99ezina?= Date: Wed, 9 Nov 2022 10:01:21 +0100 Subject: [PATCH] tests: fix all flake8 issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Iker Pedrosa Reviewed-by: Jakub Vávra --- src/config/SSSDConfigTest.py | 2 +- src/sbus/codegen/sbus_CodeGen.py | 17 +----- src/sbus/codegen/sbus_Generator.py | 21 +++++-- src/tests/intg/conftest.py | 1 + src/tests/intg/test_files_ops.py | 2 +- src/tests/intg/test_files_provider.py | 2 +- src/tests/intg/test_kcm.py | 1 - src/tests/intg/test_pam_responder.py | 1 - src/tests/multihost/ad/conftest.py | 6 +- src/tests/multihost/admultidomain/conftest.py | 6 +- src/tests/multihost/adsites/conftest.py | 6 +- src/tests/multihost/alltests/conftest.py | 6 +- src/tests/multihost/basic/conftest.py | 9 +-- src/tests/multihost/basic/mhc.yaml | 2 +- src/tests/multihost/ipa/conftest.py | 6 +- .../multihost/sssd/testlib/common/fixtures.py | 60 +++++++++++++++++++ .../multihost/sssd/testlib/common/qe_class.py | 57 ------------------ 17 files changed, 115 insertions(+), 90 deletions(-) create mode 100644 src/tests/intg/conftest.py create mode 100644 src/tests/multihost/sssd/testlib/common/fixtures.py diff --git a/src/config/SSSDConfigTest.py b/src/config/SSSDConfigTest.py index 6ca73c4a921..9e1749b66f2 100755 --- a/src/config/SSSDConfigTest.py +++ b/src/config/SSSDConfigTest.py @@ -36,7 +36,7 @@ srcdir = srcdir + "/src/config" else: srcdir = "." -import SSSDConfig +import SSSDConfig # noqa def create_temp_dir(): diff --git a/src/sbus/codegen/sbus_CodeGen.py b/src/sbus/codegen/sbus_CodeGen.py index 2ae25a56cd3..b799da93af5 100644 --- a/src/sbus/codegen/sbus_CodeGen.py +++ b/src/sbus/codegen/sbus_CodeGen.py @@ -22,8 +22,9 @@ import argparse from collections import OrderedDict from sbus_Introspection import Introspectable -from sbus_Template import * -from sbus_Generator import * +from sbus_Template import TemplateFile +from sbus_Generator import Generator +from sbus_DataType import DataType class CodeGen: @@ -78,18 +79,6 @@ def add(self, introspection_file): def generate(self): Generator.GenerateCode(self.templates, self.interfaces) - @staticmethod - def FilterAnnotations(annotations): - dict = OrderedDict() - if annotations is None or not annotations: - return dict - - for name, annotation in annotations.items(): - if not name.startswith("codegen."): - dict[name] = annotation - - return dict - class Options: def __init__(self, SbusHeadersPath, diff --git a/src/sbus/codegen/sbus_Generator.py b/src/sbus/codegen/sbus_Generator.py index e9508431492..b80bff14834 100644 --- a/src/sbus/codegen/sbus_Generator.py +++ b/src/sbus/codegen/sbus_Generator.py @@ -18,8 +18,9 @@ # along with this program. If not, see . # -from sbus_Invoker import * -from sbus_CodeGen import CodeGen +from collections import OrderedDict +from sbus_Invoker import Invoker, InvokerArgumentType, InvokerCaller, InvokerKeygen +from sbus_Introspection import SBus from sbus_DataType import DataType @@ -104,6 +105,18 @@ def __init__(self, interfaces, type): templates.write() + @staticmethod + def FilterAnnotations(annotations): + dict = OrderedDict() + if annotations is None or not annotations: + return dict + + for name, annotation in annotations.items(): + if not name.startswith("codegen."): + dict[name] = annotation + + return dict + class Base(object): """ Base object for code generators. @@ -296,7 +309,7 @@ def toggleAnnotations(self, tpl, annotations): """ # We do not include codegen annotations. - filtered = CodeGen.FilterAnnotations(annotations) + filtered = Generator.FilterAnnotations(annotations) show = True if filtered is None or not filtered: @@ -385,7 +398,7 @@ def argument(self, argument): def generateAnnotations(self, token, annotations): # We do not include codegen annotations. - filtered = CodeGen.FilterAnnotations(annotations) + filtered = Generator.FilterAnnotations(annotations) if filtered is None or not filtered: return diff --git a/src/tests/intg/conftest.py b/src/tests/intg/conftest.py new file mode 100644 index 00000000000..f07a410940e --- /dev/null +++ b/src/tests/intg/conftest.py @@ -0,0 +1 @@ +from files_ops import passwd_ops_setup, group_ops_setup # noqa diff --git a/src/tests/intg/test_files_ops.py b/src/tests/intg/test_files_ops.py index 9af7a12539a..f778a89b063 100644 --- a/src/tests/intg/test_files_ops.py +++ b/src/tests/intg/test_files_ops.py @@ -21,7 +21,7 @@ import pytest import ent -from files_ops import passwd_ops_setup, group_ops_setup + USER1 = dict(name='user1', passwd='*', uid=10001, gid=20001, gecos='User for tests', diff --git a/src/tests/intg/test_files_provider.py b/src/tests/intg/test_files_provider.py index 48d5487c5b6..344e1850e9e 100644 --- a/src/tests/intg/test_files_provider.py +++ b/src/tests/intg/test_files_provider.py @@ -34,7 +34,7 @@ from sssd_passwd import (call_sssd_getpwnam, call_sssd_getpwuid) from sssd_group import call_sssd_getgrnam, call_sssd_getgrgid -from files_ops import passwd_ops_setup, group_ops_setup, PasswdOps, GroupOps +from files_ops import PasswdOps, GroupOps from util import unindent # Sync this with files_ops.c diff --git a/src/tests/intg/test_kcm.py b/src/tests/intg/test_kcm.py index 14f6d5662aa..96a4b0362cb 100644 --- a/src/tests/intg/test_kcm.py +++ b/src/tests/intg/test_kcm.py @@ -31,7 +31,6 @@ import krb5utils import config from util import unindent -from intg.files_ops import passwd_ops_setup MAX_SECRETS = 10 diff --git a/src/tests/intg/test_pam_responder.py b/src/tests/intg/test_pam_responder.py index cf04d7cc8bf..497fe8eb0d3 100644 --- a/src/tests/intg/test_pam_responder.py +++ b/src/tests/intg/test_pam_responder.py @@ -35,7 +35,6 @@ import pytest from intg.util import unindent -from intg.files_ops import passwd_ops_setup LDAP_BASE_DN = "dc=example,dc=com" diff --git a/src/tests/multihost/ad/conftest.py b/src/tests/multihost/ad/conftest.py index 8180592b247..583ab695860 100644 --- a/src/tests/multihost/ad/conftest.py +++ b/src/tests/multihost/ad/conftest.py @@ -7,7 +7,6 @@ import pytest import os import posixpath -from sssd.testlib.common.qe_class import session_multihost from sssd.testlib.common.paths import SSSD_DEFAULT_CONF from sssd.testlib.common.exceptions import SSSDException from sssd.testlib.common.utils import ADOperations @@ -15,6 +14,11 @@ from sssd.testlib.common.utils import sssdTools +pytest_plugins = ( + 'sssd.testlib.common.fixtures', +) + + def pytest_configure(): """ Namespace hook, Adds below dict to pytest namespace """ pytest.num_masters = 1 diff --git a/src/tests/multihost/admultidomain/conftest.py b/src/tests/multihost/admultidomain/conftest.py index 1d08ad42b0d..a08d34bfd4e 100644 --- a/src/tests/multihost/admultidomain/conftest.py +++ b/src/tests/multihost/admultidomain/conftest.py @@ -4,11 +4,15 @@ import subprocess import random import pytest -from sssd.testlib.common.qe_class import session_multihost from sssd.testlib.common.paths import SSSD_DEFAULT_CONF from sssd.testlib.common.utils import sssdTools +pytest_plugins = ( + 'sssd.testlib.common.fixtures', +) + + def pytest_configure(): """ Namespace hook, Adds below dict to pytest namespace """ pytest.num_masters = 0 diff --git a/src/tests/multihost/adsites/conftest.py b/src/tests/multihost/adsites/conftest.py index 84cda15bd69..49cc969bc0e 100644 --- a/src/tests/multihost/adsites/conftest.py +++ b/src/tests/multihost/adsites/conftest.py @@ -6,13 +6,17 @@ import pytest import os import posixpath -from sssd.testlib.common.qe_class import session_multihost from sssd.testlib.common.paths import SSSD_DEFAULT_CONF from sssd.testlib.common.exceptions import SSSDException from sssd.testlib.common.samba import sambaTools from sssd.testlib.common.utils import sssdTools +pytest_plugins = ( + 'sssd.testlib.common.fixtures', +) + + def pytest_configure(): """ Namespace hook, Adds below dict to pytest namespace """ pytest.num_masters = 0 diff --git a/src/tests/multihost/alltests/conftest.py b/src/tests/multihost/alltests/conftest.py index 73907f4892c..28399c2e0a6 100644 --- a/src/tests/multihost/alltests/conftest.py +++ b/src/tests/multihost/alltests/conftest.py @@ -12,13 +12,17 @@ from constants import ds_instance_name, ds_suffix, krb_realm, ds_rootdn, ds_rootpw from sssd.testlib.common.libkrb5 import krb5srv from sssd.testlib.common.paths import SSSD_DEFAULT_CONF, NSSWITCH_DEFAULT_CONF -from sssd.testlib.common.qe_class import session_multihost from sssd.testlib.common.utils import PkiTools, sssdTools, LdapOperations from sssd.testlib.common.libdirsrv import DirSrvWrap from sssd.testlib.common.exceptions import PkiLibException, LdapException from datetime import datetime, timedelta +pytest_plugins = ( + 'sssd.testlib.common.fixtures', +) + + def pytest_configure(): """ Namespace hook to add below dict in the pytest namespace """ pytest.num_masters = 2 diff --git a/src/tests/multihost/basic/conftest.py b/src/tests/multihost/basic/conftest.py index 709beab3c10..225eddb8a4b 100644 --- a/src/tests/multihost/basic/conftest.py +++ b/src/tests/multihost/basic/conftest.py @@ -1,4 +1,3 @@ -from sssd.testlib.common.qe_class import session_multihost from sssd.testlib.common.libkrb5 import krb5srv from sssd.testlib.common.utils import sssdTools, PkiTools from sssd.testlib.common.utils import LdapOperations @@ -16,6 +15,11 @@ import ldap +pytest_plugins = ( + 'sssd.testlib.common.fixtures', +) + + def pytest_configure(): pytest.num_masters = 1 pytest.num_ad = 0 @@ -449,9 +453,6 @@ def setup_session(request, session_multihost, create_posix_usersgroups, enable_oddjob): """ Run all session scoped fixtures """ - # pylint: disable=unused-argument - _pytest_fixture = [package_install, run_authselect, - setup_ldap, setup_kerberos, create_posix_usersgroups] tp = TestPrep(session_multihost) tp.setup() diff --git a/src/tests/multihost/basic/mhc.yaml b/src/tests/multihost/basic/mhc.yaml index 6242f6ab06e..24d505481a6 100644 --- a/src/tests/multihost/basic/mhc.yaml +++ b/src/tests/multihost/basic/mhc.yaml @@ -4,5 +4,5 @@ domains: type: sssd hosts: - name: client - external_hostname: master.client.vm + external_hostname: client.test role: master diff --git a/src/tests/multihost/ipa/conftest.py b/src/tests/multihost/ipa/conftest.py index fd7e61131b0..a33815e65d3 100644 --- a/src/tests/multihost/ipa/conftest.py +++ b/src/tests/multihost/ipa/conftest.py @@ -7,13 +7,17 @@ import posixpath import pexpect import pytest -from sssd.testlib.common.qe_class import session_multihost from sssd.testlib.common.utils import sssdTools from sssd.testlib.ipa.utils import ipaTools from sssd.testlib.common.utils import ADOperations from sssd.testlib.common.paths import SSSD_DEFAULT_CONF +pytest_plugins = ( + 'sssd.testlib.common.fixtures', +) + + def pytest_configure(): """ Namespace hook to add below dict in the pytest namespace """ pytest.num_masters = 1 diff --git a/src/tests/multihost/sssd/testlib/common/fixtures.py b/src/tests/multihost/sssd/testlib/common/fixtures.py new file mode 100644 index 00000000000..502d0080baa --- /dev/null +++ b/src/tests/multihost/sssd/testlib/common/fixtures.py @@ -0,0 +1,60 @@ +import pytest +from pytest_multihost import make_multihost_fixture + +from .qe_class import QeConfig + + +@pytest.fixture(scope="session", autouse=True) +def session_multihost(request): + # pylint: disable=no-member + """Multihost plugin fixture for session scope""" + if pytest.num_ad > 0: + mhost = make_multihost_fixture(request, descriptions=[ + { + 'type': 'sssd', + 'hosts': + { + 'master': pytest.num_masters, + 'atomic': pytest.num_atomic, + 'replica': pytest.num_replicas, + 'client': pytest.num_clients, + 'other': pytest.num_others, + } + }, + { + 'type': 'ad', + 'hosts': + { + 'ad': pytest.num_ad, + }, + }, + ], config_class=QeConfig,) + else: + mhost = make_multihost_fixture(request, descriptions=[ + { + 'type': 'sssd', + 'hosts': + { + 'master': pytest.num_masters, + 'atomic': pytest.num_atomic, + 'replica': pytest.num_replicas, + 'client': pytest.num_clients, + 'other': pytest.num_others, + } + }, + ], config_class=QeConfig,) + mhost.domain = mhost.config.domains[0] + mhost.master = mhost.domain.hosts_by_role('master') + mhost.atomic = mhost.domain.hosts_by_role('atomic') + mhost.replica = mhost.domain.hosts_by_role('replica') + mhost.client = mhost.domain.hosts_by_role('client') + mhost.others = mhost.domain.hosts_by_role('other') + + if pytest.num_ad > 0: + mhost.ad = [] + for i in range(1, pytest.num_ad + 1): + print(i) + print(mhost.config.domains[i].hosts_by_role('ad')) + mhost.ad.extend(mhost.config.domains[i].hosts_by_role('ad')) + + yield mhost diff --git a/src/tests/multihost/sssd/testlib/common/qe_class.py b/src/tests/multihost/sssd/testlib/common/qe_class.py index 27be3fac27d..ae01b7150da 100644 --- a/src/tests/multihost/sssd/testlib/common/qe_class.py +++ b/src/tests/multihost/sssd/testlib/common/qe_class.py @@ -5,7 +5,6 @@ import time import logging import pytest -from pytest_multihost import make_multihost_fixture import pytest_multihost.config import pytest_multihost.host from .exceptions import SSSDException @@ -296,62 +295,6 @@ def __init__(self, config, name, domain_type): host_classes = {'default': QeHost, 'windows': QeWinHost} -@pytest.fixture(scope="session", autouse=True) -def session_multihost(request): - # pylint: disable=no-member - """Multihost plugin fixture for session scope""" - if pytest.num_ad > 0: - mhost = make_multihost_fixture(request, descriptions=[ - { - 'type': 'sssd', - 'hosts': - { - 'master': pytest.num_masters, - 'atomic': pytest.num_atomic, - 'replica': pytest.num_replicas, - 'client': pytest.num_clients, - 'other': pytest.num_others, - } - }, - { - 'type': 'ad', - 'hosts': - { - 'ad': pytest.num_ad, - }, - }, - ], config_class=QeConfig,) - else: - mhost = make_multihost_fixture(request, descriptions=[ - { - 'type': 'sssd', - 'hosts': - { - 'master': pytest.num_masters, - 'atomic': pytest.num_atomic, - 'replica': pytest.num_replicas, - 'client': pytest.num_clients, - 'other': pytest.num_others, - } - }, - ], config_class=QeConfig,) - mhost.domain = mhost.config.domains[0] - mhost.master = mhost.domain.hosts_by_role('master') - mhost.atomic = mhost.domain.hosts_by_role('atomic') - mhost.replica = mhost.domain.hosts_by_role('replica') - mhost.client = mhost.domain.hosts_by_role('client') - mhost.others = mhost.domain.hosts_by_role('other') - - if pytest.num_ad > 0: - mhost.ad = [] - for i in range(1, pytest.num_ad + 1): - print(i) - print(mhost.config.domains[i].hosts_by_role('ad')) - mhost.ad.extend(mhost.config.domains[i].hosts_by_role('ad')) - - yield mhost - - # pylint: disable=redefined-outer-name @pytest.fixture(scope='session', autouse=True) def create_testdir(session_multihost, request):