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

        issue9215
        review389851002
diffstat:

 setup.py              |    2 -
 tests/__init__.py     |    6 -
 tests/test_customs.py |  216 --------------------------------------------------
 tests/test_module.py  |  208 ++++++++++++++++++++++++++++++++++++++++++++++++
 tox.ini               |    2 +-
 5 files changed, 209 insertions(+), 225 deletions(-)

diffs (466 lines):

diff -r 836737c062d6 -r c2bf0afa2ef9 setup.py
--- a/setup.py  Sun Apr 10 19:11:38 2022 +0200
+++ b/setup.py  Sat Apr 16 18:30:17 2022 +0200
@@ -142,6 +142,4 @@
     [trytond.modules]
     customs = trytond.modules.customs
     """,
-    test_suite='tests',
-    test_loader='trytond.test_loader:Loader',
     )
diff -r 836737c062d6 -r c2bf0afa2ef9 tests/__init__.py
--- a/tests/__init__.py Sun Apr 10 19:11:38 2022 +0200
+++ b/tests/__init__.py Sat Apr 16 18:30:17 2022 +0200
@@ -1,8 +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.customs.tests.test_customs import suite
-except ImportError:
-    from .test_customs import suite
-
-__all__ = ['suite']
diff -r 836737c062d6 -r c2bf0afa2ef9 tests/test_customs.py
--- a/tests/test_customs.py     Sun Apr 10 19:11:38 2022 +0200
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,216 +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 datetime import date
-from decimal import Decimal
-
-from trytond.pool import Pool
-from trytond.tests.test_tryton import ModuleTestCase
-from trytond.tests.test_tryton import suite as test_suite
-from trytond.tests.test_tryton import with_transaction
-
-
-class CustomsTestCase(ModuleTestCase):
-    'Test Customs module'
-    module = 'customs'
-
-    @with_transaction()
-    def test_tariff_code_match(self):
-        'Test tariff code match'
-        pool = Pool()
-        Tariff = pool.get('customs.tariff.code')
-        Template = pool.get('product.template')
-        Product_TariffCode = pool.get(
-            'product-customs.tariff.code')
-
-        # Test start <= end
-        tariff1 = Tariff(code='170390')
-        tariff2 = Tariff(code='17039099',
-                start_month='06', start_day=20,
-                end_month='08', end_day=20)
-        Tariff.save([tariff1, tariff2])
-        template = Template(tariff_codes=[
-                Product_TariffCode(tariff_code=tariff2),
-                Product_TariffCode(tariff_code=tariff1),
-                ], tariff_codes_category=False)
-
-        for pattern, result in [
-                ({'date': date(2015, 1, 1)}, tariff1),
-                ({'date': date(2015, 7, 1)}, tariff2),
-                ({'date': date(2016, 9, 1)}, tariff1),
-                ]:
-            self.assertEqual(template.get_tariff_code(pattern), result)
-
-        # Test start > end
-        tariff2.start_month = '08'
-        tariff2.end_month = '06'
-        tariff2.save()
-
-        for pattern, result in [
-                ({'date': date(2015, 1, 1)}, tariff2),
-                ({'date': date(2015, 7, 1)}, tariff1),
-                ({'date': date(2016, 9, 1)}, tariff2),
-                ]:
-            self.assertEqual(template.get_tariff_code(pattern), result)
-
-    @with_transaction()
-    def test_get_tariff_code(self):
-        'Test get_tariff_code'
-        pool = Pool()
-        Tariff = pool.get('customs.tariff.code')
-        Template = pool.get('product.template')
-        Category = pool.get('product.category')
-        Product_TariffCode = pool.get(
-            'product-customs.tariff.code')
-
-        tariff1, tariff2, tariff3 = Tariff.create([
-                {'code': '170390'},
-                {'code': '17039099'},
-                {'code': '1703909999'},
-                ])
-
-        category1 = Category(tariff_codes=[
-                Product_TariffCode(tariff_code=tariff1),
-                ], tariff_codes_parent=False, customs=True)
-        category2 = Category(tariff_codes=[
-                Product_TariffCode(tariff_code=tariff2),
-                ], parent=category1, tariff_codes_parent=False, customs=True)
-        template = Template(tariff_codes=[
-                Product_TariffCode(tariff_code=tariff3),
-                ], customs_category=category2, tariff_codes_category=False)
-
-        self.assertEqual(template.get_tariff_code({}), tariff3)
-
-        template.tariff_codes_category = True
-        self.assertEqual(template.get_tariff_code({}), tariff2)
-
-        category2.tariff_codes_parent = True
-        self.assertEqual(template.get_tariff_code({}), tariff1)
-
-    @with_transaction()
-    def test_duty_rate_match(self):
-        'Test duty rate match'
-        pool = Pool()
-        Tariff = pool.get('customs.tariff.code')
-        Rate = pool.get('customs.duty.rate')
-        Currency = pool.get('currency.currency')
-        CurrencyRate = pool.get('currency.currency.rate')
-
-        currency = Currency(name='cur', symbol='cur', code='XXX',
-            rates=[CurrencyRate(rate=Decimal(1))])
-        currency.save()
-
-        tariff = Tariff(code='170390')
-        tariff.save()
-
-        rate1 = Rate(tariff_code=tariff,
-            computation_type='amount',
-            end_date=date(2015, 6, 30),
-            amount=Decimal(10), currency=currency)
-        rate2 = Rate(tariff_code=tariff,
-            start_date=date(2015, 7, 1),
-            end_date=date(2015, 12, 31),
-            computation_type='amount',
-            amount=Decimal(10), currency=currency)
-        rate3 = Rate(tariff_code=tariff,
-            start_date=date(2015, 12, 31),
-            computation_type='amount',
-            amount=Decimal(10), currency=currency)
-        Rate.save([rate1, rate2, rate3])
-
-        for pattern, result in [
-                ({'date': date(2015, 1, 1)}, rate1),
-                ({'date': date(2015, 8, 1)}, rate2),
-                ({'date': date(2016, 9, 1)}, rate3),
-                ]:
-            self.assertEqual(tariff.get_duty_rate(pattern), result)
-
-    @with_transaction()
-    def test_duty_rate_compute(self):
-        'Test duty rate compute'
-        pool = Pool()
-        Rate = pool.get('customs.duty.rate')
-        Currency = pool.get('currency.currency')
-        CurrencyRate = pool.get('currency.currency.rate')
-        Uom = pool.get('product.uom')
-
-        kg, g = Uom.search([('name', 'in', ['Kilogram', 'Gram'])],
-            order=[('name', 'DESC')])
-        currency1 = Currency(name='cur1', symbol='cur1', code='XX1',
-            rates=[CurrencyRate(rate=Decimal(1))])
-        currency2 = Currency(name='cur2', symbol='cur1', code='XX2',
-            rates=[CurrencyRate(rate=Decimal('.5'))])
-        Currency.save([currency1, currency2])
-
-        rate = Rate(computation_type='amount',
-            amount=Decimal(10), currency=currency1)
-        self.assertEqual(rate.compute(currency2, 1, kg), Decimal(5))
-
-        rate = Rate(computation_type='quantity',
-            amount=Decimal(10), currency=currency1, uom=kg)
-        self.assertEqual(rate.compute(currency2, 100, g), Decimal('0.5'))
-
-    @with_transaction()
-    def test_delete_category(self):
-        'Test delete category'
-        pool = Pool()
-        Tariff = pool.get('customs.tariff.code')
-        Category = pool.get('product.category')
-        Product_TariffCode = pool.get(
-            'product-customs.tariff.code')
-
-        tariff = Tariff(code='170390')
-        tariff.save()
-
-        category = Category(name='Test', customs=True,
-            tariff_codes=[
-                Product_TariffCode(tariff_code=tariff),
-                ])
-        category.save()
-        product_tariff_code, = category.tariff_codes
-
-        Category.delete([category])
-
-        self.assertEqual(
-            Product_TariffCode.search([
-                    ('id', '=', product_tariff_code.id),
-                    ]), [])
-
-    @with_transaction()
-    def test_delete_template(self):
-        'Test delete template'
-        pool = Pool()
-        Tariff = pool.get('customs.tariff.code')
-        Template = pool.get('product.template')
-        Uom = pool.get('product.uom')
-        Product_TariffCode = pool.get(
-            'product-customs.tariff.code')
-
-        unit, = Uom.search([('name', '=', 'Unit')])
-
-        tariff = Tariff(code='170390')
-        tariff.save()
-
-        template = Template(name='Test',
-            default_uom=unit,
-            tariff_codes=[
-                Product_TariffCode(tariff_code=tariff),
-                ])
-        template.save()
-        product_tariff_code, = template.tariff_codes
-
-        Template.delete([template])
-
-        self.assertEqual(
-            Product_TariffCode.search([
-                    ('id', '=', product_tariff_code.id),
-                    ]), [])
-
-
-def suite():
-    suite = test_suite()
-    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
-            CustomsTestCase))
-    return suite
diff -r 836737c062d6 -r c2bf0afa2ef9 tests/test_module.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_module.py      Sat Apr 16 18:30:17 2022 +0200
@@ -0,0 +1,208 @@
+# 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 datetime import date
+from decimal import Decimal
+
+from trytond.pool import Pool
+from trytond.tests.test_tryton import ModuleTestCase, with_transaction
+
+
+class CustomsTestCase(ModuleTestCase):
+    'Test Customs module'
+    module = 'customs'
+
+    @with_transaction()
+    def test_tariff_code_match(self):
+        'Test tariff code match'
+        pool = Pool()
+        Tariff = pool.get('customs.tariff.code')
+        Template = pool.get('product.template')
+        Product_TariffCode = pool.get(
+            'product-customs.tariff.code')
+
+        # Test start <= end
+        tariff1 = Tariff(code='170390')
+        tariff2 = Tariff(code='17039099',
+                start_month='06', start_day=20,
+                end_month='08', end_day=20)
+        Tariff.save([tariff1, tariff2])
+        template = Template(tariff_codes=[
+                Product_TariffCode(tariff_code=tariff2),
+                Product_TariffCode(tariff_code=tariff1),
+                ], tariff_codes_category=False)
+
+        for pattern, result in [
+                ({'date': date(2015, 1, 1)}, tariff1),
+                ({'date': date(2015, 7, 1)}, tariff2),
+                ({'date': date(2016, 9, 1)}, tariff1),
+                ]:
+            self.assertEqual(template.get_tariff_code(pattern), result)
+
+        # Test start > end
+        tariff2.start_month = '08'
+        tariff2.end_month = '06'
+        tariff2.save()
+
+        for pattern, result in [
+                ({'date': date(2015, 1, 1)}, tariff2),
+                ({'date': date(2015, 7, 1)}, tariff1),
+                ({'date': date(2016, 9, 1)}, tariff2),
+                ]:
+            self.assertEqual(template.get_tariff_code(pattern), result)
+
+    @with_transaction()
+    def test_get_tariff_code(self):
+        'Test get_tariff_code'
+        pool = Pool()
+        Tariff = pool.get('customs.tariff.code')
+        Template = pool.get('product.template')
+        Category = pool.get('product.category')
+        Product_TariffCode = pool.get(
+            'product-customs.tariff.code')
+
+        tariff1, tariff2, tariff3 = Tariff.create([
+                {'code': '170390'},
+                {'code': '17039099'},
+                {'code': '1703909999'},
+                ])
+
+        category1 = Category(tariff_codes=[
+                Product_TariffCode(tariff_code=tariff1),
+                ], tariff_codes_parent=False, customs=True)
+        category2 = Category(tariff_codes=[
+                Product_TariffCode(tariff_code=tariff2),
+                ], parent=category1, tariff_codes_parent=False, customs=True)
+        template = Template(tariff_codes=[
+                Product_TariffCode(tariff_code=tariff3),
+                ], customs_category=category2, tariff_codes_category=False)
+
+        self.assertEqual(template.get_tariff_code({}), tariff3)
+
+        template.tariff_codes_category = True
+        self.assertEqual(template.get_tariff_code({}), tariff2)
+
+        category2.tariff_codes_parent = True
+        self.assertEqual(template.get_tariff_code({}), tariff1)
+
+    @with_transaction()
+    def test_duty_rate_match(self):
+        'Test duty rate match'
+        pool = Pool()
+        Tariff = pool.get('customs.tariff.code')
+        Rate = pool.get('customs.duty.rate')
+        Currency = pool.get('currency.currency')
+        CurrencyRate = pool.get('currency.currency.rate')
+
+        currency = Currency(name='cur', symbol='cur', code='XXX',
+            rates=[CurrencyRate(rate=Decimal(1))])
+        currency.save()
+
+        tariff = Tariff(code='170390')
+        tariff.save()
+
+        rate1 = Rate(tariff_code=tariff,
+            computation_type='amount',
+            end_date=date(2015, 6, 30),
+            amount=Decimal(10), currency=currency)
+        rate2 = Rate(tariff_code=tariff,
+            start_date=date(2015, 7, 1),
+            end_date=date(2015, 12, 31),
+            computation_type='amount',
+            amount=Decimal(10), currency=currency)
+        rate3 = Rate(tariff_code=tariff,
+            start_date=date(2015, 12, 31),
+            computation_type='amount',
+            amount=Decimal(10), currency=currency)
+        Rate.save([rate1, rate2, rate3])
+
+        for pattern, result in [
+                ({'date': date(2015, 1, 1)}, rate1),
+                ({'date': date(2015, 8, 1)}, rate2),
+                ({'date': date(2016, 9, 1)}, rate3),
+                ]:
+            self.assertEqual(tariff.get_duty_rate(pattern), result)
+
+    @with_transaction()
+    def test_duty_rate_compute(self):
+        'Test duty rate compute'
+        pool = Pool()
+        Rate = pool.get('customs.duty.rate')
+        Currency = pool.get('currency.currency')
+        CurrencyRate = pool.get('currency.currency.rate')
+        Uom = pool.get('product.uom')
+
+        kg, g = Uom.search([('name', 'in', ['Kilogram', 'Gram'])],
+            order=[('name', 'DESC')])
+        currency1 = Currency(name='cur1', symbol='cur1', code='XX1',
+            rates=[CurrencyRate(rate=Decimal(1))])
+        currency2 = Currency(name='cur2', symbol='cur1', code='XX2',
+            rates=[CurrencyRate(rate=Decimal('.5'))])
+        Currency.save([currency1, currency2])
+
+        rate = Rate(computation_type='amount',
+            amount=Decimal(10), currency=currency1)
+        self.assertEqual(rate.compute(currency2, 1, kg), Decimal(5))
+
+        rate = Rate(computation_type='quantity',
+            amount=Decimal(10), currency=currency1, uom=kg)
+        self.assertEqual(rate.compute(currency2, 100, g), Decimal('0.5'))
+
+    @with_transaction()
+    def test_delete_category(self):
+        'Test delete category'
+        pool = Pool()
+        Tariff = pool.get('customs.tariff.code')
+        Category = pool.get('product.category')
+        Product_TariffCode = pool.get(
+            'product-customs.tariff.code')
+
+        tariff = Tariff(code='170390')
+        tariff.save()
+
+        category = Category(name='Test', customs=True,
+            tariff_codes=[
+                Product_TariffCode(tariff_code=tariff),
+                ])
+        category.save()
+        product_tariff_code, = category.tariff_codes
+
+        Category.delete([category])
+
+        self.assertEqual(
+            Product_TariffCode.search([
+                    ('id', '=', product_tariff_code.id),
+                    ]), [])
+
+    @with_transaction()
+    def test_delete_template(self):
+        'Test delete template'
+        pool = Pool()
+        Tariff = pool.get('customs.tariff.code')
+        Template = pool.get('product.template')
+        Uom = pool.get('product.uom')
+        Product_TariffCode = pool.get(
+            'product-customs.tariff.code')
+
+        unit, = Uom.search([('name', '=', 'Unit')])
+
+        tariff = Tariff(code='170390')
+        tariff.save()
+
+        template = Template(name='Test',
+            default_uom=unit,
+            tariff_codes=[
+                Product_TariffCode(tariff_code=tariff),
+                ])
+        template.save()
+        product_tariff_code, = template.tariff_codes
+
+        Template.delete([template])
+
+        self.assertEqual(
+            Product_TariffCode.search([
+                    ('id', '=', product_tariff_code.id),
+                    ]), [])
+
+
+del ModuleTestCase
diff -r 836737c062d6 -r c2bf0afa2ef9 tox.ini
--- a/tox.ini   Sun Apr 10 19:11:38 2022 +0200
+++ b/tox.ini   Sat Apr 16 18:30:17 2022 +0200
@@ -3,7 +3,7 @@
 
 [testenv]
 commands =
-    coverage run --include=.*/customs/* setup.py test
+    coverage run --include=.*/customs/* -m unittest discover -s tests
     coverage report --include=.*/customs/* --omit=*/tests/*
 deps =
     coverage

Reply via email to