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

        issue9215
        review389851002
diffstat:

 setup.py                               |    6 +-
 tests/__init__.py                      |    8 -
 tests/test_account_tax_rule_country.py |  176 ---------------------------------
 tests/test_module.py                   |  170 +++++++++++++++++++++++++++++++
 tox.ini                                |    3 +-
 5 files changed, 175 insertions(+), 188 deletions(-)

diffs (402 lines):

diff -r cee0534d4d10 -r 51b4d5ddda59 setup.py
--- a/setup.py  Sun Apr 10 19:11:38 2022 +0200
+++ b/setup.py  Sat Apr 16 18:30:17 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_tax_rule_country = trytond.modules.account_tax_rule_country
     """,
-    test_suite='tests',
-    test_loader='trytond.test_loader:Loader',
-    tests_require=tests_require,
     )
diff -r cee0534d4d10 -r 51b4d5ddda59 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,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_tax_rule_country.tests.test_account_tax_rule_country 
import \
-        suite  # noqa: E501
-except ImportError:
-    from .test_account_tax_rule_country import suite
-
-__all__ = ['suite']
diff -r cee0534d4d10 -r 51b4d5ddda59 tests/test_account_tax_rule_country.py
--- a/tests/test_account_tax_rule_country.py    Sun Apr 10 19:11:38 2022 +0200
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,176 +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
-
-import trytond.tests.test_tryton
-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 AccountTaxRuleCountryTestCase(CompanyTestMixin, ModuleTestCase):
-    'Test Account Tax Rule Country module'
-    module = 'account_tax_rule_country'
-    extras = ['account_invoice', 'sale', 'purchase', 'stock']
-
-    @with_transaction()
-    def test_account_chart(self):
-        'Test creation and update of minimal chart of accounts'
-        pool = Pool()
-        Account = pool.get('account.account')
-        UpdateChart = pool.get('account.update_chart', type='wizard')
-
-        company = create_company()
-        with set_company(company):
-            create_chart(company, tax=True)
-            root, = Account.search([('parent', '=', None)])
-
-            session_id, _, _ = UpdateChart.create()
-            update_chart = UpdateChart(session_id)
-            update_chart.start.account = root
-            update_chart.transition_update()
-
-    @classmethod
-    def _create_countries(cls):
-        pool = Pool()
-        Country = pool.get('country.country')
-        Subdivision = pool.get('country.subdivision')
-
-        country1 = Country(name="Country 1")
-        country1.save()
-        subdivision1 = Subdivision(
-            country=country1, name="Subdivision 1", code="SUB1",
-            type='province')
-        subdivision1.save()
-        subdivision11 = Subdivision(
-            country=country1, parent=subdivision1,
-            name="Sub-Subdivision 1", code="SUBSUB1", type='province')
-        subdivision11.save()
-        country2 = Country(name="Country 2")
-        country2.save()
-        subdivision2 = Subdivision(
-            country=country2, name="Subdivision 2", code="SUB2",
-            type='province')
-        subdivision2.save()
-
-        return [country1, country2]
-
-    def _get_taxes(cls):
-        pool = Pool()
-        Tax = pool.get('account.tax')
-        tax, = Tax.search([])
-        target_tax, = Tax.copy([tax])
-        return [tax, target_tax]
-
-    def _create_rule(cls, lines):
-        pool = Pool()
-        TaxRule = pool.get('account.tax.rule')
-        return TaxRule.create([{
-                    'name': 'Test',
-                    'kind': 'both',
-                    'lines': [('create', lines)],
-                    }])[0]
-
-    @with_transaction()
-    def test_tax_rule(self):
-        "Test tax rule"
-        country1, country2 = self._create_countries()[:2]
-        subdivision1 = country1.subdivisions[0]
-        subdivision2 = country2.subdivisions[0]
-        company = create_company()
-        with set_company(company):
-            create_chart(company, tax=True)
-            tax, target_tax = self._get_taxes()[:2]
-            tax_rule = self._create_rule([{
-                        'from_country': country1.id,
-                        'from_subdivision': subdivision1.id,
-                        'to_country': country2.id,
-                        'to_subdivision': subdivision2.id,
-                        'origin_tax': tax.id,
-                        'tax': target_tax.id,
-                        }])
-            pattern = {
-                'from_country': country1.id,
-                'from_subdivision': subdivision1.id,
-                'to_country': country2.id,
-                'to_subdivision': subdivision2.id,
-                }
-
-            self.assertListEqual(tax_rule.apply(tax, pattern), [target_tax.id])
-
-    @with_transaction()
-    def test_tax_rule_children(self):
-        "Test tax rule with children subdivision"
-        country = self._create_countries()[0]
-        parent_subdivision = [
-            s for s in country.subdivisions if not s.parent][0]
-        subdivision = [
-            s for s in country.subdivisions
-            if s.parent == parent_subdivision][0]
-        company = create_company()
-        with set_company(company):
-            create_chart(company, tax=True)
-            tax, target_tax = self._get_taxes()[:2]
-            tax_rule = self._create_rule([{
-                        'to_country': country.id,
-                        'to_subdivision': parent_subdivision.id,
-                        'origin_tax': tax.id,
-                        'tax': target_tax.id,
-                        }])
-            pattern = {
-                'to_country': country.id,
-                'to_subdivision': subdivision.id,
-                }
-
-            self.assertListEqual(tax_rule.apply(tax, pattern), [target_tax.id])
-
-    @with_transaction()
-    def test_tax_rule_no_subdivision(self):
-        "Test tax rule without subdivision"
-        country = self._create_countries()[0]
-        subdivision = country.subdivisions[0]
-        company = create_company()
-        with set_company(company):
-            create_chart(company, tax=True)
-            tax, target_tax = self._get_taxes()[:2]
-            tax_rule = self._create_rule([{
-                        'to_country': country.id,
-                        'origin_tax': tax.id,
-                        'tax': target_tax.id,
-                        }])
-            pattern = {
-                'to_country': country.id,
-                'to_subdivision': subdivision.id,
-                }
-
-            self.assertListEqual(tax_rule.apply(tax, pattern), [target_tax.id])
-
-    @with_transaction()
-    def test_tax_rule_no_subdivision_pattern(self):
-        "Test tax rule without subdivision in pattern"
-        country = self._create_countries()[0]
-        subdivision = country.subdivisions[0]
-        company = create_company()
-        with set_company(company):
-            create_chart(company, tax=True)
-            tax, target_tax = self._get_taxes()[:2]
-            tax_rule = self._create_rule([{
-                        'to_country': country.id,
-                        'to_subdivision': subdivision.id,
-                        'origin_tax': tax.id,
-                        'tax': target_tax.id,
-                        }])
-            pattern = {
-                'to_country': country.id,
-                }
-
-            self.assertListEqual(tax_rule.apply(tax, pattern), [tax.id])
-
-
-def suite():
-    suite = trytond.tests.test_tryton.suite()
-    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
-        AccountTaxRuleCountryTestCase))
-    return suite
diff -r cee0534d4d10 -r 51b4d5ddda59 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,170 @@
+# 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 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 AccountTaxRuleCountryTestCase(CompanyTestMixin, ModuleTestCase):
+    'Test Account Tax Rule Country module'
+    module = 'account_tax_rule_country'
+    extras = ['account_invoice', 'sale', 'purchase', 'stock']
+
+    @with_transaction()
+    def test_account_chart(self):
+        'Test creation and update of minimal chart of accounts'
+        pool = Pool()
+        Account = pool.get('account.account')
+        UpdateChart = pool.get('account.update_chart', type='wizard')
+
+        company = create_company()
+        with set_company(company):
+            create_chart(company, tax=True)
+            root, = Account.search([('parent', '=', None)])
+
+            session_id, _, _ = UpdateChart.create()
+            update_chart = UpdateChart(session_id)
+            update_chart.start.account = root
+            update_chart.transition_update()
+
+    @classmethod
+    def _create_countries(cls):
+        pool = Pool()
+        Country = pool.get('country.country')
+        Subdivision = pool.get('country.subdivision')
+
+        country1 = Country(name="Country 1")
+        country1.save()
+        subdivision1 = Subdivision(
+            country=country1, name="Subdivision 1", code="SUB1",
+            type='province')
+        subdivision1.save()
+        subdivision11 = Subdivision(
+            country=country1, parent=subdivision1,
+            name="Sub-Subdivision 1", code="SUBSUB1", type='province')
+        subdivision11.save()
+        country2 = Country(name="Country 2")
+        country2.save()
+        subdivision2 = Subdivision(
+            country=country2, name="Subdivision 2", code="SUB2",
+            type='province')
+        subdivision2.save()
+
+        return [country1, country2]
+
+    def _get_taxes(cls):
+        pool = Pool()
+        Tax = pool.get('account.tax')
+        tax, = Tax.search([])
+        target_tax, = Tax.copy([tax])
+        return [tax, target_tax]
+
+    def _create_rule(cls, lines):
+        pool = Pool()
+        TaxRule = pool.get('account.tax.rule')
+        return TaxRule.create([{
+                    'name': 'Test',
+                    'kind': 'both',
+                    'lines': [('create', lines)],
+                    }])[0]
+
+    @with_transaction()
+    def test_tax_rule(self):
+        "Test tax rule"
+        country1, country2 = self._create_countries()[:2]
+        subdivision1 = country1.subdivisions[0]
+        subdivision2 = country2.subdivisions[0]
+        company = create_company()
+        with set_company(company):
+            create_chart(company, tax=True)
+            tax, target_tax = self._get_taxes()[:2]
+            tax_rule = self._create_rule([{
+                        'from_country': country1.id,
+                        'from_subdivision': subdivision1.id,
+                        'to_country': country2.id,
+                        'to_subdivision': subdivision2.id,
+                        'origin_tax': tax.id,
+                        'tax': target_tax.id,
+                        }])
+            pattern = {
+                'from_country': country1.id,
+                'from_subdivision': subdivision1.id,
+                'to_country': country2.id,
+                'to_subdivision': subdivision2.id,
+                }
+
+            self.assertListEqual(tax_rule.apply(tax, pattern), [target_tax.id])
+
+    @with_transaction()
+    def test_tax_rule_children(self):
+        "Test tax rule with children subdivision"
+        country = self._create_countries()[0]
+        parent_subdivision = [
+            s for s in country.subdivisions if not s.parent][0]
+        subdivision = [
+            s for s in country.subdivisions
+            if s.parent == parent_subdivision][0]
+        company = create_company()
+        with set_company(company):
+            create_chart(company, tax=True)
+            tax, target_tax = self._get_taxes()[:2]
+            tax_rule = self._create_rule([{
+                        'to_country': country.id,
+                        'to_subdivision': parent_subdivision.id,
+                        'origin_tax': tax.id,
+                        'tax': target_tax.id,
+                        }])
+            pattern = {
+                'to_country': country.id,
+                'to_subdivision': subdivision.id,
+                }
+
+            self.assertListEqual(tax_rule.apply(tax, pattern), [target_tax.id])
+
+    @with_transaction()
+    def test_tax_rule_no_subdivision(self):
+        "Test tax rule without subdivision"
+        country = self._create_countries()[0]
+        subdivision = country.subdivisions[0]
+        company = create_company()
+        with set_company(company):
+            create_chart(company, tax=True)
+            tax, target_tax = self._get_taxes()[:2]
+            tax_rule = self._create_rule([{
+                        'to_country': country.id,
+                        'origin_tax': tax.id,
+                        'tax': target_tax.id,
+                        }])
+            pattern = {
+                'to_country': country.id,
+                'to_subdivision': subdivision.id,
+                }
+
+            self.assertListEqual(tax_rule.apply(tax, pattern), [target_tax.id])
+
+    @with_transaction()
+    def test_tax_rule_no_subdivision_pattern(self):
+        "Test tax rule without subdivision in pattern"
+        country = self._create_countries()[0]
+        subdivision = country.subdivisions[0]
+        company = create_company()
+        with set_company(company):
+            create_chart(company, tax=True)
+            tax, target_tax = self._get_taxes()[:2]
+            tax_rule = self._create_rule([{
+                        'to_country': country.id,
+                        'to_subdivision': subdivision.id,
+                        'origin_tax': tax.id,
+                        'tax': target_tax.id,
+                        }])
+            pattern = {
+                'to_country': country.id,
+                }
+
+            self.assertListEqual(tax_rule.apply(tax, pattern), [tax.id])
+
+
+del ModuleTestCase
diff -r cee0534d4d10 -r 51b4d5ddda59 tox.ini
--- a/tox.ini   Sun Apr 10 19:11:38 2022 +0200
+++ b/tox.ini   Sat Apr 16 18:30:17 2022 +0200
@@ -2,8 +2,9 @@
 envlist = {py37,py38,py39,py310}-{sqlite,postgresql}
 
 [testenv]
+extras = test
 commands =
-    coverage run --include=.*/account_tax_rule_country/* setup.py test
+    coverage run --include=.*/account_tax_rule_country/* -m unittest discover 
-s tests
     coverage report --include=.*/account_tax_rule_country/* --omit=*/tests/*
 deps =
     coverage

Reply via email to