#11 Miscellaneous changes
Merged 3 years ago by pingou. Opened 3 years ago by nphilipp.
fedora-infra/ nphilipp/toddlers master--misc  into  master

file modified
+2 -2
@@ -1,7 +1,7 @@ 

- import toddlers.plugins.debug

- 

  import fedora_messaging.api

  

+ import toddlers.plugins.debug

+ 

  

  class TestDebugToddler:

      def test_accepts_topic(self):

@@ -1,10 +1,10 @@ 

  import logging

- from unittest.mock import patch, MagicMock

+ from unittest.mock import MagicMock, patch

  

- import toddlers.plugins.flag_ci_pr

+ import fedora_messaging.api

  import pytest

  

- import fedora_messaging.api

+ import toddlers.plugins.flag_ci_pr

  

  

  class TestFlagCIPRToddler:

@@ -1,5 +1,5 @@ 

  import logging

- from unittest.mock import patch, MagicMock, Mock

+ from unittest.mock import MagicMock, Mock, patch

  

  import fedora_messaging.api

  import pytest

@@ -1,4 +1,4 @@ 

- from unittest.mock import patch, Mock

+ from unittest.mock import Mock, patch

  

  import pytest

  
@@ -118,12 +118,15 @@ 

      def test_main_no_args(self, capsys):

          with pytest.raises(SystemExit):

              toddlers.plugins.packager_bugzilla_sync.main([])

+ 

          out, err = capsys.readouterr()

-         exp = """usage: pytest [-h] [--dry-run] [-q | --debug] conf [username]

- pytest: error: the following arguments are required: conf

- """

          assert out == ""

-         assert err == exp

+         # Expecting something along these lines, but don't make the test too tight:

+         #

+         # usage: pytest [-h] [--dry-run] [-q | --debug] conf [username]

+         # pytest: error: the following arguments are required: conf

+         assert err.startswith("usage:")

+         assert "error: the following arguments are required:" in err

  

      @patch("toml.load", new=Mock(return_value={}))

      def test_main_debug(self, capsys):

file modified
+7 -4
@@ -12,12 +12,15 @@ 

      def test_playtime_no_args(self, capsys):

          with pytest.raises(SystemExit):

              toddlers.playtime.main([])

+ 

          out, err = capsys.readouterr()

-         exp = """usage: pytest [-h] [--conf CONF] [--debug] name

- pytest: error: the following arguments are required: name

- """

          assert out == ""

-         assert err == exp

+         # Expecting something along these lines, but don't make the test too tight:

+         #

+         # usage: pytest [-h] [--conf CONF] [--debug] name

+         # pytest: error: the following arguments are required: name

+         assert err.startswith("usage:")

+         assert "error: the following arguments are required:" in err

  

      def test_playtime_arg(self, capsys):

          with fedora_messaging.testing.mock_sends(

file modified
+2 -2
@@ -1,5 +1,5 @@ 

  import logging

- from unittest.mock import patch, Mock

+ from unittest.mock import Mock, patch

  

  import fedora_messaging.api

  import fedora_messaging.exceptions
@@ -18,7 +18,7 @@ 

              "packager_bugzilla_sync",

          ]

  

-     @patch("toddlers.base.ToddlerBase")

+     @patch("toddlers.runner.ToddlerBase")

      def test___init__no_toddlers(self, mock_base, caplog):

          mock_base.__subclasses__ = Mock(return_value=[])

          caplog.set_level(logging.INFO)

@@ -1,6 +1,6 @@ 

  import logging

- import xmlrpc.client

  from unittest.mock import Mock, patch

+ import xmlrpc.client

  

  import pytest

  

file modified
+4 -2
@@ -4,12 +4,14 @@ 

  class ToddlerBase(object):

      __metaclass__ = abc.ABCMeta

  

-     @abc.abstractproperty

+     @property

+     @abc.abstractmethod

      def name():

          """Returns name of the plugin."""

          return "base"

  

-     @abc.abstractproperty

+     @property

+     @abc.abstractmethod

      def amqp_topics():

          """Returns the list of topics of interest for this toddler in a format

          that can be used directly when connecting to amqp.

file modified
+1 -1
@@ -6,4 +6,4 @@ 

  for name in os.listdir(here):

      if name.endswith(".py") and not name.startswith("__"):

          name = name[:-3]

-         importlib.__import__(f"toddlers.plugins.{name}")

+         importlib.import_module(f".{name}", package=__name__)

file modified
+1 -1
@@ -9,7 +9,7 @@ 

  

  import logging

  

- from toddlers.base import ToddlerBase

+ from ..base import ToddlerBase

  

  

  _log = logging.getLogger(__name__)

@@ -13,7 +13,7 @@ 

  import requests

  from requests.packages.urllib3.util import retry

  

- from toddlers.base import ToddlerBase

+ from ..base import ToddlerBase

  

  

  _log = logging.getLogger(__name__)

@@ -13,7 +13,7 @@ 

  import requests

  from requests.packages.urllib3.util import retry

  

- from toddlers.base import ToddlerBase

+ from ..base import ToddlerBase

  

  

  _log = logging.getLogger(__name__)

@@ -13,17 +13,18 @@ 

  import sys

  

  import requests

- import toml

  from requests.packages.urllib3.util import retry

+ import toml

  

  try:

      import tqdm

  except ImportError:

      tqdm = None

  

- from toddlers.base import ToddlerBase

- import toddlers.utils.fedora_account

- import toddlers.utils.bugzilla_system

+ from ..base import ToddlerBase

+ from ..utils import bugzilla_system

+ from ..utils import fedora_account

+ 

  

  _log = logging.getLogger(__name__)

  
@@ -67,14 +68,12 @@ 

              raise

  

          _log.info("Setting up connection to FAS")

-         toddlers.utils.fedora_account.set_fas(config)

+         fedora_account.set_fas(config)

  

          if not username:

              # Retrieve all the packagers in FAS:

              _log.info("Retrieving the list of packagers in FAS")

-             fas_packagers = sorted(

-                 toddlers.utils.fedora_account.get_group_member("packager")

-             )

+             fas_packagers = sorted(fedora_account.get_group_member("packager"))

          else:

              fas_packagers = [username]

  
@@ -96,19 +95,15 @@ 

              _log.debug(

                  f"   Retrieving bz email of user {username}: {idx}/{n_packagers}"

              )

-             bz_email = toddlers.utils.fedora_account.get_bz_email_user(

-                 username, email_overrides

-             )

+             bz_email = fedora_account.get_bz_email_user(username, email_overrides)

              fas_packagers_info[bz_email] = username

  

          _log.info("Setting up connection to bugzilla")

-         toddlers.utils.bugzilla_system.set_bz(config)

+         bugzilla_system.set_bz(config)

  

          # Retrieve all the packagers in bugzilla

          _log.info("Retrieving the list of packagers in bugzilla")

-         bz_packagers = toddlers.utils.bugzilla_system.get_group_member(

-             config["bugzilla_group"]

-         )

+         bz_packagers = bugzilla_system.get_group_member(config["bugzilla_group"])

          n_bz_packagers = len(bz_packagers)

          _log.info(

              f"{n_bz_packagers} members of {config['bugzilla_group']} found in bugzilla"
@@ -130,7 +125,7 @@ 

          # Add the packagers found only in FAS to the bugzilla group

          _log.info(f"Adding to {config['bugzilla_group']} the packagers found in FAS")

          for user_email in sorted(fas_only):

-             no_bz_account = toddlers.utils.bugzilla_system.add_user_to_group(

+             no_bz_account = bugzilla_system.add_user_to_group(

                  user_email=user_email,

                  bz_group=config["bugzilla_group"],

                  no_bz_account=no_bz_account,

file modified
+5 -4
@@ -1,10 +1,11 @@ 

  import logging

  

- import fedora_messaging.exceptions

  import fedora_messaging.config

+ import fedora_messaging.exceptions

+ 

+ from . import plugins  # noqa: F401

+ from .base import ToddlerBase

  

- import toddlers.base

- import toddlers.plugins

  

  _log = logging.getLogger(__name__)

  
@@ -27,7 +28,7 @@ 

              or []

          )

          self.toddlers = []

-         for toddler in toddlers.base.ToddlerBase.__subclasses__():

+         for toddler in ToddlerBase.__subclasses__():

              if toddler.name in blocked_toddlers:

                  _log.info("Toddler '%s' is blocked, skipping it", toddler.name)

                  continue

@@ -1,7 +1,6 @@ 

  import logging

- import xmlrpc.client

- 

  from typing import Mapping

+ import xmlrpc.client

  

  from bugzilla import Bugzilla

  

file modified
+1 -1
@@ -1,5 +1,5 @@ 

- import smtplib

  from email.message import EmailMessage

+ import smtplib

  

  

  def notify_packager(mail_server, admin_email, username, email):

file modified
+1
@@ -22,5 +22,6 @@ 

  [testenv:flake8]

  deps =

      flake8

+     flake8-import-order

  commands =

      flake8 .

  • don't use deprecated decorators
  • cope with different ways of invoking pytest
  • appease flake8 and use its import plugin
  • use importlib.import_module() rather than .__import__()
  • use relative imports within the package

Build succeeded.

  • tox : SUCCESS in 4m 07s

1 new commit added

  • Depend on the flake8 import-order plugin for tox
3 years ago

Build succeeded.

  • tox : SUCCESS in 5m 05s

2 new commits added

  • Use relative imports within the toddlers package
  • Don't use importlib.__import__() directly
3 years ago

Build failed.

  • tox : FAILURE in 4m 05s

6 new commits added

  • Use relative imports within the toddlers package
  • Don't use importlib.__import__() directly
  • Depend on the flake8 import-order plugin for tox
  • Fix import order, separation to appease flake8
  • Tests: Cope with different invocation methods
  • Don't use deprecated @abstractproperty
3 years ago

Build failed.

  • tox : FAILURE in 3m 26s

1 new commit added

  • Tests: patch object in the right place
3 years ago

Build failed.

  • tox : FAILURE in 3m 23s

7 new commits added

  • Tests: patch object in the right place
  • Use relative imports within the toddlers package
  • Don't use importlib.__import__() directly
  • Depend on the flake8 import-order plugin for tox
  • Fix import order, separation to appease flake8
  • Tests: Cope with different invocation methods
  • Don't use deprecated @abstractproperty
3 years ago

Build succeeded.

  • tox : SUCCESS in 3m 05s

Pull-Request has been merged by pingou

3 years ago