From 36f3adca1ecb8463e2de1039d30c7e1e38ae68fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 9 Jun 2024 12:45:39 +0200 Subject: [PATCH] Add TestCase to filter warnings with TEST_PYTHONWARNINGS --- modules/currency/tests/test_module.py | 6 +- trytond-gis/trytond_gis/tests/test_fields.py | 6 +- trytond/doc/ref/tests.rst | 14 +++- trytond/trytond/tests/test_access.py | 10 +-- trytond/trytond/tests/test_backend.py | 6 +- trytond/trytond/tests/test_bus.py | 6 +- trytond/trytond/tests/test_cache.py | 10 +-- trytond/trytond/tests/test_copy.py | 7 +- trytond/trytond/tests/test_exportdata.py | 6 +- trytond/trytond/tests/test_field_binary.py | 6 +- trytond/trytond/tests/test_field_boolean.py | 6 +- trytond/trytond/tests/test_field_char.py | 6 +- trytond/trytond/tests/test_field_context.py | 7 +- trytond/trytond/tests/test_field_date.py | 5 +- trytond/trytond/tests/test_field_datetime.py | 6 +- trytond/trytond/tests/test_field_depends.py | 6 +- trytond/trytond/tests/test_field_dict.py | 4 +- trytond/trytond/tests/test_field_float.py | 6 +- trytond/trytond/tests/test_field_function.py | 7 +- trytond/trytond/tests/test_field_integer.py | 6 +- trytond/trytond/tests/test_field_many2many.py | 8 +-- trytond/trytond/tests/test_field_many2one.py | 8 +-- .../tests/test_field_multiselection.py | 5 +- trytond/trytond/tests/test_field_numeric.py | 7 +- trytond/trytond/tests/test_field_one2many.py | 12 ++-- trytond/trytond/tests/test_field_one2one.py | 6 +- trytond/trytond/tests/test_field_reference.py | 6 +- trytond/trytond/tests/test_field_selection.py | 6 +- trytond/trytond/tests/test_field_text.py | 9 +-- trytond/trytond/tests/test_field_time.py | 6 +- trytond/trytond/tests/test_field_timedelta.py | 6 +- trytond/trytond/tests/test_filestore.py | 4 +- trytond/trytond/tests/test_history.py | 5 +- trytond/trytond/tests/test_i18n.py | 7 +- trytond/trytond/tests/test_importdata.py | 6 +- trytond/trytond/tests/test_ir.py | 4 +- trytond/trytond/tests/test_mixins.py | 10 +-- trytond/trytond/tests/test_model.py | 11 +-- trytond/trytond/tests/test_model_index.py | 5 +- trytond/trytond/tests/test_model_log.py | 6 +- trytond/trytond/tests/test_model_match.py | 5 +- trytond/trytond/tests/test_modelsingleton.py | 7 +- trytond/trytond/tests/test_modelsql.py | 6 +- trytond/trytond/tests/test_modelstorage.py | 8 +-- trytond/trytond/tests/test_modelview.py | 5 +- trytond/trytond/tests/test_mptt.py | 6 +- trytond/trytond/tests/test_multivalue.py | 6 +- trytond/trytond/tests/test_order.py | 6 +- trytond/trytond/tests/test_path.py | 4 +- trytond/trytond/tests/test_protocols.py | 6 +- trytond/trytond/tests/test_pyson.py | 3 +- trytond/trytond/tests/test_report.py | 6 +- trytond/trytond/tests/test_resource.py | 6 +- trytond/trytond/tests/test_routes.py | 6 +- trytond/trytond/tests/test_rpc.py | 6 +- trytond/trytond/tests/test_rule.py | 6 +- trytond/trytond/tests/test_sendmail.py | 5 +- trytond/trytond/tests/test_sequence.py | 6 +- trytond/trytond/tests/test_tools.py | 19 ++--- trytond/trytond/tests/test_transaction.py | 5 +- trytond/trytond/tests/test_tree.py | 8 +-- trytond/trytond/tests/test_trigger.py | 6 +- trytond/trytond/tests/test_tryton.py | 70 ++++++++++++++++++- trytond/trytond/tests/test_union.py | 6 +- trytond/trytond/tests/test_user.py | 6 +- trytond/trytond/tests/test_wizard.py | 6 +- trytond/trytond/tests/test_workflow.py | 7 +- trytond/trytond/tests/test_wsgi.py | 5 +- 68 files changed, 298 insertions(+), 216 deletions(-) diff --git a/modules/currency/tests/test_module.py b/modules/currency/tests/test_module.py index e6efeb4419..206877b8a9 100644 --- a/modules/currency/tests/test_module.py +++ b/modules/currency/tests/test_module.py @@ -2,14 +2,14 @@ # this repository contains the full copyright notices and license terms. import datetime -import unittest from decimal import ROUND_HALF_DOWN, Decimal from trytond import backend from trytond.modules.currency.ecb import ( RatesNotAvailableError, UnsupportedCurrencyError, get_rates) from trytond.pool import Pool -from trytond.tests.test_tryton import ModuleTestCase, with_transaction +from trytond.tests.test_tryton import ( + ModuleTestCase, TestCase, with_transaction) from trytond.transaction import Transaction @@ -394,7 +394,7 @@ class CurrencyTestCase(ModuleTestCase): self.assertSetEqual(data, result) -class ECBtestCase(unittest.TestCase): +class ECBtestCase(TestCase): def test_rate_EUR_week_ago(self): "Fetch EUR rates a week ago" diff --git a/trytond-gis/trytond_gis/tests/test_fields.py b/trytond-gis/trytond_gis/tests/test_fields.py index 6d688caa7a..f17adca85c 100644 --- a/trytond-gis/trytond_gis/tests/test_fields.py +++ b/trytond-gis/trytond_gis/tests/test_fields.py @@ -1,14 +1,14 @@ # This file is part of trytond_gis. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from sql import Null from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) -class TestGeographicFields(unittest.TestCase): +class TestGeographicFields(TestCase): @classmethod def setUpClass(cls): diff --git a/trytond/doc/ref/tests.rst b/trytond/doc/ref/tests.rst index 7dd78730ec..829b183651 100644 --- a/trytond/doc/ref/tests.rst +++ b/trytond/doc/ref/tests.rst @@ -38,12 +38,22 @@ Tests dump and restore operations. The default value is the number of CPU. +TestCase +-------- + +.. class:: TestCase() + + A subclass of `unittest.TestCase`_ for testing non-module Tryton. + + It setups warning filters based on ``TEST_PYTHONWARNINGS`` environment + variable. + ModuleTestCase -------------- .. class:: ModuleTestCase() - A subclass of `unittest.TestCase`_ that tests a Tryton module. + A subclass of :class:`TestCase` that tests a Tryton module. Some tests are included to ensure that the module works properly. It creates a temporary database with the module activated in setUpClass_ and @@ -67,7 +77,7 @@ RouteTestCase .. class:: RouteTestCase() - A subclass of `unittest.TestCase`_ to test Tryton routes. + A subclass of :class:`TestCase` to test Tryton routes. It creates a temporary database with the module activated in setUpClass_ and drops it in the tearDownClass_ method. diff --git a/trytond/trytond/tests/test_access.py b/trytond/trytond/tests/test_access.py index b47edfd8b3..48995dc4e4 100644 --- a/trytond/trytond/tests/test_access.py +++ b/trytond/trytond/tests/test_access.py @@ -1,17 +1,17 @@ # -*- coding: utf-8 -*- # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from trytond.model.exceptions import AccessError from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction _context = {'_check_access': True} -class _ModelAccessTestCase(unittest.TestCase): +class _ModelAccessTestCase(TestCase): _perm = None @classmethod @@ -408,7 +408,7 @@ class ModelAccessModelTestCase(_ModelAccessTestCase): TestAccess.search([]) -class _ModelFieldAccessTestCase(unittest.TestCase): +class _ModelFieldAccessTestCase(TestCase): _perm = None @classmethod @@ -1020,7 +1020,7 @@ class ModelFieldAccessWriteTestCase(_ModelFieldAccessTestCase): TestAccess.write([record], {'field2': 'test'}) -class MenuActionAccessReadTestCase(unittest.TestCase): +class MenuActionAccessReadTestCase(TestCase): @classmethod def setUpClass(cls): diff --git a/trytond/trytond/tests/test_backend.py b/trytond/trytond/tests/test_backend.py index 0af6951d5b..35c325fe14 100644 --- a/trytond/trytond/tests/test_backend.py +++ b/trytond/trytond/tests/test_backend.py @@ -2,17 +2,17 @@ # this repository contains the full copyright notices and license terms. import datetime as dt import math -import unittest from sql import Literal, Select, functions from sql.functions import CurrentTimestamp, DateTrunc, ToChar from trytond.model import fields -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction -class BackendTestCase(unittest.TestCase): +class BackendTestCase(TestCase): "Test the backend" @classmethod diff --git a/trytond/trytond/tests/test_bus.py b/trytond/trytond/tests/test_bus.py index 0b7cbeac62..89a74f1212 100644 --- a/trytond/trytond/tests/test_bus.py +++ b/trytond/trytond/tests/test_bus.py @@ -8,11 +8,11 @@ from unittest.mock import patch from trytond import backend, bus from trytond.bus import Bus, _MessageQueue, notify from trytond.tests.test_tryton import ( - DB_NAME, activate_module, with_transaction) + DB_NAME, TestCase, activate_module, with_transaction) from trytond.transaction import Transaction -class MessageQueueTestCase(unittest.TestCase): +class MessageQueueTestCase(TestCase): def setUp(self): self._timestamp = 0 @@ -74,7 +74,7 @@ class MessageQueueTestCase(unittest.TestCase): self.assertEqual(content, {'message_id': 10}) -class BusTestCase(unittest.TestCase): +class BusTestCase(TestCase): "Test Bus" @classmethod diff --git a/trytond/trytond/tests/test_cache.py b/trytond/trytond/tests/test_cache.py index 5bca33a9df..9a9ceefb8d 100644 --- a/trytond/trytond/tests/test_cache.py +++ b/trytond/trytond/tests/test_cache.py @@ -12,7 +12,7 @@ from trytond import cache as cache_mod from trytond.cache import ( LRUDict, LRUDictTransaction, MemoryCache, freeze, unfreeze) from trytond.tests.test_tryton import ( - DB_NAME, USER, activate_module, with_transaction) + DB_NAME, USER, TestCase, activate_module, with_transaction) from trytond.transaction import Transaction cache = MemoryCache('test.cache') @@ -22,7 +22,7 @@ cache_ignored_local_context = MemoryCache( cache_ignored_global_context = MemoryCache('test.cache.ignored.global') -class CacheTestCase(unittest.TestCase): +class CacheTestCase(TestCase): "Test Cache" @classmethod @@ -96,7 +96,7 @@ class CacheTestCase(unittest.TestCase): self.assertEqual(value, 1) -class MemoryCacheTestCase(unittest.TestCase): +class MemoryCacheTestCase(TestCase): "Test Cache" @classmethod @@ -266,7 +266,7 @@ class MemoryCacheChannelTestCase(MemoryCacheTestCase): super().test_memory_cache_sync() -class LRUDictTestCase(unittest.TestCase): +class LRUDictTestCase(TestCase): "Test LRUDict" def test_setitem(self): @@ -315,7 +315,7 @@ class LRUDictTestCase(unittest.TestCase): self.assertEqual(lru_dict['foo'], 'foo') -class LRUDictTransactionTestCase(unittest.TestCase): +class LRUDictTransactionTestCase(TestCase): "Test LRUDictTransaction" @classmethod diff --git a/trytond/trytond/tests/test_copy.py b/trytond/trytond/tests/test_copy.py index 58b8b26f6c..a954646d1f 100644 --- a/trytond/trytond/tests/test_copy.py +++ b/trytond/trytond/tests/test_copy.py @@ -1,19 +1,20 @@ # -*- coding: utf-8 -*- # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest + from unittest.mock import patch from trytond.model import fields from trytond.model.exceptions import AccessError from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction from .test_modelsql import TranslationTestCase -class CopyTestCase(unittest.TestCase): +class CopyTestCase(TestCase): 'Test copy' @classmethod diff --git a/trytond/trytond/tests/test_exportdata.py b/trytond/trytond/tests/test_exportdata.py index e78c767159..419d5d8fca 100644 --- a/trytond/trytond/tests/test_exportdata.py +++ b/trytond/trytond/tests/test_exportdata.py @@ -2,15 +2,15 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. import datetime -import unittest from decimal import Decimal from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction -class ExportDataTestCase(unittest.TestCase): +class ExportDataTestCase(TestCase): 'Test export_data' @classmethod diff --git a/trytond/trytond/tests/test_field_binary.py b/trytond/trytond/tests/test_field_binary.py index 8a5c6b899b..3b6122bba1 100644 --- a/trytond/trytond/tests/test_field_binary.py +++ b/trytond/trytond/tests/test_field_binary.py @@ -2,7 +2,6 @@ # this repository contains the full copyright notices and license terms. import shutil import tempfile -import unittest from sql import Literal @@ -10,13 +9,14 @@ from trytond.config import config from trytond.model import fields from trytond.model.exceptions import RequiredValidationError from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction cast = fields.Binary.cast -class FieldBinaryTestCase(unittest.TestCase): +class FieldBinaryTestCase(TestCase): "Test Field Binary" @classmethod diff --git a/trytond/trytond/tests/test_field_boolean.py b/trytond/trytond/tests/test_field_boolean.py index db250d36ec..b6ddef2413 100644 --- a/trytond/trytond/tests/test_field_boolean.py +++ b/trytond/trytond/tests/test_field_boolean.py @@ -1,14 +1,14 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from sql import Literal from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) -class FieldBooleanTestCase(unittest.TestCase): +class FieldBooleanTestCase(TestCase): "Test Field Boolean" @classmethod diff --git a/trytond/trytond/tests/test_field_char.py b/trytond/trytond/tests/test_field_char.py index 85102740b8..63e063efd0 100644 --- a/trytond/trytond/tests/test_field_char.py +++ b/trytond/trytond/tests/test_field_char.py @@ -10,7 +10,7 @@ from trytond.model.exceptions import ( ForbiddenCharValidationError, RequiredValidationError, SizeValidationError) from trytond.pool import Pool from trytond.tests.test_tryton import ( - ExtensionTestCase, activate_module, with_transaction) + ExtensionTestCase, TestCase, activate_module, with_transaction) from trytond.transaction import Transaction @@ -382,7 +382,7 @@ class CommonTestCaseMixin: self.assertEqual(char.char_unstripped, " Foo ") -class FieldCharTestCase(unittest.TestCase, CommonTestCaseMixin): +class FieldCharTestCase(TestCase, CommonTestCaseMixin): "Test Field Char" @classmethod @@ -608,7 +608,7 @@ class FieldCharTestCase(unittest.TestCase, CommonTestCaseMixin): self.assertEqual(read_record.char_unstripped, " Bar ") -class FieldCharTranslatedTestCase(unittest.TestCase, CommonTestCaseMixin): +class FieldCharTranslatedTestCase(TestCase, CommonTestCaseMixin): "Test Field Char Translated" @classmethod diff --git a/trytond/trytond/tests/test_field_context.py b/trytond/trytond/tests/test_field_context.py index 1fbdab4316..ed95962a9d 100644 --- a/trytond/trytond/tests/test_field_context.py +++ b/trytond/trytond/tests/test_field_context.py @@ -1,13 +1,12 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest - from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) -class FieldContextTestCase(unittest.TestCase): +class FieldContextTestCase(TestCase): "Test context on field" @classmethod diff --git a/trytond/trytond/tests/test_field_date.py b/trytond/trytond/tests/test_field_date.py index 294eb50a20..f66a8ccb84 100644 --- a/trytond/trytond/tests/test_field_date.py +++ b/trytond/trytond/tests/test_field_date.py @@ -9,7 +9,8 @@ from sql.functions import CurrentDate from trytond import backend from trytond.model.exceptions import RequiredValidationError from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction today = datetime.date(2009, 1, 1) @@ -18,7 +19,7 @@ yesterday = today - datetime.timedelta(1) default_date = datetime.date(2000, 1, 1) -class FieldDateTestCase(unittest.TestCase): +class FieldDateTestCase(TestCase): "Test Field Date" @classmethod diff --git a/trytond/trytond/tests/test_field_datetime.py b/trytond/trytond/tests/test_field_datetime.py index a73589e9b5..6bb284cba1 100644 --- a/trytond/trytond/tests/test_field_datetime.py +++ b/trytond/trytond/tests/test_field_datetime.py @@ -1,14 +1,14 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. import datetime -import unittest from sql.functions import CurrentTimestamp from trytond.model.exceptions import ( RequiredValidationError, TimeFormatValidationError) from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) today = datetime.datetime(2009, 1, 1, 12, 0, 0) tomorrow = today + datetime.timedelta(1) @@ -16,7 +16,7 @@ yesterday = today - datetime.timedelta(1) default_datetime = datetime.datetime(2000, 1, 1, 12, 0, 0) -class FieldDateTimeTestCase(unittest.TestCase): +class FieldDateTimeTestCase(TestCase): "Test Field DateTime" @classmethod diff --git a/trytond/trytond/tests/test_field_depends.py b/trytond/trytond/tests/test_field_depends.py index fb4d919c6e..a76d04f8a6 100644 --- a/trytond/trytond/tests/test_field_depends.py +++ b/trytond/trytond/tests/test_field_depends.py @@ -1,13 +1,13 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of this # repository contains the full copyright notices and license terms. -import unittest from trytond.model import ModelView, fields from trytond.pyson import Eval, If -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) -class FieldDependsTestCase(unittest.TestCase): +class FieldDependsTestCase(TestCase): 'Test Field Depends' @classmethod diff --git a/trytond/trytond/tests/test_field_dict.py b/trytond/trytond/tests/test_field_dict.py index 0cac188bfb..c8430a1ee1 100644 --- a/trytond/trytond/tests/test_field_dict.py +++ b/trytond/trytond/tests/test_field_dict.py @@ -7,10 +7,10 @@ from trytond.model.dictschema import SelectionError from trytond.model.exceptions import RequiredValidationError from trytond.pool import Pool from trytond.tests.test_tryton import ( - ExtensionTestCase, activate_module, with_transaction) + ExtensionTestCase, TestCase, activate_module, with_transaction) -class FieldDictTestCase(unittest.TestCase): +class FieldDictTestCase(TestCase): "Test Field Dict" @classmethod diff --git a/trytond/trytond/tests/test_field_float.py b/trytond/trytond/tests/test_field_float.py index 9bbb01daee..7a2321c865 100644 --- a/trytond/trytond/tests/test_field_float.py +++ b/trytond/trytond/tests/test_field_float.py @@ -1,16 +1,16 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from sql import Literal from trytond.model.exceptions import ( DigitsValidationError, RequiredValidationError) from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) -class FieldFloatTestCase(unittest.TestCase): +class FieldFloatTestCase(TestCase): "Test Field Float" @classmethod diff --git a/trytond/trytond/tests/test_field_function.py b/trytond/trytond/tests/test_field_function.py index 473900f0a7..6c1db69c3e 100644 --- a/trytond/trytond/tests/test_field_function.py +++ b/trytond/trytond/tests/test_field_function.py @@ -1,14 +1,15 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest + from unittest.mock import patch from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction -class FieldFunctionTestCase(unittest.TestCase): +class FieldFunctionTestCase(TestCase): "Test Field Function" @classmethod diff --git a/trytond/trytond/tests/test_field_integer.py b/trytond/trytond/tests/test_field_integer.py index 3c9ae68faa..b1b118fdf6 100644 --- a/trytond/trytond/tests/test_field_integer.py +++ b/trytond/trytond/tests/test_field_integer.py @@ -1,16 +1,16 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from sql import Literal from trytond.model.exceptions import ( DomainValidationError, RequiredValidationError) from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) -class FieldIntegerTestCase(unittest.TestCase): +class FieldIntegerTestCase(TestCase): "Test Field Integer" @classmethod diff --git a/trytond/trytond/tests/test_field_many2many.py b/trytond/trytond/tests/test_field_many2many.py index 7fc0fa5592..5e080bb4e5 100644 --- a/trytond/trytond/tests/test_field_many2many.py +++ b/trytond/trytond/tests/test_field_many2many.py @@ -1,11 +1,11 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from trytond.model.exceptions import ( DomainValidationError, RequiredValidationError, SizeValidationError) from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) class CommonTestCaseMixin: @@ -374,7 +374,7 @@ class CommonTestCaseMixin: self.assertIsNone(relation.write_date) -class FieldMany2ManyTestCase(unittest.TestCase, CommonTestCaseMixin): +class FieldMany2ManyTestCase(TestCase, CommonTestCaseMixin): "Test Field Many2Many" @classmethod @@ -780,7 +780,7 @@ class FieldMany2ManyTestCase(unittest.TestCase, CommonTestCaseMixin): sorted([t.id for t in targets], reverse=True)) -class FieldMany2ManyReferenceTestCase(unittest.TestCase, CommonTestCaseMixin): +class FieldMany2ManyReferenceTestCase(TestCase, CommonTestCaseMixin): "Test Field Many2Many Reference" @classmethod diff --git a/trytond/trytond/tests/test_field_many2one.py b/trytond/trytond/tests/test_field_many2one.py index b2b68a5855..b96761e04f 100644 --- a/trytond/trytond/tests/test_field_many2one.py +++ b/trytond/trytond/tests/test_field_many2one.py @@ -1,15 +1,15 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from sql import Join from trytond.model.exceptions import DomainValidationError from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) -class FieldMany2OneTestCase(unittest.TestCase): +class FieldMany2OneTestCase(TestCase): "Test Field Many2One" @classmethod @@ -243,7 +243,7 @@ class FieldMany2OneTestCase(unittest.TestCase): self.assertEqual(record.target.context, 'foo') -class FieldMany2OneTreeTestCase(unittest.TestCase): +class FieldMany2OneTreeTestCase(TestCase): "Test Field Many2One Tree" model_name = 'test.many2one_tree' diff --git a/trytond/trytond/tests/test_field_multiselection.py b/trytond/trytond/tests/test_field_multiselection.py index 881d59ecda..806157f7e0 100644 --- a/trytond/trytond/tests/test_field_multiselection.py +++ b/trytond/trytond/tests/test_field_multiselection.py @@ -6,11 +6,12 @@ from trytond import backend from trytond.model.exceptions import ( RequiredValidationError, SelectionValidationError) from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction -class FieldMultiSelectionTestCase(unittest.TestCase): +class FieldMultiSelectionTestCase(TestCase): "Test Field MultiSelection" @classmethod diff --git a/trytond/trytond/tests/test_field_numeric.py b/trytond/trytond/tests/test_field_numeric.py index e4743876ad..9d246776ae 100644 --- a/trytond/trytond/tests/test_field_numeric.py +++ b/trytond/trytond/tests/test_field_numeric.py @@ -1,6 +1,6 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest + from decimal import Decimal, InvalidOperation from sql import Literal @@ -8,10 +8,11 @@ from sql import Literal from trytond.model.exceptions import ( DigitsValidationError, RequiredValidationError) from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) -class FieldNumericTestCase(unittest.TestCase): +class FieldNumericTestCase(TestCase): "Test Field Numeric" @classmethod diff --git a/trytond/trytond/tests/test_field_one2many.py b/trytond/trytond/tests/test_field_one2many.py index f96d615050..74e714ca92 100644 --- a/trytond/trytond/tests/test_field_one2many.py +++ b/trytond/trytond/tests/test_field_one2many.py @@ -1,12 +1,12 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from trytond.config import config from trytond.model.exceptions import ( DomainValidationError, RequiredValidationError, SizeValidationError) from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) class SearchTestCaseMixin: @@ -450,7 +450,7 @@ class CommonTestCaseMixin: class FieldOne2ManyTestCase( - unittest.TestCase, CommonTestCaseMixin, SearchTestCaseMixin): + TestCase, CommonTestCaseMixin, SearchTestCaseMixin): "Test Field One2Many" _strategy = 'IN' @@ -719,7 +719,7 @@ class FieldOne2ManyTestCase( class FieldOne2ManyReferenceTestCase( - unittest.TestCase, CommonTestCaseMixin, SearchTestCaseMixin): + TestCase, CommonTestCaseMixin, SearchTestCaseMixin): "Test Field One2Many Reference" _strategy = 'IN' @@ -734,7 +734,7 @@ class FieldOne2ManyReferenceTestCase( return Pool().get('test.one2many_reference.target') -class FieldOne2ManyExistsTestCase(unittest.TestCase, SearchTestCaseMixin): +class FieldOne2ManyExistsTestCase(TestCase, SearchTestCaseMixin): "Test Field One2Many when using EXISTS" _strategy = 'EXISTS' @@ -758,7 +758,7 @@ class FieldOne2ManyExistsTestCase(unittest.TestCase, SearchTestCaseMixin): class FieldOne2ManyReferenceExistsTestCase( - unittest.TestCase, SearchTestCaseMixin): + TestCase, SearchTestCaseMixin): "Test Field One2Many Reference when using EXISTS" _strategy = 'EXISTS' diff --git a/trytond/trytond/tests/test_field_one2one.py b/trytond/trytond/tests/test_field_one2one.py index a72807569c..82078c6f4e 100644 --- a/trytond/trytond/tests/test_field_one2one.py +++ b/trytond/trytond/tests/test_field_one2one.py @@ -1,14 +1,14 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from trytond.model.exceptions import ( DomainValidationError, RequiredValidationError, SQLConstraintError) from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) -class FieldOne2OneTestCase(unittest.TestCase): +class FieldOne2OneTestCase(TestCase): "Test Field One2One" @classmethod diff --git a/trytond/trytond/tests/test_field_reference.py b/trytond/trytond/tests/test_field_reference.py index 76563623e2..68acb5f8a4 100644 --- a/trytond/trytond/tests/test_field_reference.py +++ b/trytond/trytond/tests/test_field_reference.py @@ -1,14 +1,14 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from trytond.model.exceptions import ( DomainValidationError, RequiredValidationError) from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) -class FieldReferenceTestCase(unittest.TestCase): +class FieldReferenceTestCase(TestCase): "Test Field Reference" @classmethod diff --git a/trytond/trytond/tests/test_field_selection.py b/trytond/trytond/tests/test_field_selection.py index ab891cf6e0..1d29e79792 100644 --- a/trytond/trytond/tests/test_field_selection.py +++ b/trytond/trytond/tests/test_field_selection.py @@ -1,14 +1,14 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from trytond.model.exceptions import ( RequiredValidationError, SelectionValidationError) from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) -class FieldSelectionTestCase(unittest.TestCase): +class FieldSelectionTestCase(TestCase): "Test Field Selection" @classmethod diff --git a/trytond/trytond/tests/test_field_text.py b/trytond/trytond/tests/test_field_text.py index b24a5cc948..e2a283b100 100644 --- a/trytond/trytond/tests/test_field_text.py +++ b/trytond/trytond/tests/test_field_text.py @@ -7,7 +7,8 @@ from trytond import backend from trytond.model.exceptions import ( RequiredValidationError, SizeValidationError) from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction @@ -389,7 +390,7 @@ class CommonTestCaseMixin: self.assertEqual(text.text, "é") -class FieldTextTestCase(unittest.TestCase, CommonTestCaseMixin): +class FieldTextTestCase(TestCase, CommonTestCaseMixin): "Test Field Text" @classmethod @@ -510,14 +511,14 @@ class FieldTextTestCase(unittest.TestCase, CommonTestCaseMixin): }) -class FieldTextTranslatedTestCase(unittest.TestCase, CommonTestCaseMixin): +class FieldTextTranslatedTestCase(TestCase, CommonTestCaseMixin): "Test Field Text Translated" def Text(self): return Pool().get('test.text_translate') -class FieldFullTextTestCase(unittest.TestCase): +class FieldFullTextTestCase(TestCase): "Test Field FullText" @classmethod diff --git a/trytond/trytond/tests/test_field_time.py b/trytond/trytond/tests/test_field_time.py index be69e6b4da..78ef6c7ebd 100644 --- a/trytond/trytond/tests/test_field_time.py +++ b/trytond/trytond/tests/test_field_time.py @@ -1,14 +1,14 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. import datetime -import unittest from sql.functions import CurrentTimestamp from trytond.model.exceptions import ( RequiredValidationError, TimeFormatValidationError) from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) pre_evening = datetime.time(16, 30) evening = datetime.time(18, 45, 3) @@ -16,7 +16,7 @@ night = datetime.time(20, 00) default_time = datetime.time(16, 30) -class FieldTimeTestCase(unittest.TestCase): +class FieldTimeTestCase(TestCase): "Test Field Time" @classmethod diff --git a/trytond/trytond/tests/test_field_timedelta.py b/trytond/trytond/tests/test_field_timedelta.py index 765878d3bb..a34b036326 100644 --- a/trytond/trytond/tests/test_field_timedelta.py +++ b/trytond/trytond/tests/test_field_timedelta.py @@ -1,11 +1,11 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. import datetime -import unittest from trytond.model.exceptions import RequiredValidationError from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) minute = datetime.timedelta(minutes=1) hour = datetime.timedelta(hours=1) @@ -13,7 +13,7 @@ day = datetime.timedelta(days=1) default_timedelta = datetime.timedelta(seconds=3600) -class FieldTimeDeltaTestCase(unittest.TestCase): +class FieldTimeDeltaTestCase(TestCase): "Test Field TimeDelta" @classmethod diff --git a/trytond/trytond/tests/test_filestore.py b/trytond/trytond/tests/test_filestore.py index 4d551bb6de..68d96df961 100644 --- a/trytond/trytond/tests/test_filestore.py +++ b/trytond/trytond/tests/test_filestore.py @@ -3,14 +3,14 @@ import os import shutil import tempfile -import unittest from unittest.mock import patch from trytond.config import config from trytond.filestore import filestore +from trytond.tests.test_tryton import TestCase -class FileStoreTestCase(unittest.TestCase): +class FileStoreTestCase(TestCase): "Test FileStore" def setUp(self): diff --git a/trytond/trytond/tests/test_history.py b/trytond/trytond/tests/test_history.py index effebfa3ad..e646f1ecaf 100644 --- a/trytond/trytond/tests/test_history.py +++ b/trytond/trytond/tests/test_history.py @@ -7,11 +7,12 @@ from unittest.mock import patch from trytond import backend from trytond.model.exceptions import AccessError from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction -class HistoryTestCase(unittest.TestCase): +class HistoryTestCase(TestCase): 'Test History' @classmethod diff --git a/trytond/trytond/tests/test_i18n.py b/trytond/trytond/tests/test_i18n.py index 5dd41a8efe..d717aac05d 100644 --- a/trytond/trytond/tests/test_i18n.py +++ b/trytond/trytond/tests/test_i18n.py @@ -1,15 +1,16 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest + from unittest.mock import patch from trytond.i18n import gettext, lazy_gettext from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.tools.string_ import LazyString -class I18nTestCase(unittest.TestCase): +class I18nTestCase(TestCase): 'Test Model Access' @classmethod diff --git a/trytond/trytond/tests/test_importdata.py b/trytond/trytond/tests/test_importdata.py index cadd464495..dfbcefdfb7 100644 --- a/trytond/trytond/tests/test_importdata.py +++ b/trytond/trytond/tests/test_importdata.py @@ -2,16 +2,16 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. import datetime as dt -import unittest from decimal import Decimal from trytond.model.exceptions import ImportDataError from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction -class ImportDataTestCase(unittest.TestCase): +class ImportDataTestCase(TestCase): 'Test import_data' @classmethod diff --git a/trytond/trytond/tests/test_ir.py b/trytond/trytond/tests/test_ir.py index f4beb959e9..b303229ba2 100644 --- a/trytond/trytond/tests/test_ir.py +++ b/trytond/trytond/tests/test_ir.py @@ -25,7 +25,7 @@ from trytond.tools import timezone from trytond.transaction import Transaction from .test_tryton import ( - ModuleTestCase, activate_module, drop_db, with_transaction) + ModuleTestCase, TestCase, activate_module, drop_db, with_transaction) class IrTestCase(ModuleTestCase): @@ -478,7 +478,7 @@ class IrTestCase(ModuleTestCase): }) -class IrCronTestCase(unittest.TestCase): +class IrCronTestCase(TestCase): "Test ir.cron features" @classmethod diff --git a/trytond/trytond/tests/test_mixins.py b/trytond/trytond/tests/test_mixins.py index b2bbdee660..432c9608ec 100644 --- a/trytond/trytond/tests/test_mixins.py +++ b/trytond/trytond/tests/test_mixins.py @@ -2,19 +2,19 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest import urllib.parse from trytond.model import ModelView from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction from trytond.url import HOSTNAME, http_host from .mixin import NotMixin, ReportMixin, TestMixin, TestSecondMixin -class UrlTestCase(unittest.TestCase): +class UrlTestCase(TestCase): "Test URL generation" @classmethod @@ -74,7 +74,7 @@ class UrlTestCase(unittest.TestCase): http_host(), urllib.parse.quote(db_name))) -class MixinTestCase(unittest.TestCase): +class MixinTestCase(TestCase): "Test Mixin" @classmethod @@ -112,7 +112,7 @@ class MixinTestCase(unittest.TestCase): self.assertTrue(issubclass(Report, ReportMixin)) -class DeactivableMixinTestCase(unittest.TestCase): +class DeactivableMixinTestCase(TestCase): "Test DeactivableMixin" @classmethod diff --git a/trytond/trytond/tests/test_model.py b/trytond/trytond/tests/test_model.py index 1c67745464..66ca01c8d4 100644 --- a/trytond/trytond/tests/test_model.py +++ b/trytond/trytond/tests/test_model.py @@ -1,15 +1,16 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of this # repository contains the full copyright notices and license terms. -import unittest + from copy import copy from trytond.model.model import record from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction -class ModelTestCase(unittest.TestCase): +class ModelTestCase(TestCase): 'Test Model' @classmethod @@ -390,7 +391,7 @@ class ModelTestCase(unittest.TestCase): }) -class ModelTranslationTestCase(unittest.TestCase): +class ModelTranslationTestCase(TestCase): "Test Model translation" default_language = 'en' other_language = 'fr' @@ -445,7 +446,7 @@ class ModelTranslationTestCase(unittest.TestCase): self.assertEqual(other['string'], "Nom") -class RecordTestCase(unittest.TestCase): +class RecordTestCase(TestCase): "Test record" def test_creation(self): diff --git a/trytond/trytond/tests/test_model_index.py b/trytond/trytond/tests/test_model_index.py index 7c3ef89c37..e85e6ca40c 100644 --- a/trytond/trytond/tests/test_model_index.py +++ b/trytond/trytond/tests/test_model_index.py @@ -1,14 +1,13 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of this # repository contains the full copyright notices and license terms. -import unittest - from sql import Table from trytond.model import Index +from trytond.tests.test_tryton import TestCase -class ModelIndexTestCase(unittest.TestCase): +class ModelIndexTestCase(TestCase): "Test Model Index" def test_index_equality(self): diff --git a/trytond/trytond/tests/test_model_log.py b/trytond/trytond/tests/test_model_log.py index 18eb35a9b9..3a3ea6d183 100644 --- a/trytond/trytond/tests/test_model_log.py +++ b/trytond/trytond/tests/test_model_log.py @@ -1,15 +1,13 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of this # repository contains the full copyright notices and license terms. -import unittest - from trytond.pool import Pool from trytond.transaction import Transaction -from .test_tryton import activate_module, with_transaction +from .test_tryton import TestCase, activate_module, with_transaction -class ModelLogTestCase(unittest.TestCase): +class ModelLogTestCase(TestCase): "Test Model Log" @classmethod diff --git a/trytond/trytond/tests/test_model_match.py b/trytond/trytond/tests/test_model_match.py index 86791639bb..39ce043573 100644 --- a/trytond/trytond/tests/test_model_match.py +++ b/trytond/trytond/tests/test_model_match.py @@ -1,9 +1,8 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest - from trytond.model import MatchMixin, fields +from trytond.tests.test_tryton import TestCase class Model(MatchMixin): @@ -26,7 +25,7 @@ class Target(): return f"Target({self.id})" -class ModelMatchMixinTestCase(unittest.TestCase): +class ModelMatchMixinTestCase(TestCase): "Test MatchMixin" def test_match(self): diff --git a/trytond/trytond/tests/test_modelsingleton.py b/trytond/trytond/tests/test_modelsingleton.py index d7bb539a13..c7775a0f71 100644 --- a/trytond/trytond/tests/test_modelsingleton.py +++ b/trytond/trytond/tests/test_modelsingleton.py @@ -1,15 +1,16 @@ # -*- coding: utf-8 -*- # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest + from datetime import datetime from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction -class ModelSingletonTestCase(unittest.TestCase): +class ModelSingletonTestCase(TestCase): 'Test ModelSingleton' @classmethod diff --git a/trytond/trytond/tests/test_modelsql.py b/trytond/trytond/tests/test_modelsql.py index c710b36cb4..72d9f54e7d 100644 --- a/trytond/trytond/tests/test_modelsql.py +++ b/trytond/trytond/tests/test_modelsql.py @@ -14,11 +14,11 @@ from trytond.model.exceptions import ( from trytond.model.modelsql import split_subquery_domain from trytond.pool import Pool from trytond.tests.test_tryton import ( - CONTEXT, DB_NAME, USER, activate_module, with_transaction) + CONTEXT, DB_NAME, USER, TestCase, activate_module, with_transaction) from trytond.transaction import Transaction, TransactionError -class ModelSQLTestCase(unittest.TestCase): +class ModelSQLTestCase(TestCase): 'Test ModelSQL' @classmethod @@ -1335,7 +1335,7 @@ class ModelSQLTestCase(unittest.TestCase): ]) -class TranslationTestCase(unittest.TestCase): +class TranslationTestCase(TestCase): default_language = 'fr' other_language = 'en' diff --git a/trytond/trytond/tests/test_modelstorage.py b/trytond/trytond/tests/test_modelstorage.py index f23f9cee95..755cdbe9a8 100644 --- a/trytond/trytond/tests/test_modelstorage.py +++ b/trytond/trytond/tests/test_modelstorage.py @@ -1,7 +1,6 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of this # repository contains the full copyright notices and license terms. -import unittest import warnings from trytond.model import EvalEnvironment @@ -9,11 +8,12 @@ from trytond.model.exceptions import ( AccessError, DomainValidationError, RequiredValidationError) from trytond.model.modelstorage import _UnsavedRecordError from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction, check_access -class ModelStorageTestCase(unittest.TestCase): +class ModelStorageTestCase(TestCase): 'Test ModelStorage' @classmethod @@ -766,7 +766,7 @@ class ModelStorageTestCase(unittest.TestCase): Model.delete([record]) -class EvalEnvironmentTestCase(unittest.TestCase): +class EvalEnvironmentTestCase(TestCase): "Test EvalEnvironment" @classmethod diff --git a/trytond/trytond/tests/test_modelview.py b/trytond/trytond/tests/test_modelview.py index d1603bb014..2ac3459994 100644 --- a/trytond/trytond/tests/test_modelview.py +++ b/trytond/trytond/tests/test_modelview.py @@ -11,10 +11,11 @@ from trytond.model.exceptions import ( from trytond.model.modelview import set_visible from trytond.pool import Pool from trytond.pyson import Eval, PYSONDecoder, PYSONEncoder -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) -class ModelView(unittest.TestCase): +class ModelView(TestCase): "Test ModelView" @classmethod diff --git a/trytond/trytond/tests/test_mptt.py b/trytond/trytond/tests/test_mptt.py index 061f2f2020..06d346f031 100644 --- a/trytond/trytond/tests/test_mptt.py +++ b/trytond/trytond/tests/test_mptt.py @@ -2,17 +2,17 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. import sys -import unittest from unittest.mock import patch from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import inactive_records from .test_tree import TreeTestCaseMixin -class MPTTTestCase(TreeTestCaseMixin, unittest.TestCase): +class MPTTTestCase(TreeTestCaseMixin, TestCase): 'Test Modified Preorder Tree Traversal' model_name = 'test.mptt' diff --git a/trytond/trytond/tests/test_multivalue.py b/trytond/trytond/tests/test_multivalue.py index 7c9a1ce700..6d765030d1 100644 --- a/trytond/trytond/tests/test_multivalue.py +++ b/trytond/trytond/tests/test_multivalue.py @@ -1,12 +1,12 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) -class MultiValueTestCase(unittest.TestCase): +class MultiValueTestCase(TestCase): "Test MultiValue" @classmethod diff --git a/trytond/trytond/tests/test_order.py b/trytond/trytond/tests/test_order.py index b145ce6fc0..790bb981e1 100644 --- a/trytond/trytond/tests/test_order.py +++ b/trytond/trytond/tests/test_order.py @@ -1,14 +1,14 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from unittest.mock import Mock from trytond.model import sort from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) -class SequenceOrderedMixinTestCase(unittest.TestCase): +class SequenceOrderedMixinTestCase(TestCase): 'Test SequenceOrderedMixin' @classmethod diff --git a/trytond/trytond/tests/test_path.py b/trytond/trytond/tests/test_path.py index b2c6f8528c..1ff8a6989d 100644 --- a/trytond/trytond/tests/test_path.py +++ b/trytond/trytond/tests/test_path.py @@ -1,14 +1,14 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from trytond.pool import Pool +from trytond.tests.test_tryton import TestCase from trytond.transaction import inactive_records from .test_tree import TreeTestCaseMixin -class PathTestCase(TreeTestCaseMixin, unittest.TestCase): +class PathTestCase(TreeTestCaseMixin, TestCase): "Test Path" model_name = 'test.path' diff --git a/trytond/trytond/tests/test_protocols.py b/trytond/trytond/tests/test_protocols.py index f157c74020..f4b915c827 100644 --- a/trytond/trytond/tests/test_protocols.py +++ b/trytond/trytond/tests/test_protocols.py @@ -3,11 +3,11 @@ import datetime import json -import unittest from decimal import Decimal from trytond.protocols.jsonrpc import JSONDecoder, JSONEncoder, JSONRequest from trytond.protocols.xmlrpc import XMLRequest, client +from trytond.tests.test_tryton import TestCase from trytond.tools.immutabledict import ImmutableDict @@ -54,7 +54,7 @@ class DumpsLoadsMixin: self.dumps_loads(None) -class JSONTestCase(DumpsLoadsMixin, unittest.TestCase): +class JSONTestCase(DumpsLoadsMixin, TestCase): 'Test JSON' def test_json_request(self): @@ -73,7 +73,7 @@ class JSONTestCase(DumpsLoadsMixin, unittest.TestCase): object_hook=JSONDecoder()), value) -class XMLTestCase(DumpsLoadsMixin, unittest.TestCase): +class XMLTestCase(DumpsLoadsMixin, TestCase): 'Test XML' def test_xml_request(self): diff --git a/trytond/trytond/tests/test_pyson.py b/trytond/trytond/tests/test_pyson.py index 1d550b7aef..c03796e69f 100644 --- a/trytond/trytond/tests/test_pyson.py +++ b/trytond/trytond/tests/test_pyson.py @@ -8,9 +8,10 @@ import unittest from decimal import Decimal from trytond import pyson +from trytond.tests.test_tryton import TestCase -class PYSONTestCase(unittest.TestCase): +class PYSONTestCase(TestCase): 'Test PySON' def test_Decimal(self): diff --git a/trytond/trytond/tests/test_report.py b/trytond/trytond/tests/test_report.py index e866df1c2e..7f94429964 100644 --- a/trytond/trytond/tests/test_report.py +++ b/trytond/trytond/tests/test_report.py @@ -1,13 +1,13 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. import datetime -import unittest from trytond.report.report import Report -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) -class ReportTestCase(unittest.TestCase): +class ReportTestCase(TestCase): 'Test Report' @classmethod diff --git a/trytond/trytond/tests/test_resource.py b/trytond/trytond/tests/test_resource.py index cf11020ed4..d8c3ef7ba0 100644 --- a/trytond/trytond/tests/test_resource.py +++ b/trytond/trytond/tests/test_resource.py @@ -1,13 +1,13 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction -class ResourceTestCase(unittest.TestCase): +class ResourceTestCase(TestCase): "Test Resource" @classmethod diff --git a/trytond/trytond/tests/test_routes.py b/trytond/trytond/tests/test_routes.py index 58297111f4..c711083e54 100644 --- a/trytond/trytond/tests/test_routes.py +++ b/trytond/trytond/tests/test_routes.py @@ -3,16 +3,16 @@ import base64 import json -import unittest from trytond.pool import Pool from trytond.protocols.wrappers import Response -from trytond.tests.test_tryton import DB_NAME, Client, activate_module, drop_db +from trytond.tests.test_tryton import ( + DB_NAME, Client, TestCase, activate_module, drop_db) from trytond.transaction import Transaction from trytond.wsgi import app -class RoutesTestCase(unittest.TestCase): +class RoutesTestCase(TestCase): @classmethod def setUpClass(cls): diff --git a/trytond/trytond/tests/test_rpc.py b/trytond/trytond/tests/test_rpc.py index 48e6b46a8d..8a31b15053 100644 --- a/trytond/trytond/tests/test_rpc.py +++ b/trytond/trytond/tests/test_rpc.py @@ -1,14 +1,14 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from unittest.mock import DEFAULT, Mock, call from trytond.rpc import RPC -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction -class RPCTestCase(unittest.TestCase): +class RPCTestCase(TestCase): "Test RPC" @classmethod diff --git a/trytond/trytond/tests/test_rule.py b/trytond/trytond/tests/test_rule.py index 120c40c7ea..e21cdb2173 100644 --- a/trytond/trytond/tests/test_rule.py +++ b/trytond/trytond/tests/test_rule.py @@ -1,16 +1,16 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. import json -import unittest from trytond.model.exceptions import AccessError from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) _context = {'_check_access': True} -class ModelRuleTestCase(unittest.TestCase): +class ModelRuleTestCase(TestCase): "Test Model Rule" @classmethod diff --git a/trytond/trytond/tests/test_sendmail.py b/trytond/trytond/tests/test_sendmail.py index f884763823..7e4cab85eb 100644 --- a/trytond/trytond/tests/test_sendmail.py +++ b/trytond/trytond/tests/test_sendmail.py @@ -1,7 +1,6 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. import smtplib -import unittest from email.message import Message from unittest.mock import ANY, MagicMock, Mock, call, patch @@ -9,10 +8,10 @@ from trytond.sendmail import ( SMTPDataManager, get_smtp_server, sendmail, sendmail_transactional) from trytond.transaction import Transaction -from .test_tryton import activate_module, with_transaction +from .test_tryton import TestCase, activate_module, with_transaction -class SendmailTestCase(unittest.TestCase): +class SendmailTestCase(TestCase): 'Test sendmail' @classmethod diff --git a/trytond/trytond/tests/test_sequence.py b/trytond/trytond/tests/test_sequence.py index 591f11d51a..f8f47f7610 100644 --- a/trytond/trytond/tests/test_sequence.py +++ b/trytond/trytond/tests/test_sequence.py @@ -2,15 +2,15 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. import datetime -import unittest from trytond.ir.sequence import LastTimestampError from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction -class SequenceTestCase(unittest.TestCase): +class SequenceTestCase(TestCase): 'Test Sequence' @classmethod diff --git a/trytond/trytond/tests/test_tools.py b/trytond/trytond/tests/test_tools.py index cbdca204b5..f3499dcfa5 100644 --- a/trytond/trytond/tests/test_tools.py +++ b/trytond/trytond/tests/test_tools.py @@ -19,6 +19,7 @@ except ImportError: email_validator = None from trytond.pool import Pool +from trytond.tests.test_tryton import TestCase from trytond.tools import ( cached_property, decimal_, email_, escape_wildcard, file_open, firstline, grouped_slice, is_full_text, is_instance_method, likify, lstrip_wildcard, @@ -43,7 +44,7 @@ except ImportError: qrcode = None -class ToolsTestCase(unittest.TestCase): +class ToolsTestCase(TestCase): 'Test tools' table = sql.Table('test') @@ -433,7 +434,7 @@ class ToolsTestCase(unittest.TestCase): long_form) -class StringPartitionedTestCase(unittest.TestCase): +class StringPartitionedTestCase(TestCase): "Test StringPartitioned" def test_init(self): @@ -485,7 +486,7 @@ class StringPartitionedTestCase(unittest.TestCase): self.assertEqual(list(s), ['bar', 'foo']) -class LazyStringTestCase(unittest.TestCase): +class LazyStringTestCase(TestCase): "Test LazyString" def test_init(self): @@ -515,7 +516,7 @@ class LazyStringTestCase(unittest.TestCase): self.assertEqual(s, 'barfoo') -class ImmutableDictTestCase(unittest.TestCase): +class ImmutableDictTestCase(TestCase): "Test ImmutableDict" def test_setitem(self): @@ -575,7 +576,7 @@ class ImmutableDictTestCase(unittest.TestCase): d.update({'foo': 'bar'}) -class DomainInversionTestCase(unittest.TestCase): +class DomainInversionTestCase(TestCase): "Test domain_inversion" def test_simple_inversion(self): @@ -1212,7 +1213,7 @@ class DomainInversionTestCase(unittest.TestCase): @unittest.skipUnless(barcode, "required barcode") -class BarcodeTestCase(unittest.TestCase): +class BarcodeTestCase(TestCase): "Test barcode module" def test_generate_svg(self): @@ -1229,7 +1230,7 @@ class BarcodeTestCase(unittest.TestCase): @unittest.skipUnless(qrcode, "required qrcode") -class QRCodeTestCase(unittest.TestCase): +class QRCodeTestCase(TestCase): "Test qrcode module" def test_generate_svg(self): @@ -1268,7 +1269,7 @@ class CachedPropertySlots: cached_count = cached_property(get_count) -class CachedPropertyTestCase(unittest.TestCase): +class CachedPropertyTestCase(TestCase): "Test cached_property" def test_cached_property_clear(self): @@ -1297,7 +1298,7 @@ class CachedPropertyTestCase(unittest.TestCase): self.assertEqual(item.cached_count, 2) -class EmailTestCase(unittest.TestCase): +class EmailTestCase(TestCase): "Test email" def test_set_from_header_same(self): diff --git a/trytond/trytond/tests/test_transaction.py b/trytond/trytond/tests/test_transaction.py index 7b63464b44..a401e182a1 100644 --- a/trytond/trytond/tests/test_transaction.py +++ b/trytond/trytond/tests/test_transaction.py @@ -4,7 +4,8 @@ import unittest from unittest.mock import Mock from trytond import backend -from trytond.tests.test_tryton import CONTEXT, DB_NAME, USER, activate_module +from trytond.tests.test_tryton import ( + CONTEXT, DB_NAME, USER, TestCase, activate_module) from trytond.transaction import Transaction @@ -19,7 +20,7 @@ def empty_transaction(*args, **kwargs): return True -class TransactionTestCase(unittest.TestCase): +class TransactionTestCase(TestCase): 'Test the Transaction Context manager' @classmethod diff --git a/trytond/trytond/tests/test_tree.py b/trytond/trytond/tests/test_tree.py index 64aa64e423..35e9be2c7b 100644 --- a/trytond/trytond/tests/test_tree.py +++ b/trytond/trytond/tests/test_tree.py @@ -1,13 +1,13 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from collections import defaultdict from trytond.model import sum_tree from trytond.model.exceptions import DomainValidationError, RecursionError from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) class TreeTestCaseMixin: @@ -172,7 +172,7 @@ class TreeTestCaseMixin: self.check_tree() -class TreeMixinTestCase(unittest.TestCase): +class TreeMixinTestCase(TestCase): "Test TreeMixin" @classmethod @@ -433,7 +433,7 @@ class TreeMixinTestCase(unittest.TestCase): parent1.save() -class TreeTestCase(unittest.TestCase): +class TreeTestCase(TestCase): "Test Tree" @with_transaction() diff --git a/trytond/trytond/tests/test_trigger.py b/trytond/trytond/tests/test_trigger.py index 04b555b1e4..06929177f1 100644 --- a/trytond/trytond/tests/test_trigger.py +++ b/trytond/trytond/tests/test_trigger.py @@ -2,19 +2,19 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. import datetime -import unittest from itertools import combinations from trytond.ir.exceptions import TriggerConditionError from trytond.model.exceptions import SQLConstraintError from trytond.pool import Pool from trytond.pyson import Eval, PYSONEncoder -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.tests.trigger import TRIGGER_LOGS from trytond.transaction import Transaction -class TriggerTestCase(unittest.TestCase): +class TriggerTestCase(TestCase): 'Test Trigger' @classmethod diff --git a/trytond/trytond/tests/test_tryton.py b/trytond/trytond/tests/test_tryton.py index 9773395286..7b45d99c64 100644 --- a/trytond/trytond/tests/test_tryton.py +++ b/trytond/trytond/tests/test_tryton.py @@ -16,6 +16,7 @@ import sys import time import unittest import unittest.mock +import warnings from configparser import ConfigParser from fnmatch import fnmatchcase from functools import reduce, wraps @@ -43,8 +44,10 @@ __all__ = [ 'CONTEXT', 'Client', 'DB_NAME', + 'TestCase', 'ModuleTestCase', 'RouteTestCase', + 'ExtensionTestCase', 'USER', 'activate_module', 'doctest_checker', @@ -282,7 +285,70 @@ def with_transaction(user=1, context=None): return decorator -class _DBTestCase(unittest.TestCase): +class TestCase(unittest.TestCase): + + @classmethod + def setUpClass(cls): + super().setUpClass() + if pythonwarnings := os.getenv('TEST_PYTHONWARNINGS'): + cm = warnings.catch_warnings() + cm.__enter__() + cls.addClassCleanup(cm.__exit__, cm, None, None, None) + cls.setUpClassWarning(pythonwarnings.split(',')) + + @classmethod + def setUpClassWarning(cls, options): + + def _getcategory(category): + if not category: + return Warning + if '.' not in category: + import builtins as m + klass = category + else: + module, _, klass = category.rpartition('.') + try: + m = __import__(module, None, None, [klass]) + except ImportError: + raise ValueError( + "invalid module name: %r" % module) from None + try: + cat = getattr(m, klass) + except AttributeError: + raise ValueError( + "unknown warning category: %r" % category) from None + if not issubclass(cat, Warning): + raise ValueError("invalid warning category: %r" % category) + return cat + + for option in options: + parts = option.split(':') + if len(parts) > 5: + raise ValueError("too many fields (max 5): %r" % option) + while len(parts) < 5: + parts.append('') + action, message, category, module, lineno = [ + s.strip() for s in parts] + if not action: + action = 'default' + category = _getcategory(category) + if message: + message = re.escape(message) + if module: + module = re.escape(module) + r'\Z' + if lineno: + try: + lineno = int(lineno) + if lineno < 0: + raise ValueError + except (ValueError, OverflowError): + raise ValueError("invalid lineno %r" % lineno) from None + else: + lineno = 0 + warnings.filterwarnings(action, message, category, module, lineno) + + +class _DBTestCase(TestCase): module = None extras = None language = 'en' @@ -1036,7 +1102,7 @@ def create_db(name=DB_NAME, lang='en'): pool.init() -class ExtensionTestCase(unittest.TestCase): +class ExtensionTestCase(TestCase): extension = None @classmethod diff --git a/trytond/trytond/tests/test_union.py b/trytond/trytond/tests/test_union.py index 76eb965387..2d6867bb4a 100644 --- a/trytond/trytond/tests/test_union.py +++ b/trytond/trytond/tests/test_union.py @@ -1,12 +1,12 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) -class UnionMixinTestCase(unittest.TestCase): +class UnionMixinTestCase(TestCase): 'Test UnionMixin' @classmethod diff --git a/trytond/trytond/tests/test_user.py b/trytond/trytond/tests/test_user.py index 480ae9ae80..5c89d193e7 100644 --- a/trytond/trytond/tests/test_user.py +++ b/trytond/trytond/tests/test_user.py @@ -2,7 +2,6 @@ # repository contains the full copyright notices and license terms. import datetime import os -import unittest from contextlib import contextmanager from unittest.mock import Mock, patch @@ -10,7 +9,8 @@ from trytond.config import config from trytond.pool import Pool from trytond.res import user as user_module from trytond.res.user import PasswordError -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction FROM = 'tryton@example.com' @@ -26,7 +26,7 @@ def set_authentications(methods): config.set('session', 'authentications', saved_methods) -class UserTestCase(unittest.TestCase): +class UserTestCase(TestCase): 'Test User' @classmethod diff --git a/trytond/trytond/tests/test_wizard.py b/trytond/trytond/tests/test_wizard.py index a2c7ffd473..9a9796a9c2 100644 --- a/trytond/trytond/tests/test_wizard.py +++ b/trytond/trytond/tests/test_wizard.py @@ -1,14 +1,14 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of this # repository contains the full copyright notices and license terms. -import unittest from trytond.model.exceptions import AccessError from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) from trytond.transaction import Transaction -class WizardTestCase(unittest.TestCase): +class WizardTestCase(TestCase): @classmethod def setUpClass(cls): diff --git a/trytond/trytond/tests/test_workflow.py b/trytond/trytond/tests/test_workflow.py index 1254a5e9a7..bca473128f 100644 --- a/trytond/trytond/tests/test_workflow.py +++ b/trytond/trytond/tests/test_workflow.py @@ -1,13 +1,12 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of this # repository contains the full copyright notices and license terms. -import unittest - from trytond.pool import Pool -from trytond.tests.test_tryton import activate_module, with_transaction +from trytond.tests.test_tryton import ( + TestCase, activate_module, with_transaction) -class WorkflowTestCase(unittest.TestCase): +class WorkflowTestCase(TestCase): @classmethod def setUpClass(cls): diff --git a/trytond/trytond/tests/test_wsgi.py b/trytond/trytond/tests/test_wsgi.py index 47780d1859..254f526664 100644 --- a/trytond/trytond/tests/test_wsgi.py +++ b/trytond/trytond/tests/test_wsgi.py @@ -1,16 +1,15 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import unittest from unittest.mock import Mock, sentinel from trytond.exceptions import TrytonException from trytond.protocols.wrappers import Response -from trytond.tests.test_tryton import Client +from trytond.tests.test_tryton import Client, TestCase from trytond.wsgi import TrytondWSGI -class WSGIAppTestCase(unittest.TestCase): +class WSGIAppTestCase(TestCase): 'Test WSGI Application' class TestException(TrytonException):