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

        issue9215
        review389851002
diffstat:

 setup.py               |   4 +-
 tests/__init__.py      |   7 ---
 tests/test_module.py   |  65 ++++++++++++++++++++++++++++++++++
 tests/test_sale.py     |  95 --------------------------------------------------
 tests/test_scenario.py |  22 +++++++++++
 tox.ini                |   3 +-
 6 files changed, 90 insertions(+), 106 deletions(-)

diffs (240 lines):

diff -r dcb88659d5a4 -r 2d1adfba4226 setup.py
--- a/setup.py  Mon Apr 11 23:24:21 2022 +0200
+++ b/setup.py  Sat Apr 16 18:30:18 2022 +0200
@@ -143,6 +143,7 @@
     install_requires=requires,
     extras_require={
         'sparklines': ['pygal'],
+        'test': tests_require,
         },
     dependency_links=dependency_links,
     zip_safe=False,
@@ -150,7 +151,4 @@
     [trytond.modules]
     sale = trytond.modules.sale
     """,
-    test_suite='tests',
-    test_loader='trytond.test_loader:Loader',
-    tests_require=tests_require,
     )
diff -r dcb88659d5a4 -r 2d1adfba4226 tests/__init__.py
--- a/tests/__init__.py Mon Apr 11 23:24:21 2022 +0200
+++ b/tests/__init__.py Sat Apr 16 18:30:18 2022 +0200
@@ -1,9 +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.sale.tests.test_sale import suite
-except ImportError:
-    from .test_sale import suite
-
-__all__ = ['suite']
diff -r dcb88659d5a4 -r 2d1adfba4226 tests/test_module.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_module.py      Sat Apr 16 18:30:18 2022 +0200
@@ -0,0 +1,65 @@
+# 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.modules.account.tests import create_chart
+from trytond.modules.company.tests import (
+    CompanyTestMixin, PartyCompanyCheckEraseMixin, create_company, set_company)
+from trytond.pool import Pool
+from trytond.tests.test_tryton import ModuleTestCase, with_transaction
+from trytond.transaction import Transaction
+
+
+class SaleTestCase(
+        PartyCompanyCheckEraseMixin, CompanyTestMixin, ModuleTestCase):
+    'Test Sale module'
+    module = 'sale'
+
+    @with_transaction()
+    def test_sale_price(self):
+        "Test sale price"
+        pool = Pool()
+        Account = pool.get('account.account')
+        Template = pool.get('product.template')
+        Product = pool.get('product.product')
+        Uom = pool.get('product.uom')
+
+        company = create_company()
+        with set_company(company):
+            create_chart(company)
+
+            receivable, = Account.search([
+                    ('type.receivable', '=', True),
+                    ('company', '=', company.id),
+                    ])
+            payable, = Account.search([
+                    ('type.payable', '=', True),
+                    ('company', '=', company.id),
+                    ])
+
+            kg, = Uom.search([('name', '=', 'Kilogram')])
+            g, = Uom.search([('name', '=', 'Gram')])
+            pound, = Uom.search([('name', '=', 'Pound')])
+
+            template, = Template.create([{
+                        'name': 'Product',
+                        'default_uom': g.id,
+                        'sale_uom': kg.id,
+                        'list_price': Decimal(5),
+                        'products': [('create', [{}])],
+                        }])
+            product, = template.products
+
+            prices = Product.get_sale_price([product], quantity=100)
+            self.assertEqual(prices, {product.id: Decimal(5000)})
+            prices = Product.get_sale_price([product], quantity=1500)
+            self.assertEqual(prices, {product.id: Decimal(5000)})
+
+            with Transaction().set_context(uom=pound.id):
+                prices = Product.get_sale_price([product], quantity=0.5)
+                self.assertEqual(prices, {product.id: Decimal('2267.96185')})
+                prices = Product.get_sale_price([product], quantity=1.5)
+                self.assertEqual(prices, {product.id: Decimal('2267.96185')})
+
+
+del ModuleTestCase
diff -r dcb88659d5a4 -r 2d1adfba4226 tests/test_sale.py
--- a/tests/test_sale.py        Mon Apr 11 23:24:21 2022 +0200
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,95 +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 doctest
-import unittest
-from decimal import Decimal
-
-import trytond.tests.test_tryton
-from trytond.modules.account.tests import create_chart
-from trytond.modules.company.tests import (
-    CompanyTestMixin, PartyCompanyCheckEraseMixin, create_company, set_company)
-from trytond.pool import Pool
-from trytond.tests.test_tryton import (
-    ModuleTestCase, doctest_checker, doctest_teardown, with_transaction)
-from trytond.transaction import Transaction
-
-
-class SaleTestCase(
-        PartyCompanyCheckEraseMixin, CompanyTestMixin, ModuleTestCase):
-    'Test Sale module'
-    module = 'sale'
-
-    @with_transaction()
-    def test_sale_price(self):
-        "Test sale price"
-        pool = Pool()
-        Account = pool.get('account.account')
-        Template = pool.get('product.template')
-        Product = pool.get('product.product')
-        Uom = pool.get('product.uom')
-
-        company = create_company()
-        with set_company(company):
-            create_chart(company)
-
-            receivable, = Account.search([
-                    ('type.receivable', '=', True),
-                    ('company', '=', company.id),
-                    ])
-            payable, = Account.search([
-                    ('type.payable', '=', True),
-                    ('company', '=', company.id),
-                    ])
-
-            kg, = Uom.search([('name', '=', 'Kilogram')])
-            g, = Uom.search([('name', '=', 'Gram')])
-            pound, = Uom.search([('name', '=', 'Pound')])
-
-            template, = Template.create([{
-                        'name': 'Product',
-                        'default_uom': g.id,
-                        'sale_uom': kg.id,
-                        'list_price': Decimal(5),
-                        'products': [('create', [{}])],
-                        }])
-            product, = template.products
-
-            prices = Product.get_sale_price([product], quantity=100)
-            self.assertEqual(prices, {product.id: Decimal(5000)})
-            prices = Product.get_sale_price([product], quantity=1500)
-            self.assertEqual(prices, {product.id: Decimal(5000)})
-
-            with Transaction().set_context(uom=pound.id):
-                prices = Product.get_sale_price([product], quantity=0.5)
-                self.assertEqual(prices, {product.id: Decimal('2267.96185')})
-                prices = Product.get_sale_price([product], quantity=1.5)
-                self.assertEqual(prices, {product.id: Decimal('2267.96185')})
-
-
-def suite():
-    suite = trytond.tests.test_tryton.suite()
-    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(SaleTestCase))
-    suite.addTests(doctest.DocFileSuite('scenario_sale.rst',
-            tearDown=doctest_teardown, encoding='utf-8',
-            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE,
-            checker=doctest_checker))
-    suite.addTests(doctest.DocFileSuite('scenario_sale_empty.rst',
-            tearDown=doctest_teardown, encoding='utf-8',
-            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE,
-            checker=doctest_checker))
-    suite.addTests(doctest.DocFileSuite(
-            'scenario_sale_modify_header.rst',
-            tearDown=doctest_teardown, encoding='utf-8',
-            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE,
-            checker=doctest_checker))
-    suite.addTests(doctest.DocFileSuite(
-            'scenario_sale_reporting.rst',
-            tearDown=doctest_teardown, encoding='utf-8',
-            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE,
-            checker=doctest_checker))
-    suite.addTests(doctest.DocFileSuite(
-            'scenario_sale_default_methods.rst',
-            tearDown=doctest_teardown, encoding='utf-8',
-            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE,
-            checker=doctest_checker))
-    return suite
diff -r dcb88659d5a4 -r 2d1adfba4226 tests/test_scenario.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_scenario.py    Sat Apr 16 18:30:18 2022 +0200
@@ -0,0 +1,22 @@
+# 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 doctest
+import glob
+import os
+
+from trytond.tests.test_tryton import doctest_checker, doctest_teardown
+
+
+def load_tests(loader, tests, pattern):
+    cwd = os.getcwd()
+    try:
+        os.chdir(os.path.dirname(__file__))
+        for scenario in glob.glob('*.rst'):
+            tests.addTests(doctest.DocFileSuite(
+                    scenario, tearDown=doctest_teardown, encoding='utf-8',
+                    checker=doctest_checker,
+                    optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
+    finally:
+        os.chdir(cwd)
+    return tests
diff -r dcb88659d5a4 -r 2d1adfba4226 tox.ini
--- a/tox.ini   Mon Apr 11 23:24:21 2022 +0200
+++ b/tox.ini   Sat Apr 16 18:30:18 2022 +0200
@@ -2,8 +2,9 @@
 envlist = {py37,py38,py39,py310}-{sqlite,postgresql}
 
 [testenv]
+extras = test
 commands =
-    coverage run --include=.*/sale/* setup.py test
+    coverage run --include=.*/sale/* -m unittest discover -s tests
     coverage report --include=.*/sale/* --omit=*/tests/*
 deps =
     coverage

Reply via email to