changeset 5e57540745bc in modules/account_product:default
details: 
https://hg.tryton.org/modules/account_product?cmd=changeset&node=5e57540745bc
description:
        Replace test setuptools command by unittest discover

        issue9215
        review389851002
diffstat:

 setup.py                      |    6 +-
 tests/__init__.py             |    8 --
 tests/test_account_product.py |  123 ------------------------------------------
 tests/test_module.py          |  118 ++++++++++++++++++++++++++++++++++++++++
 tox.ini                       |    3 +-
 5 files changed, 123 insertions(+), 135 deletions(-)

diffs (297 lines):

diff -r 097db734956e -r 5e57540745bc setup.py
--- a/setup.py  Sun Apr 10 19:11:37 2022 +0200
+++ b/setup.py  Sat Apr 16 18:30:16 2022 +0200
@@ -141,13 +141,13 @@
     license='GPL-3',
     python_requires='>=3.7',
     install_requires=requires,
+    extras_require={
+        'test': tests_require,
+        },
     dependency_links=dependency_links,
     zip_safe=False,
     entry_points="""
     [trytond.modules]
     account_product = trytond.modules.account_product
     """,
-    test_suite='tests',
-    test_loader='trytond.test_loader:Loader',
-    tests_require=tests_require,
     )
diff -r 097db734956e -r 5e57540745bc tests/__init__.py
--- a/tests/__init__.py Sun Apr 10 19:11:37 2022 +0200
+++ b/tests/__init__.py Sat Apr 16 18:30:16 2022 +0200
@@ -1,10 +1,2 @@
 # This file is part of Tryton.  The COPYRIGHT file at the top level of
 # this repository contains the full copyright notices and license terms.
-
-try:
-    from trytond.modules.account_product.tests.test_account_product import \
-        suite  # noqa: E501
-except ImportError:
-    from .test_account_product import suite
-
-__all__ = ['suite']
diff -r 097db734956e -r 5e57540745bc tests/test_account_product.py
--- a/tests/test_account_product.py     Sun Apr 10 19:11:37 2022 +0200
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,123 +0,0 @@
-# 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
-
-import trytond.tests.test_tryton
-from trytond.exceptions import UserError
-from trytond.modules.account.tests import create_chart
-from trytond.modules.company.tests import (
-    CompanyTestMixin, create_company, set_company)
-from trytond.pool import Pool
-from trytond.tests.test_tryton import ModuleTestCase, with_transaction
-
-
-class AccountProductTestCase(CompanyTestMixin, ModuleTestCase):
-    'Test AccountProduct module'
-    module = 'account_product'
-    extras = ['analytic_account']
-
-    @with_transaction()
-    def test_account_chart(self):
-        "Test creation of chart of accounts"
-        company = create_company()
-        with set_company(company):
-            create_chart(company, tax=True)
-
-    @with_transaction()
-    def test_account_chart_many_companies(self):
-        "Test creation of chart of accounts for many companies"
-        company1 = create_company()
-        with set_company(company1):
-            create_chart(company1, tax=True)
-
-        company2 = create_company()
-        with set_company(company2):
-            create_chart(company2, tax=True)
-
-    @with_transaction()
-    def test_account_used(self):
-        'Test account used'
-        pool = Pool()
-        ProductTemplate = pool.get('product.template')
-        ProductCategory = pool.get('product.category')
-        Uom = pool.get('product.uom')
-        Account = pool.get('account.account')
-
-        company = create_company()
-        with set_company(company):
-            create_chart(company)
-
-            unit, = Uom.search([
-                    ('name', '=', 'Unit'),
-                    ])
-            account_expense, = Account.search([
-                    ('type.expense', '=', True),
-                    ])
-
-            # raise when empty
-            template = ProductTemplate(
-                name='Product',
-                list_price=Decimal(10),
-                default_uom=unit.id,
-                products=[],
-                )
-            template.save()
-
-            with self.assertRaisesRegex(
-                    UserError, 'Account Category.*Product'):
-                template.account_expense_used
-
-            # with account on category
-            category = ProductCategory(
-                name='Category', accounting=True,
-                account_expense=None)
-            category.save()
-            template.account_category = category
-            template.save()
-
-            with self.assertRaisesRegex(
-                    UserError, 'Account Expense.*Product'):
-                template.account_expense_used
-
-            category.account_expense = account_expense
-            category.save()
-
-            self.assertEqual(template.account_expense_used, account_expense)
-
-            # with account on grant category
-            parent_category = ProductCategory(name='Parent Category',
-                account_expense=account_expense, accounting=True)
-            parent_category.save()
-            category.account_expense = None
-            category.account_parent = True
-            category.parent = parent_category
-            category.save()
-
-            self.assertEqual(template.account_expense_used, account_expense)
-            self.assertEqual(category.account_expense_used, account_expense)
-
-            # raise only at direct usage
-            categories = ProductCategory.create([{
-                        'name': 'Category 1',
-                        'accounting': True,
-                        'account_expense': account_expense.id,
-                        }, {
-                        'name': 'Category 2',
-                        'accounting': True,
-                        'account_expense': None,
-                        }])
-
-            self.assertEqual(categories[0].account_expense_used.id,
-                account_expense.id)
-
-            with self.assertRaisesRegex(
-                    UserError, 'Account Expense.*Category 2'):
-                categories[1].account_expense_used
-
-
-def suite():
-    suite = trytond.tests.test_tryton.suite()
-    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
-        AccountProductTestCase))
-    return suite
diff -r 097db734956e -r 5e57540745bc tests/test_module.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_module.py      Sat Apr 16 18:30:16 2022 +0200
@@ -0,0 +1,118 @@
+# This file is part of Tryton.  The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+
+from decimal import Decimal
+
+from trytond.exceptions import UserError
+from trytond.modules.account.tests import create_chart
+from trytond.modules.company.tests import (
+    CompanyTestMixin, create_company, set_company)
+from trytond.pool import Pool
+from trytond.tests.test_tryton import ModuleTestCase, with_transaction
+
+
+class AccountProductTestCase(CompanyTestMixin, ModuleTestCase):
+    'Test AccountProduct module'
+    module = 'account_product'
+    extras = ['analytic_account']
+
+    @with_transaction()
+    def test_account_chart(self):
+        "Test creation of chart of accounts"
+        company = create_company()
+        with set_company(company):
+            create_chart(company, tax=True)
+
+    @with_transaction()
+    def test_account_chart_many_companies(self):
+        "Test creation of chart of accounts for many companies"
+        company1 = create_company()
+        with set_company(company1):
+            create_chart(company1, tax=True)
+
+        company2 = create_company()
+        with set_company(company2):
+            create_chart(company2, tax=True)
+
+    @with_transaction()
+    def test_account_used(self):
+        'Test account used'
+        pool = Pool()
+        ProductTemplate = pool.get('product.template')
+        ProductCategory = pool.get('product.category')
+        Uom = pool.get('product.uom')
+        Account = pool.get('account.account')
+
+        company = create_company()
+        with set_company(company):
+            create_chart(company)
+
+            unit, = Uom.search([
+                    ('name', '=', 'Unit'),
+                    ])
+            account_expense, = Account.search([
+                    ('type.expense', '=', True),
+                    ])
+
+            # raise when empty
+            template = ProductTemplate(
+                name='Product',
+                list_price=Decimal(10),
+                default_uom=unit.id,
+                products=[],
+                )
+            template.save()
+
+            with self.assertRaisesRegex(
+                    UserError, 'Account Category.*Product'):
+                template.account_expense_used
+
+            # with account on category
+            category = ProductCategory(
+                name='Category', accounting=True,
+                account_expense=None)
+            category.save()
+            template.account_category = category
+            template.save()
+
+            with self.assertRaisesRegex(
+                    UserError, 'Account Expense.*Product'):
+                template.account_expense_used
+
+            category.account_expense = account_expense
+            category.save()
+
+            self.assertEqual(template.account_expense_used, account_expense)
+
+            # with account on grant category
+            parent_category = ProductCategory(name='Parent Category',
+                account_expense=account_expense, accounting=True)
+            parent_category.save()
+            category.account_expense = None
+            category.account_parent = True
+            category.parent = parent_category
+            category.save()
+
+            self.assertEqual(template.account_expense_used, account_expense)
+            self.assertEqual(category.account_expense_used, account_expense)
+
+            # raise only at direct usage
+            categories = ProductCategory.create([{
+                        'name': 'Category 1',
+                        'accounting': True,
+                        'account_expense': account_expense.id,
+                        }, {
+                        'name': 'Category 2',
+                        'accounting': True,
+                        'account_expense': None,
+                        }])
+
+            self.assertEqual(categories[0].account_expense_used.id,
+                account_expense.id)
+
+            with self.assertRaisesRegex(
+                    UserError, 'Account Expense.*Category 2'):
+                categories[1].account_expense_used
+
+
+del ModuleTestCase
diff -r 097db734956e -r 5e57540745bc tox.ini
--- a/tox.ini   Sun Apr 10 19:11:37 2022 +0200
+++ b/tox.ini   Sat Apr 16 18:30:16 2022 +0200
@@ -2,8 +2,9 @@
 envlist = {py37,py38,py39,py310}-{sqlite,postgresql}
 
 [testenv]
+extras = test
 commands =
-    coverage run --include=.*/account_product/* setup.py test
+    coverage run --include=.*/account_product/* -m unittest discover -s tests
     coverage report --include=.*/account_product/* --omit=*/tests/*
 deps =
     coverage

Reply via email to