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

        issue9215
        review389851002
diffstat:

 setup.py               |    6 +-
 tests/__init__.py      |    7 --
 tests/test_module.py   |  106 ++++++++++++++++++++++++++++++++++++++
 tests/test_purchase.py |  136 -------------------------------------------------
 tests/test_scenario.py |   22 +++++++
 tox.ini                |    3 +-
 6 files changed, 133 insertions(+), 147 deletions(-)

diffs (323 lines):

diff -r e5199cde6738 -r 774247542058 setup.py
--- a/setup.py  Tue Apr 12 20:28:14 2022 +0200
+++ b/setup.py  Sat Apr 16 18:30:18 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]
     purchase = trytond.modules.purchase
     """,
-    test_suite='tests',
-    test_loader='trytond.test_loader:Loader',
-    tests_require=tests_require,
     )
diff -r e5199cde6738 -r 774247542058 tests/__init__.py
--- a/tests/__init__.py Tue Apr 12 20:28:14 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.purchase.tests.test_purchase import suite
-except ImportError:
-    from .test_purchase import suite
-
-__all__ = ['suite']
diff -r e5199cde6738 -r 774247542058 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,106 @@
+# 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 PurchaseTestCase(
+        PartyCompanyCheckEraseMixin, CompanyTestMixin, ModuleTestCase):
+    'Test Purchase module'
+    module = 'purchase'
+
+    @with_transaction()
+    def test_purchase_price(self):
+        'Test purchase price'
+        pool = Pool()
+        Account = pool.get('account.account')
+        Template = pool.get('product.template')
+        Product = pool.get('product.product')
+        Uom = pool.get('product.uom')
+        ProductSupplier = pool.get('purchase.product_supplier')
+        Party = pool.get('party.party')
+
+        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')])
+
+            template, = Template.create([{
+                        'name': 'Product',
+                        'default_uom': g.id,
+                        'purchase_uom': kg.id,
+                        'list_price': Decimal(5),
+                        'products': [('create', [{
+                                        'cost_price': Decimal(2),
+                                        }])],
+                        }])
+            product, = template.products
+
+            supplier, = Party.create([{
+                        'name': 'Supplier',
+                        'account_receivable': receivable.id,
+                        'account_payable': payable.id,
+                        }])
+            product_supplier, = ProductSupplier.create([{
+                        'template': template.id,
+                        'party': supplier.id,
+                        'prices': [('create', [{
+                                        'sequence': 1,
+                                        'quantity': 1,
+                                        'unit_price': Decimal(3000),
+                                        }, {
+                                        'sequence': 2,
+                                        'quantity': 2,
+                                        'unit_price': Decimal(2500),
+                                        }])],
+                        }])
+
+            prices = Product.get_purchase_price([product], quantity=100)
+            self.assertEqual(prices, {product.id: Decimal(2)})
+            prices = Product.get_purchase_price([product], quantity=1500)
+            self.assertEqual(prices, {product.id: Decimal(2)})
+
+            with Transaction().set_context(uom=kg.id):
+                prices = Product.get_purchase_price([product], quantity=0.5)
+                self.assertEqual(prices, {product.id: Decimal(2000)})
+                prices = Product.get_purchase_price([product], quantity=1.5)
+                self.assertEqual(prices, {product.id: Decimal(2000)})
+
+            with Transaction().set_context(supplier=supplier.id):
+                prices = Product.get_purchase_price([product], quantity=100)
+                self.assertEqual(prices, {product.id: Decimal(2)})
+                prices = Product.get_purchase_price([product], quantity=1500)
+                self.assertEqual(prices, {product.id: Decimal(3)})
+                prices = Product.get_purchase_price([product], quantity=3000)
+                self.assertEqual(prices, {product.id: Decimal('2.5')})
+
+            with Transaction().set_context(uom=kg.id, supplier=supplier.id):
+                prices = Product.get_purchase_price([product], quantity=0.5)
+                self.assertEqual(prices, {product.id: Decimal(2000)})
+                prices = Product.get_purchase_price([product], quantity=1.5)
+                self.assertEqual(prices, {product.id: Decimal(3000)})
+                prices = Product.get_purchase_price([product], quantity=3)
+                self.assertEqual(prices, {product.id: Decimal(2500)})
+                prices = Product.get_purchase_price([product], quantity=-4)
+                self.assertEqual(prices, {product.id: Decimal(2500)})
+
+
+del ModuleTestCase
diff -r e5199cde6738 -r 774247542058 tests/test_purchase.py
--- a/tests/test_purchase.py    Tue Apr 12 20:28:14 2022 +0200
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,136 +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 PurchaseTestCase(
-        PartyCompanyCheckEraseMixin, CompanyTestMixin, ModuleTestCase):
-    'Test Purchase module'
-    module = 'purchase'
-
-    @with_transaction()
-    def test_purchase_price(self):
-        'Test purchase price'
-        pool = Pool()
-        Account = pool.get('account.account')
-        Template = pool.get('product.template')
-        Product = pool.get('product.product')
-        Uom = pool.get('product.uom')
-        ProductSupplier = pool.get('purchase.product_supplier')
-        Party = pool.get('party.party')
-
-        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')])
-
-            template, = Template.create([{
-                        'name': 'Product',
-                        'default_uom': g.id,
-                        'purchase_uom': kg.id,
-                        'list_price': Decimal(5),
-                        'products': [('create', [{
-                                        'cost_price': Decimal(2),
-                                        }])],
-                        }])
-            product, = template.products
-
-            supplier, = Party.create([{
-                        'name': 'Supplier',
-                        'account_receivable': receivable.id,
-                        'account_payable': payable.id,
-                        }])
-            product_supplier, = ProductSupplier.create([{
-                        'template': template.id,
-                        'party': supplier.id,
-                        'prices': [('create', [{
-                                        'sequence': 1,
-                                        'quantity': 1,
-                                        'unit_price': Decimal(3000),
-                                        }, {
-                                        'sequence': 2,
-                                        'quantity': 2,
-                                        'unit_price': Decimal(2500),
-                                        }])],
-                        }])
-
-            prices = Product.get_purchase_price([product], quantity=100)
-            self.assertEqual(prices, {product.id: Decimal(2)})
-            prices = Product.get_purchase_price([product], quantity=1500)
-            self.assertEqual(prices, {product.id: Decimal(2)})
-
-            with Transaction().set_context(uom=kg.id):
-                prices = Product.get_purchase_price([product], quantity=0.5)
-                self.assertEqual(prices, {product.id: Decimal(2000)})
-                prices = Product.get_purchase_price([product], quantity=1.5)
-                self.assertEqual(prices, {product.id: Decimal(2000)})
-
-            with Transaction().set_context(supplier=supplier.id):
-                prices = Product.get_purchase_price([product], quantity=100)
-                self.assertEqual(prices, {product.id: Decimal(2)})
-                prices = Product.get_purchase_price([product], quantity=1500)
-                self.assertEqual(prices, {product.id: Decimal(3)})
-                prices = Product.get_purchase_price([product], quantity=3000)
-                self.assertEqual(prices, {product.id: Decimal('2.5')})
-
-            with Transaction().set_context(uom=kg.id, supplier=supplier.id):
-                prices = Product.get_purchase_price([product], quantity=0.5)
-                self.assertEqual(prices, {product.id: Decimal(2000)})
-                prices = Product.get_purchase_price([product], quantity=1.5)
-                self.assertEqual(prices, {product.id: Decimal(3000)})
-                prices = Product.get_purchase_price([product], quantity=3)
-                self.assertEqual(prices, {product.id: Decimal(2500)})
-                prices = Product.get_purchase_price([product], quantity=-4)
-                self.assertEqual(prices, {product.id: Decimal(2500)})
-
-
-def suite():
-    suite = trytond.tests.test_tryton.suite()
-    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
-        PurchaseTestCase))
-    suite.addTests(doctest.DocFileSuite('scenario_purchase.rst',
-            tearDown=doctest_teardown, encoding='UTF-8',
-            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE,
-            checker=doctest_checker))
-    suite.addTests(doctest.DocFileSuite('scenario_purchase_empty.rst',
-            tearDown=doctest_teardown, encoding='UTF-8',
-            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE,
-            checker=doctest_checker))
-    suite.addTests(doctest.DocFileSuite(
-            'scenario_purchase_modify_header.rst',
-            tearDown=doctest_teardown, encoding='utf-8',
-            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE,
-            checker=doctest_checker))
-    suite.addTests(doctest.DocFileSuite(
-            'scenario_purchase_return_wizard.rst',
-            tearDown=doctest_teardown, encoding='utf-8',
-            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE,
-            checker=doctest_checker))
-    suite.addTests(doctest.DocFileSuite(
-            'scenario_purchase_copy_product_suppliers.rst',
-            tearDown=doctest_teardown, encoding='utf-8',
-            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE,
-            checker=doctest_checker))
-    return suite
diff -r e5199cde6738 -r 774247542058 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 e5199cde6738 -r 774247542058 tox.ini
--- a/tox.ini   Tue Apr 12 20:28:14 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=.*/purchase/* setup.py test
+    coverage run --include=.*/purchase/* -m unittest discover -s tests
     coverage report --include=.*/purchase/* --omit=*/tests/*
 deps =
     coverage

Reply via email to