[IMP] unittest2 > unittest

The `unittest2` package is simply a backport of `unittest` from the
Standard Library of Python 2.7 to previous versions.

There is no reason to use it any longer.

Closes #6941
This commit is contained in:
Leonardo Rochael Almeida
2015-09-28 10:37:27 +02:00
committed by Martin Trigaux
parent 864ac67905
commit 06b3026bcd
39 changed files with 83 additions and 99 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
from openerp.addons.account.tests.account_test_classes import AccountingTestCase
import time
import unittest2
import unittest
class TestReconciliation(AccountingTestCase):
@@ -209,7 +209,7 @@ class TestReconciliation(AccountingTestCase):
self.account_rcv.id: {'debit': 42.0, 'credit': 0.0, 'amount_currency': 50, 'currency_id': self.currency_swiss_id},
})
@unittest2.skip('adapt to new accounting')
@unittest.skip('adapt to new accounting')
def test_balanced_exchanges_gain_loss(self):
# The point of this test is to show that we handle correctly the gain/loss exchanges during reconciliations in foreign currencies.
# For instance, with a company set in EUR, and a USD rate set to 0.033,
+2 -2
View File
@@ -1,4 +1,4 @@
import unittest2
import unittest
from openerp.tests.common import TransactionCase
class TestProductIdChange(TransactionCase):
@@ -17,7 +17,7 @@ class TestProductIdChange(TransactionCase):
self.product_model = self.registry('product.product')
self.so_line_model = self.registry('sale.order.line')
@unittest2.skip("""
@unittest.skip("""
Due to `sale` rewrite (94716a3f14d929574c46ef165e4364d12a5903ed),
the commit 503820acb6d82a85c0c49ac26f7e7f8cd73851dd has been partially ignored
during the forward-port to master and need to be rewritten using new-api.
+2 -2
View File
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
import unittest2
import unittest
from ..controllers import main
class ActionMungerTest(unittest2.TestCase):
class ActionMungerTest(unittest.TestCase):
def test_actual_treeview(self):
action = {
"views": [[False, "tree"], [False, "form"],
+2 -2
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import random
import unittest2
import unittest
from openerp.tools import topological_sort
@@ -10,7 +10,7 @@ def sample(population):
population,
random.randint(0, min(len(population), 5)))
class TestModulesLoading(unittest2.TestCase):
class TestModulesLoading(unittest.TestCase):
def setUp(self):
self.mods = map(str, range(1000))
def test_topological_sort(self):
+2 -2
View File
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
import textwrap
import unittest2
import unittest
from lxml import etree, html
from lxml.builder import E
@@ -10,7 +10,7 @@ from openerp.addons.base.ir import ir_qweb
from openerp.addons.web_editor.models.ir_qweb import html_to_text
class TestHTMLToText(unittest2.TestCase):
class TestHTMLToText(unittest.TestCase):
def test_rawstring(self):
self.assertEqual(
"foobar",
+3 -4
View File
@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
import unittest2
import unittest
from openerp.addons.website.models.website import slugify, unslug
class TestUnslug(unittest2.TestCase):
class TestUnslug(unittest.TestCase):
def test_unslug(self):
tests = {
'': (None, None),
@@ -24,7 +23,7 @@ class TestUnslug(unittest2.TestCase):
self.assertEqual(unslug(slug), expected)
class TestTitleToSlug(unittest2.TestCase):
class TestTitleToSlug(unittest.TestCase):
"""
Those tests should pass with or without python-slugify
See website/models/website.py slugify method
+2 -2
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import itertools
import unittest2
import unittest
from lxml import etree as ET, html
from lxml.html import builder as h
@@ -61,7 +61,7 @@ class TestViewSaving(common.TransactionCase):
company = self.registry('res.company').browse(self.cr, self.uid, 1)
self.assertEqual(company.phone, "+00 00 000 00 0 000")
@unittest2.skip("save conflict for embedded (saved by third party or previous version in page) not implemented")
@unittest.skip("save conflict for embedded (saved by third party or previous version in page) not implemented")
def test_embedded_conflict(self):
e1 = h.SPAN("My Company", attrs(model='res.company', id=1, field='name'))
e2 = h.SPAN("Leeroy Jenkins", attrs(model='res.company', id=1, field='name'))
-1
View File
@@ -44,7 +44,6 @@ Depends:
python-simplejson,
python-suds,
python-tz,
python-unittest2,
python-vatnumber,
python-vobject,
python-werkzeug,
-7
View File
@@ -1330,11 +1330,6 @@ command-line (or in a CI system), but while actually running it is
pretty simple the setup of the pre-requisite parts has some
complexities.
#. Install unittest2_ in your Python environment. Both
can trivially be installed via `pip <http://pip-installer.org>`_ or
`easy_install
<http://packages.python.org/distribute/easy_install.html>`_.
#. Install PhantomJS_. It is a headless
browser which allows automating running and testing web
pages. QUnitSuite_ uses it to actually run the qunit_ test suite.
@@ -1402,8 +1397,6 @@ the OpenERP Web test suite.
.. _qunit assertions: http://api.qunitjs.com/category/assert/
.. _unittest2: http://pypi.python.org/pypi/unittest2
.. _QUnitSuite: http://pypi.python.org/pypi/QUnitSuite/
.. _PhantomJS: http://phantomjs.org/
+1 -2
View File
@@ -7,7 +7,7 @@
Testing Modules
===============
Odoo provides support for testing modules using unittest2_.
Odoo provides support for testing modules using unittest.
To write tests, simply define a ``tests`` sub-package in your module, it will
be automatically inspected for test modules. Test modules should have a name
@@ -80,5 +80,4 @@ Odoo server.
As of Odoo 8, running tests outside of the install/update cycle is not
supported.
.. _unittest2: http://pypi.python.org/pypi/unittest2
.. _unittest documentation: https://docs.python.org/2/library/unittest.html
+2 -2
View File
@@ -1,4 +1,4 @@
import unittest2
import unittest
from lxml import etree
from openerp.exceptions import AccessError
@@ -165,4 +165,4 @@ class TestACL(common.TransactionCase):
self.erp_manager_group.write({'users': [(3, self.demo_uid)]})
if __name__ == '__main__':
unittest2.main()
unittest.main()
+5 -5
View File
@@ -1,4 +1,4 @@
import unittest2
import unittest
import openerp.tests.common as common
from openerp.exceptions import ValidationError
@@ -474,7 +474,7 @@ def tearDownModule():
global test_state
test_state = None
class TestPhaseInstall00(unittest2.TestCase):
class TestPhaseInstall00(unittest.TestCase):
"""
WARNING: Relies on tests being run in alphabetical order
"""
@@ -494,7 +494,7 @@ class TestPhaseInstall00(unittest2.TestCase):
self.state, 'init',
"Testcase state should not have been transitioned from 00")
class TestPhaseInstall01(unittest2.TestCase):
class TestPhaseInstall01(unittest.TestCase):
at_install = False
def test_default_norun(self):
@@ -504,7 +504,7 @@ class TestPhaseInstall01(unittest2.TestCase):
def test_set_run(self):
test_state['set_at_install'] = True
class TestPhaseInstall02(unittest2.TestCase):
class TestPhaseInstall02(unittest.TestCase):
"""
Can't put the check for test_set_run in the same class: if
@common.at_install does not work for test_set_run, it won't work for
@@ -520,4 +520,4 @@ class TestPhaseInstall02(unittest2.TestCase):
"The flag should be set if local overriding of runstate")
if __name__ == '__main__':
unittest2.main()
unittest.main()
+2 -2
View File
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
import unittest2
import unittest
from openerp.tests import common
@@ -83,4 +83,4 @@ class test_transaction_case(common.TransactionCase):
self.assertEqual(partner, p_browse_ref, "browse_ref() should resolve xid to browse records")
if __name__ == '__main__':
unittest2.main()
unittest.main()
+2 -2
View File
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
import unittest2
import unittest
import openerp
from openerp.tools.misc import mute_logger
@@ -12,7 +12,7 @@ def registry():
return openerp.modules.registry.RegistryManager.get(common.get_db_name())
class test_cr_execute(unittest2.TestCase):
class test_cr_execute(unittest.TestCase):
""" Try cr.execute with wrong parameters """
@mute_logger('openerp.sql_db')
+2 -2
View File
@@ -1,4 +1,4 @@
import unittest2
import unittest
import openerp
from openerp.osv.expression import get_unaccent_wrapper
@@ -521,4 +521,4 @@ class test_expression(common.TransactionCase):
self.env['res.users'].search([('name', '=', 'test')])
if __name__ == '__main__':
unittest2.main()
unittest.main()
+2 -2
View File
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
import functools
import unittest2
import unittest
from openerp.tools.func import compose
class TestCompose(unittest2.TestCase):
class TestCompose(unittest.TestCase):
def test_basic(self):
str_add = compose(str, lambda a, b: a + b)
self.assertEqual(
+2 -2
View File
@@ -1,4 +1,4 @@
import unittest2
import unittest
from openerp.exceptions import ValidationError
import openerp.tests.common as common
@@ -403,4 +403,4 @@ workflow"""
if __name__ == '__main__':
unittest2.main()
unittest.main()
@@ -9,7 +9,7 @@
# This assume an existing database.
import psycopg2
import psycopg2.errorcodes
import unittest2
import unittest
import openerp
from openerp.tests import common
@@ -31,7 +31,7 @@ def drop_sequence(code):
cr.commit()
cr.close()
class test_ir_sequence_standard(unittest2.TestCase):
class test_ir_sequence_standard(unittest.TestCase):
""" A few tests for a 'Standard' (i.e. PostgreSQL) sequence. """
def test_ir_sequence_create(self):
@@ -76,7 +76,7 @@ class test_ir_sequence_standard(unittest2.TestCase):
def tearDownClass(cls):
drop_sequence('test_sequence_type')
class test_ir_sequence_no_gap(unittest2.TestCase):
class test_ir_sequence_no_gap(unittest.TestCase):
""" Copy of the previous tests for a 'No gap' sequence. """
def test_ir_sequence_create_no_gap(self):
@@ -116,7 +116,7 @@ class test_ir_sequence_no_gap(unittest2.TestCase):
def tearDownClass(cls):
drop_sequence('test_sequence_type_2')
class test_ir_sequence_change_implementation(unittest2.TestCase):
class test_ir_sequence_change_implementation(unittest.TestCase):
""" Create sequence objects and change their ``implementation`` field. """
def test_ir_sequence_1_create(self):
@@ -156,7 +156,7 @@ class test_ir_sequence_change_implementation(unittest2.TestCase):
drop_sequence('test_sequence_type_3')
drop_sequence('test_sequence_type_4')
class test_ir_sequence_generate(unittest2.TestCase):
class test_ir_sequence_generate(unittest.TestCase):
""" Create sequence objects and generate some values. """
def test_ir_sequence_create(self):
@@ -224,4 +224,4 @@ class Test_ir_sequence_init(common.TransactionCase):
assert read_sequence == "0001", 'The actual sequence value must be 1. reading : %s' % read_sequence
if __name__ == "__main__":
unittest2.main()
unittest.main()
@@ -1,4 +1,4 @@
import unittest2
import unittest
from openerp.tests import common
from datetime import date
@@ -119,4 +119,4 @@ class test_ir_sequence_date_range_change_implementation(common.SingleTransaction
if __name__ == '__main__':
unittest2.main()
unittest.main()
+2 -2
View File
@@ -1,4 +1,4 @@
import unittest2
import unittest
import openerp.tests.common as common
@@ -95,4 +95,4 @@ class test_ir_values(common.TransactionCase):
assert isinstance(actions[0][2], dict) and actions[0][2]['id'] == report_id, 'Bound action does not match definition'
if __name__ == '__main__':
unittest2.main()
unittest.main()
+6 -6
View File
@@ -4,13 +4,13 @@
# > PYTHONPATH=. python2 openerp/tests/test_misc.py
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import unittest2
import unittest
from openerp.tools import html_sanitize, html_email_clean, append_content_to_html, plaintext2html, email_split
import test_mail_examples
class TestSanitizer(unittest2.TestCase):
class TestSanitizer(unittest.TestCase):
""" Test the html sanitizer that filters html to remove unwanted attributes """
def test_basic_sanitizer(self):
@@ -111,7 +111,7 @@ class TestSanitizer(unittest2.TestCase):
self.assertNotIn('</body></html>', html, 'html_sanitize did not remove extra closing tags')
class TestCleaner(unittest2.TestCase):
class TestCleaner(unittest.TestCase):
""" Test the email cleaner function that filters the content of incoming emails """
def test_00_basic_text(self):
@@ -340,7 +340,7 @@ class TestCleaner(unittest2.TestCase):
self.assertNotIn('encoding', new_html, 'html_email_cleaner did not remove correctly encoding attributes')
class TestHtmlTools(unittest2.TestCase):
class TestHtmlTools(unittest.TestCase):
""" Test some of our generic utility functions about html """
def test_plaintext2html(self):
@@ -367,7 +367,7 @@ class TestHtmlTools(unittest2.TestCase):
self.assertEqual(append_content_to_html(html, content, plaintext_flag, preserve_flag, container_tag), expected, 'append_content_to_html is broken')
class TestEmailTools(unittest2.TestCase):
class TestEmailTools(unittest.TestCase):
""" Test some of our generic utility functions for emails """
def test_email_split(self):
@@ -382,4 +382,4 @@ class TestEmailTools(unittest2.TestCase):
self.assertEqual(email_split(text), expected, 'email_split is broken')
if __name__ == '__main__':
unittest2.main()
unittest.main()
+3 -3
View File
@@ -1,9 +1,9 @@
import unittest2
import unittest
from openerp.tools import misc
class test_countingstream(unittest2.TestCase):
class test_countingstream(unittest.TestCase):
def test_empty_stream(self):
s = misc.CountingStream(iter([]))
self.assertEqual(s.index, -1)
@@ -34,4 +34,4 @@ class test_countingstream(unittest2.TestCase):
self.assertEqual(s.index, 0)
if __name__ == '__main__':
unittest2.main()
unittest.main()
+1 -1
View File
@@ -1,4 +1,4 @@
import unittest2
import unittest
import openerp
import openerp.tests.common as common
+1 -1
View File
@@ -1,4 +1,4 @@
import unittest2
import unittest
import openerp.tests.common as common
+2 -2
View File
@@ -1,4 +1,4 @@
import unittest2
import unittest
import openerp.tests.common as common
@@ -161,4 +161,4 @@ class test_search(common.TransactionCase):
self.assertEqual(search_result, expected_order)
if __name__ == '__main__':
unittest2.main()
unittest.main()
+3 -3
View File
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# This assumes an existing but uninitialized database.
import unittest2
import unittest
import openerp
from openerp import SUPERUSER_ID
@@ -51,7 +51,7 @@ def uninstall_module(module_name):
cr.close()
reload_registry()
class test_uninstall(unittest2.TestCase):
class test_uninstall(unittest.TestCase):
"""
Test the install/uninstall of a test module. The module is available in
`openerp.tests` which should be present in the addons-path.
@@ -82,4 +82,4 @@ class test_uninstall(unittest2.TestCase):
if __name__ == '__main__':
unittest2.main()
unittest.main()
@@ -2,7 +2,7 @@
# > PYTHONPATH=. python2 openerp/tests/test_view_validation.py
from lxml import etree
from StringIO import StringIO
import unittest2
import unittest
from openerp.tools.view_validation import (valid_page_in_book, valid_att_in_form, valid_type_in_colspan,
valid_type_in_col, valid_att_in_field, valid_att_in_label,
@@ -92,7 +92,7 @@ valid_tree = etree.parse(StringIO('''\
''')).getroot()
class test_view_validation(unittest2.TestCase):
class test_view_validation(unittest.TestCase):
""" Test the view validation code (but not the views themselves). """
def test_page_validation(self):
@@ -128,4 +128,4 @@ class test_view_validation(unittest2.TestCase):
if __name__ == '__main__':
unittest2.main()
unittest.main()
+1 -1
View File
@@ -2,7 +2,7 @@
from functools import partial
import itertools
import unittest2
import unittest
from lxml import etree as ET
from lxml.builder import E
@@ -1,5 +1,5 @@
import collections
import unittest2
import unittest
from lxml import etree as ET
from lxml.builder import E
@@ -72,10 +72,10 @@ class TestEvalXML(common.TransactionCase):
with self.assertRaises(IOError):
self.eval_xml(Field('test_nofile.txt', type='file'), obj)
@unittest2.skip("not tested")
@unittest.skip("not tested")
def test_xml(self):
pass
@unittest2.skip("not tested")
@unittest.skip("not tested")
def test_html(self):
pass
+1 -1
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import json
import pkgutil
import unittest2
import unittest
import openerp.modules.registry
import openerp
+7 -7
View File
@@ -15,7 +15,7 @@ import unittest
import threading
from os.path import join as opj
import unittest2
import unittest
import openerp
import openerp.tools as tools
@@ -377,7 +377,7 @@ def adapt_version(version):
def get_test_modules(module):
""" Return a list of module for the addons potentially containing tests to
feed unittest2.TestLoader.loadTestsFromModule() """
feed unittest.TestLoader.loadTestsFromModule() """
# Try to import the module
modpath = 'openerp.addons.' + module
try:
@@ -446,14 +446,14 @@ def run_unit_tests(module_name, dbname, position=runs_at_install):
threading.currentThread().testing = True
r = True
for m in mods:
tests = unwrap_suite(unittest2.TestLoader().loadTestsFromModule(m))
suite = unittest2.TestSuite(itertools.ifilter(position, tests))
tests = unwrap_suite(unittest.TestLoader().loadTestsFromModule(m))
suite = unittest.TestSuite(itertools.ifilter(position, tests))
if suite.countTestCases():
t0 = time.time()
t0_sql = openerp.sql_db.sql_counter
_logger.info('%s running tests.', m.__name__)
result = unittest2.TextTestRunner(verbosity=2, stream=TestStream(m.__name__)).run(suite)
result = unittest.TextTestRunner(verbosity=2, stream=TestStream(m.__name__)).run(suite)
if time.time() - t0 > 5:
_logger.log(25, "%s tested in %.2fs, %s queries", m.__name__, time.time() - t0, openerp.sql_db.sql_counter - t0_sql)
if not result.wasSuccessful():
@@ -471,8 +471,8 @@ def unwrap_suite(test):
test suites). These can then be checked for run/skip attributes
individually.
An alternative would be to use a variant of @unittest2.skipIf with a state
flag of some sort e.g. @unittest2.skipIf(common.runstate != 'at_install'),
An alternative would be to use a variant of @unittest.skipIf with a state
flag of some sort e.g. @unittest.skipIf(common.runstate != 'at_install'),
but then things become weird with post_install as tests should *not* run
by default there
"""
+4 -4
View File
@@ -15,7 +15,7 @@ import subprocess
import sys
import threading
import time
import unittest2
import unittest
import werkzeug.serving
from werkzeug.debug import DebuggedApplication
@@ -860,12 +860,12 @@ def load_test_file_py(registry, test_file):
if mod_mod:
mod_path, _ = os.path.splitext(getattr(mod_mod, '__file__', ''))
if test_path == mod_path:
suite = unittest2.TestSuite()
for t in unittest2.TestLoader().loadTestsFromModule(mod_mod):
suite = unittest.TestSuite()
for t in unittest.TestLoader().loadTestsFromModule(mod_mod):
suite.addTest(t)
_logger.log(logging.INFO, 'running tests %s.', mod_mod.__name__)
stream = openerp.modules.module.TestStream()
result = unittest2.TextTestRunner(verbosity=2, stream=stream).run(suite)
result = unittest.TextTestRunner(verbosity=2, stream=stream).run(suite)
success = result.wasSuccessful()
if hasattr(registry._assertion_report,'report_result'):
registry._assertion_report.report_result(success)
+4 -4
View File
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""
The module :mod:`openerp.tests.common` provides unittest2 test cases and a few
The module :mod:`openerp.tests.common` provides unittest test cases and a few
helpers and classes to write tests.
"""
@@ -15,7 +15,7 @@ import subprocess
import threading
import time
import itertools
import unittest2
import unittest
import urllib2
import xmlrpclib
from contextlib import contextmanager
@@ -79,7 +79,7 @@ def post_install(flag):
return obj
return decorator
class BaseCase(unittest2.TestCase):
class BaseCase(unittest.TestCase):
"""
Subclass of TestCase for common OpenERP-specific code.
@@ -352,7 +352,7 @@ class HttpCase(TransactionCase):
try:
phantom = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=None)
except OSError:
raise unittest2.SkipTest("PhantomJS not found")
raise unittest.SkipTest("PhantomJS not found")
try:
self.phantom_poll(phantom, timeout)
finally:
+1 -1
View File
@@ -2,7 +2,7 @@
class assertion_report(object):
"""
Simple pair of success and failures counts (used to record YAML and XML
`assert` tags as well as unittest2 tests outcome (in this case, not
`assert` tags as well as unittest tests outcome (in this case, not
individual `assert`)).
"""
def __init__(self):
-1
View File
@@ -36,7 +36,6 @@ requests==2.6.0
simplejson==3.6.5
six==1.9.0
suds-jurko==0.6
unittest2==0.8.0
vatnumber==1.2
vobject==0.6.6
wsgiref==0.1.2
-1
View File
@@ -26,7 +26,6 @@ requires =
python-reportlab
python-requests
python-simplejson
python-unittest2
python-vobject
python-werkzeug
python-yaml
-2
View File
@@ -162,7 +162,6 @@ setup(
'requests',
'simplejson',
'suds-jurko',
'unittest2',
'vatnumber',
'vobject',
'werkzeug',
@@ -172,7 +171,6 @@ setup(
'SSL': ['pyopenssl'],
},
tests_require=[
'unittest2',
'mock',
],
**py2exe_options()
-1
View File
@@ -30,7 +30,6 @@ RUN yum install -d 0 -e 0 epel-release -y && \
python-reportlab \
python-requests \
python-simplejson \
python-unittest2 \
python-vobject \
python-werkzeug \
python-yaml \
-1
View File
@@ -48,7 +48,6 @@ RUN apt-get update -qq && \
python-simplejson \
python-suds \
python-tz \
python-unittest2 \
python-vatnumber \
python-vobject \
python-werkzeug \