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

        issue9215
        review389851002
diffstat:

 setup.py                                  |    6 +-
 tests/__init__.py                         |    8 -
 tests/test_module.py                      |  223 +++++++++++++++++++++++++++++
 tests/test_stock_shipment_measurements.py |  229 ------------------------------
 tox.ini                                   |    3 +-
 5 files changed, 228 insertions(+), 241 deletions(-)

diffs (508 lines):

diff -r f6de0c35fd7f -r 3d5b9feaa29f setup.py
--- a/setup.py  Sun Apr 10 19:11:40 2022 +0200
+++ b/setup.py  Sat Apr 16 18:30:20 2022 +0200
@@ -137,13 +137,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]
     stock_shipment_measurements = trytond.modules.stock_shipment_measurements
     """,
-    test_suite='tests',
-    test_loader='trytond.test_loader:Loader',
-    tests_require=tests_require,
     )
diff -r f6de0c35fd7f -r 3d5b9feaa29f tests/__init__.py
--- a/tests/__init__.py Sun Apr 10 19:11:40 2022 +0200
+++ b/tests/__init__.py Sat Apr 16 18:30:20 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.stock_shipment_measurements.tests.test_stock_shipment_measurements
 import \
-        suite  # noqa: E501
-except ImportError:
-    from .test_stock_shipment_measurements import suite
-
-__all__ = ['suite']
diff -r f6de0c35fd7f -r 3d5b9feaa29f tests/test_module.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_module.py      Sat Apr 16 18:30:20 2022 +0200
@@ -0,0 +1,223 @@
+# 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.company.tests import (
+    CompanyTestMixin, create_company, set_company)
+from trytond.pool import Pool
+from trytond.tests.test_tryton import (
+    ModuleTestCase, activate_module, with_transaction)
+
+
+class StockShipmentMeasurementsTestCase(CompanyTestMixin, ModuleTestCase):
+    'Test Stock Shipment Measurements module'
+    module = 'stock_shipment_measurements'
+    extras = ['stock_package']
+    longMessage = True
+
+    @classmethod
+    def setUpClass(cls):
+        super(StockShipmentMeasurementsTestCase, cls).setUpClass()
+        activate_module('stock_package')
+
+    @with_transaction()
+    def test_move_internal_measurements(self):
+        "Test move internal measurements"
+        pool = Pool()
+        Uom = pool.get('product.uom')
+        Template = pool.get('product.template')
+        Product = pool.get('product.product')
+        Location = pool.get('stock.location')
+        Move = pool.get('stock.move')
+
+        kg, = Uom.search([('name', '=', 'Kilogram')])
+        g, = Uom.search([('name', '=', 'Gram')])
+        liter, = Uom.search([('name', '=', 'Liter')])
+        supplier, = Location.search([('code', '=', 'SUP')])
+        storage, = Location.search([('code', '=', 'STO')])
+        company = create_company()
+        currency = company.currency
+
+        template, = Template.create([{
+                    'name': "Test internal measurements",
+                    'type': 'goods',
+                    'default_uom': kg,
+                    }])
+        product, = Product.create([{
+                    'template': template.id,
+                    }])
+
+        # without any measurements
+        with set_company(company):
+            move, = Move.create([{
+                        'product': product,
+                        'uom': g,
+                        'quantity': 200,
+                        'from_location': supplier,
+                        'to_location': storage,
+                        'company': company,
+                        'unit_price': Decimal(1),
+                        'currency': currency,
+                        }])
+            self.assertEqual(move.internal_weight, 0.2)
+            self.assertEqual(move.internal_volume, None)
+
+            Move.write([move], {'quantity': 100})
+            self.assertEqual(move.internal_weight, 0.1)
+            self.assertEqual(move.internal_volume, None)
+
+        template.weight = 1.1
+        template.weight_uom = kg
+        template.save()
+
+        # with weight measurements
+        with set_company(company):
+            move, = Move.create([{
+                        'product': product,
+                        'uom': g,
+                        'quantity': 300,
+                        'from_location': supplier,
+                        'to_location': storage,
+                        'company': company,
+                        'unit_price': Decimal(1),
+                        'currency': currency,
+                        }])
+            self.assertEqual(move.internal_weight, 0.33)
+            self.assertEqual(move.internal_volume, None)
+
+            Move.write([move], {'quantity': 500})
+            self.assertEqual(move.internal_weight, 0.55)
+            self.assertEqual(move.internal_volume, None)
+
+        template.volume = 2
+        template.volume_uom = liter
+        template.save()
+
+        # with weight and volume measurements
+        with set_company(company):
+            move, = Move.create([{
+                        'product': product,
+                        'uom': g,
+                        'quantity': 500,
+                        'from_location': supplier,
+                        'to_location': storage,
+                        'company': company,
+                        'unit_price': Decimal(1),
+                        'currency': currency,
+                        }])
+            self.assertEqual(move.internal_weight, 0.55)
+            self.assertEqual(move.internal_volume, 1)
+
+            Move.write([move], {'quantity': 600})
+            self.assertEqual(move.internal_weight, 0.66)
+            self.assertEqual(move.internal_volume, 1.2)
+
+    @with_transaction()
+    def test_shipment_out_measurements(self):
+        "Test shipment out measurements"
+        pool = Pool()
+        Uom = pool.get('product.uom')
+        Template = pool.get('product.template')
+        Product = pool.get('product.product')
+        Location = pool.get('stock.location')
+        Move = pool.get('stock.move')
+        Shipment = pool.get('stock.shipment.out')
+        Package = pool.get('stock.package')
+        PackageType = pool.get('stock.package.type')
+        Party = pool.get('party.party')
+
+        kg, = Uom.search([('name', '=', 'Kilogram')])
+        liter, = Uom.search([('name', '=', 'Liter')])
+        customer, = Location.search([('code', '=', 'CUS')])
+        storage, = Location.search([('code', '=', 'STO')])
+        party = Party(name='Customer')
+        party.addresses = [{}]
+        party.save()
+        company = create_company()
+        currency = company.currency
+        package_type = PackageType(name="Type")
+        package_type.save()
+
+        template, = Template.create([{
+                    'name': "Test measurements",
+                    'type': 'goods',
+                    'default_uom': kg,
+                    'volume': 0.2,
+                    'volume_uom': liter,
+                    }])
+        product, = Product.create([{
+                    'template': template.id,
+                    }])
+
+        with set_company(company):
+            shipment = Shipment()
+            shipment.customer = party
+            shipment.delivery_address, = party.addresses
+            shipment.save()
+
+            # without moves
+            self.assertEqual(shipment.weight, None)
+            self.assertEqual(shipment.volume, None)
+
+            shipment.moves = [Move(
+                    product=product,
+                    uom=kg,
+                    quantity=10,
+                    from_location=storage,
+                    to_location=customer,
+                    company=company,
+                    unit_price=Decimal(1),
+                    currency=currency,
+                    )]
+            shipment.save()
+
+            # without inventory moves
+            self.assertEqual(shipment.weight, 10)
+            self.assertEqual(shipment.volume, 2)
+
+            Shipment.wait([shipment])
+
+            # with inventory moves
+            self.assertEqual(shipment.weight, 10)
+            self.assertEqual(shipment.volume, 2)
+
+            for clause, result in [
+                    ([('weight', '=', 10)], [shipment]),
+                    ([('weight', '=', 5)], []),
+                    ([('volume', '=', 2)], [shipment]),
+                    ([('volume', '=', 3)], []),
+                    ]:
+                msg = 'clause: %s' % clause
+                self.assertEqual(Shipment.search(clause), result, msg=msg)
+
+            # Add packages
+            package_root = Package()
+            package_root.type = package_type
+            package_root.shipment = shipment
+            package_root.additional_weight = 1
+            package_root.packaging_volume = 3
+            package_root.packaging_volume_uom = liter
+            package_root.save()
+
+            package = Package()
+            package.type = package_type
+            package.shipment = shipment
+            package.moves = shipment.moves
+            package.parent = package_root
+            package.save()
+
+            self.assertEqual(package_root.weight, None)
+            self.assertEqual(package_root.volume, None)
+
+            self.assertEqual(package.weight, 10)
+            self.assertEqual(package.volume, 2)
+
+            self.assertEqual(package_root.total_weight, 11)
+            self.assertEqual(package_root.total_volume, 3)
+
+            self.assertEqual(package.total_weight, 10)
+            self.assertEqual(package.total_volume, 2)
+
+
+del ModuleTestCase
diff -r f6de0c35fd7f -r 3d5b9feaa29f tests/test_stock_shipment_measurements.py
--- a/tests/test_stock_shipment_measurements.py Sun Apr 10 19:11:40 2022 +0200
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,229 +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
-
-from trytond.modules.company.tests import (
-    CompanyTestMixin, create_company, set_company)
-from trytond.pool import Pool
-from trytond.tests.test_tryton import ModuleTestCase, activate_module
-from trytond.tests.test_tryton import suite as test_suite
-from trytond.tests.test_tryton import with_transaction
-
-
-class StockShipmentMeasurementsTestCase(CompanyTestMixin, ModuleTestCase):
-    'Test Stock Shipment Measurements module'
-    module = 'stock_shipment_measurements'
-    extras = ['stock_package']
-    longMessage = True
-
-    @classmethod
-    def setUpClass(cls):
-        super(StockShipmentMeasurementsTestCase, cls).setUpClass()
-        activate_module('stock_package')
-
-    @with_transaction()
-    def test_move_internal_measurements(self):
-        "Test move internal measurements"
-        pool = Pool()
-        Uom = pool.get('product.uom')
-        Template = pool.get('product.template')
-        Product = pool.get('product.product')
-        Location = pool.get('stock.location')
-        Move = pool.get('stock.move')
-
-        kg, = Uom.search([('name', '=', 'Kilogram')])
-        g, = Uom.search([('name', '=', 'Gram')])
-        liter, = Uom.search([('name', '=', 'Liter')])
-        supplier, = Location.search([('code', '=', 'SUP')])
-        storage, = Location.search([('code', '=', 'STO')])
-        company = create_company()
-        currency = company.currency
-
-        template, = Template.create([{
-                    'name': "Test internal measurements",
-                    'type': 'goods',
-                    'default_uom': kg,
-                    }])
-        product, = Product.create([{
-                    'template': template.id,
-                    }])
-
-        # without any measurements
-        with set_company(company):
-            move, = Move.create([{
-                        'product': product,
-                        'uom': g,
-                        'quantity': 200,
-                        'from_location': supplier,
-                        'to_location': storage,
-                        'company': company,
-                        'unit_price': Decimal(1),
-                        'currency': currency,
-                        }])
-            self.assertEqual(move.internal_weight, 0.2)
-            self.assertEqual(move.internal_volume, None)
-
-            Move.write([move], {'quantity': 100})
-            self.assertEqual(move.internal_weight, 0.1)
-            self.assertEqual(move.internal_volume, None)
-
-        template.weight = 1.1
-        template.weight_uom = kg
-        template.save()
-
-        # with weight measurements
-        with set_company(company):
-            move, = Move.create([{
-                        'product': product,
-                        'uom': g,
-                        'quantity': 300,
-                        'from_location': supplier,
-                        'to_location': storage,
-                        'company': company,
-                        'unit_price': Decimal(1),
-                        'currency': currency,
-                        }])
-            self.assertEqual(move.internal_weight, 0.33)
-            self.assertEqual(move.internal_volume, None)
-
-            Move.write([move], {'quantity': 500})
-            self.assertEqual(move.internal_weight, 0.55)
-            self.assertEqual(move.internal_volume, None)
-
-        template.volume = 2
-        template.volume_uom = liter
-        template.save()
-
-        # with weight and volume measurements
-        with set_company(company):
-            move, = Move.create([{
-                        'product': product,
-                        'uom': g,
-                        'quantity': 500,
-                        'from_location': supplier,
-                        'to_location': storage,
-                        'company': company,
-                        'unit_price': Decimal(1),
-                        'currency': currency,
-                        }])
-            self.assertEqual(move.internal_weight, 0.55)
-            self.assertEqual(move.internal_volume, 1)
-
-            Move.write([move], {'quantity': 600})
-            self.assertEqual(move.internal_weight, 0.66)
-            self.assertEqual(move.internal_volume, 1.2)
-
-    @with_transaction()
-    def test_shipment_out_measurements(self):
-        "Test shipment out measurements"
-        pool = Pool()
-        Uom = pool.get('product.uom')
-        Template = pool.get('product.template')
-        Product = pool.get('product.product')
-        Location = pool.get('stock.location')
-        Move = pool.get('stock.move')
-        Shipment = pool.get('stock.shipment.out')
-        Package = pool.get('stock.package')
-        PackageType = pool.get('stock.package.type')
-        Party = pool.get('party.party')
-
-        kg, = Uom.search([('name', '=', 'Kilogram')])
-        liter, = Uom.search([('name', '=', 'Liter')])
-        customer, = Location.search([('code', '=', 'CUS')])
-        storage, = Location.search([('code', '=', 'STO')])
-        party = Party(name='Customer')
-        party.addresses = [{}]
-        party.save()
-        company = create_company()
-        currency = company.currency
-        package_type = PackageType(name="Type")
-        package_type.save()
-
-        template, = Template.create([{
-                    'name': "Test measurements",
-                    'type': 'goods',
-                    'default_uom': kg,
-                    'volume': 0.2,
-                    'volume_uom': liter,
-                    }])
-        product, = Product.create([{
-                    'template': template.id,
-                    }])
-
-        with set_company(company):
-            shipment = Shipment()
-            shipment.customer = party
-            shipment.delivery_address, = party.addresses
-            shipment.save()
-
-            # without moves
-            self.assertEqual(shipment.weight, None)
-            self.assertEqual(shipment.volume, None)
-
-            shipment.moves = [Move(
-                    product=product,
-                    uom=kg,
-                    quantity=10,
-                    from_location=storage,
-                    to_location=customer,
-                    company=company,
-                    unit_price=Decimal(1),
-                    currency=currency,
-                    )]
-            shipment.save()
-
-            # without inventory moves
-            self.assertEqual(shipment.weight, 10)
-            self.assertEqual(shipment.volume, 2)
-
-            Shipment.wait([shipment])
-
-            # with inventory moves
-            self.assertEqual(shipment.weight, 10)
-            self.assertEqual(shipment.volume, 2)
-
-            for clause, result in [
-                    ([('weight', '=', 10)], [shipment]),
-                    ([('weight', '=', 5)], []),
-                    ([('volume', '=', 2)], [shipment]),
-                    ([('volume', '=', 3)], []),
-                    ]:
-                msg = 'clause: %s' % clause
-                self.assertEqual(Shipment.search(clause), result, msg=msg)
-
-            # Add packages
-            package_root = Package()
-            package_root.type = package_type
-            package_root.shipment = shipment
-            package_root.additional_weight = 1
-            package_root.packaging_volume = 3
-            package_root.packaging_volume_uom = liter
-            package_root.save()
-
-            package = Package()
-            package.type = package_type
-            package.shipment = shipment
-            package.moves = shipment.moves
-            package.parent = package_root
-            package.save()
-
-            self.assertEqual(package_root.weight, None)
-            self.assertEqual(package_root.volume, None)
-
-            self.assertEqual(package.weight, 10)
-            self.assertEqual(package.volume, 2)
-
-            self.assertEqual(package_root.total_weight, 11)
-            self.assertEqual(package_root.total_volume, 3)
-
-            self.assertEqual(package.total_weight, 10)
-            self.assertEqual(package.total_volume, 2)
-
-
-def suite():
-    suite = test_suite()
-    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
-            StockShipmentMeasurementsTestCase))
-    return suite
diff -r f6de0c35fd7f -r 3d5b9feaa29f tox.ini
--- a/tox.ini   Sun Apr 10 19:11:40 2022 +0200
+++ b/tox.ini   Sat Apr 16 18:30:20 2022 +0200
@@ -2,8 +2,9 @@
 envlist = {py37,py38,py39,py310}-{sqlite,postgresql}
 
 [testenv]
+extras = test
 commands =
-    coverage run --include=.*/stock_shipment_measurements/* setup.py test
+    coverage run --include=.*/stock_shipment_measurements/* -m unittest 
discover -s tests
     coverage report --include=.*/stock_shipment_measurements/* --omit=*/tests/*
 deps =
     coverage

Reply via email to