Skip to content

Commit

Permalink
Use odoo.tools.mute_logger
Browse files Browse the repository at this point in the history
  • Loading branch information
yajo committed Jul 4, 2017
1 parent 973f47b commit d577616
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions html_text/tests/test_extractor.py
Expand Up @@ -2,25 +2,18 @@
# Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging

from lxml import etree
from odoo.tools import mute_logger
from odoo.tests.common import TransactionCase
from ..models import ir_fields_converter


class ExtractorCase(TransactionCase):
def setUp(self):
super(ExtractorCase, self).setUp()
# Silent errors to keep beautiful logs and make CI pass
ir_fields_converter._logger.disable(logging.ERROR)
# Shortcut
self.text_from_html = self.env["ir.fields.converter"].text_from_html

def tearDown(self):
ir_fields_converter._logger.disable(logging.NOTSET)
super(ExtractorCase, self).tearDown()

def test_excerpts(self):
"""Text gets correctly extracted."""
html = u"""
Expand Down Expand Up @@ -48,18 +41,21 @@ def test_excerpts(self):
self.text_from_html(html, 7, ellipsis=""),
u"I'm a title I'm a paragraph ¡Pues")

@mute_logger(ir_fields_converter.__name__)
def test_empty_html(self):
"""Empty HTML handled correctly."""
self.assertEqual(self.text_from_html(""), "")
with self.assertRaises(etree.XMLSyntaxError):
self.text_from_html("", fail=True)

@mute_logger(ir_fields_converter.__name__)
def test_false_html(self):
"""``False`` HTML handled correctly."""
self.assertEqual(self.text_from_html(False), "")
with self.assertRaises(TypeError):
self.text_from_html(False, fail=True)

@mute_logger(ir_fields_converter.__name__)
def test_bad_html(self):
"""Bad HTML handled correctly."""
self.assertEqual(self.text_from_html("<<bad>"), "")
Expand Down

0 comments on commit d577616

Please sign in to comment.