[damned-lies] Prevented logging warnings in test output
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Prevented logging warnings in test output
- Date: Fri, 20 Dec 2019 15:50:04 +0000 (UTC)
commit ea4b96e43d9df3a44ee6b39b34a776efd99f29fe
Author: Claude Paroz <claude 2xlibre net>
Date: Fri Dec 20 16:49:21 2019 +0100
Prevented logging warnings in test output
stats/models.py | 10 ++++++----
stats/tests/tests.py | 15 ++++++++++-----
teams/tests.py | 3 ++-
3 files changed, 18 insertions(+), 10 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index c145b920..3a46a47d 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -29,6 +29,8 @@ from stats.doap import update_doap_infos
from people.models import Person
from languages.models import Language
+logger = logging.getLogger(__name__)
+
# These args should be kept in sync with
# https://github.com/mesonbuild/meson/blob/master/mesonbuild/modules/i18n.py#L25
GLIB_PRESET = (
@@ -458,7 +460,7 @@ class Branch(models.Model):
# *****************************
previous_pot = self.output_dir(dom.dtype) / ('%s.%s.pot' % (dom.potbase(),
self.name_escaped))
if not potfile:
- logging.error("Can't generate POT file for %s/%s." % (
+ logger.error("Can't generate POT file for %s/%s." % (
self.module.name, dom.name))
if previous_pot.exists():
# Use old POT file
@@ -546,7 +548,7 @@ class Branch(models.Model):
def checkout(self):
""" Do a checkout or an update of the VCS files """
- logging.debug("Checking '%s.%s' out to '%s'…" % (self.module.name, self.name, self.co_path))
+ logger.debug("Checking '%s.%s' out to '%s'…" % (self.module.name, self.name, self.co_path))
self._repo.checkout()
def update_repo(self):
@@ -555,7 +557,7 @@ class Branch(models.Model):
WARNING: the calling method should acquire a lock
for the module to not mix checkouts in different threads/processes.
"""
- logging.debug("Updating '%s.%s' (in '%s')..." % (self.module.name, self.name, self.co_path))
+ logger.debug("Updating '%s.%s' (in '%s')..." % (self.module.name, self.name, self.co_path))
self._repo.update()
def commit_po(self, po_file, domain, language, author):
@@ -1594,7 +1596,7 @@ class Statistics(models.Model):
for err in fig_errors:
self.set_error(*err)
- logging.debug("%s:\n%s" % (self.language, str(stats)))
+ logger.debug("%s:\n%s" % (self.language, str(stats)))
def set_error(self, tp, description):
Information.objects.create(statistics=self, type=tp, description=description)
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index f0c14c35..86be07c9 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -75,10 +75,12 @@ class ModuleTestCase(TestCase):
response = self.client.get(reverse('module_branch', args=['gnome-hello', 'master']))
self.assertContains(response, '<table class="stats table">')
# Missing branch
- response = self.client.get(reverse('module_branch', args=['gnome-hello', 'missing']))
+ with self.assertLogs('django.request', level='WARNING'):
+ response = self.client.get(reverse('module_branch', args=['gnome-hello', 'missing']))
self.assertEqual(response.status_code, 404)
# Branch name with slash is reverse-able
- response = self.client.get(reverse('module_branch', args=['gnome-hello', 'with/slash']))
+ with self.assertLogs('django.request', level='WARNING'):
+ response = self.client.get(reverse('module_branch', args=['gnome-hello', 'with/slash']))
self.assertEqual(response.status_code, 404)
def test_module_bugs_reporting(self):
@@ -354,8 +356,10 @@ class ModuleTestCase(TestCase):
po_file = Path(__file__).parent / 'test.po'
domain = self.mod.domain_set.get(name='po')
fr_lang = Language.objects.get(locale='fr')
- with self.assertRaisesRegex(UnableToCommit, 'read only'):
- branch.commit_po(po_file, domain, fr_lang, 'Author <someone example org>')
+ with patch_shell_command():
+ with self.assertRaisesRegex(UnableToCommit, 'read only'):
+ with self.assertLogs('stats.models', level='ERROR'):
+ branch.commit_po(po_file, domain, fr_lang, 'Author <someone example org>')
# Setup as a writable repo
self.mod.vcs_root = 'git gitlab gnome org:GNOME/%s.git' % self.mod.name
self.mod.save()
@@ -384,7 +388,8 @@ class ModuleTestCase(TestCase):
'git push origin master'
)
with patch_shell_command() as cmds:
- branch.commit_po(po_file, domain, bem_lang, 'Author <someone example org>')
+ with self.assertLogs('stats.models', level='ERROR'):
+ branch.commit_po(po_file, domain, bem_lang, 'Author <someone example org>')
for idx, cmd in enumerate(git_ops):
self.assertIn(cmd, cmds[idx])
self.assertIn('intltool-update -g', cmds[-1])
diff --git a/teams/tests.py b/teams/tests.py
index 2b7e80b3..55e396c4 100644
--- a/teams/tests.py
+++ b/teams/tests.py
@@ -159,7 +159,8 @@ class TeamTests(TeamsAndRolesMixin, TestCase):
def test_edit_team(self):
""" Test team edit form """
edit_url = reverse('team_edit', args = ['fr'], current_app='teams')
- response = self.client.get(edit_url)
+ with self.assertLogs('django.request', level='WARNING'):
+ response = self.client.get(edit_url)
self.assertEqual(response.status_code, 403)
# Login as team coordinator
response = self.client.post('/login/',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]