changeset 1b0b709ad7b9 in modules/account_stock_anglo_saxon:default
details:
https://hg.tryton.org/modules/account_stock_anglo_saxon?cmd=changeset&node=1b0b709ad7b9
description:
Replace test setuptools command by unittest discover
issue9215
review389851002
diffstat:
setup.py | 6 +-
tests/__init__.py | 8 ---
tests/test_account_stock_anglo_saxon.py | 67 ---------------------------------
tests/test_module.py | 50 ++++++++++++++++++++++++
tests/test_scenario.py | 22 ++++++++++
tox.ini | 3 +-
6 files changed, 77 insertions(+), 79 deletions(-)
diffs (199 lines):
diff -r 550b88793982 -r 1b0b709ad7b9 setup.py
--- a/setup.py Sun Apr 10 19:11:38 2022 +0200
+++ b/setup.py Sat Apr 16 18:30:16 2022 +0200
@@ -142,13 +142,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_stock_anglo_saxon = trytond.modules.account_stock_anglo_saxon
""",
- test_suite='tests',
- test_loader='trytond.test_loader:Loader',
- tests_require=tests_require,
)
diff -r 550b88793982 -r 1b0b709ad7b9 tests/__init__.py
--- a/tests/__init__.py Sun Apr 10 19:11:38 2022 +0200
+++ b/tests/__init__.py Sat Apr 16 18:30:16 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_stock_anglo_saxon.tests.test_account_stock_anglo_saxon
import \
- suite # noqa: E501
-except ImportError:
- from .test_account_stock_anglo_saxon import suite
-
-__all__ = ['suite']
diff -r 550b88793982 -r 1b0b709ad7b9 tests/test_account_stock_anglo_saxon.py
--- a/tests/test_account_stock_anglo_saxon.py Sun Apr 10 19:11:38 2022 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,67 +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 unittest.mock import Mock, patch
-
-import trytond.tests.test_tryton
-from trytond.pool import Pool
-from trytond.tests.test_tryton import (
- ModuleTestCase, doctest_checker, doctest_teardown, with_transaction)
-
-
-class AccountStockAngloSaxonTestCase(ModuleTestCase):
- 'Test Account Stock Anglo Saxon module'
- module = 'account_stock_anglo_saxon'
-
- @with_transaction()
- def test_get_anglo_saxon_move(self):
- 'Test _get_anglo_saxon_move'
- pool = Pool()
- Move = pool.get('stock.move')
- Uom = pool.get('product.uom')
- Currency = pool.get('currency.currency')
-
- def move(quantity, price):
- move = Mock()
- move.quantity = quantity
- move.unit_price = price
- move.cost_price = price
- move.in_anglo_saxon_quantity = 0
- move.out_anglo_saxon_quantity = 0
- return move
-
- with patch.object(Uom, 'compute_qty') as compute_qty, \
- patch.object(Uom, 'compute_price') as compute_price, \
- patch.object(Currency, 'compute') as compute:
- compute_qty.side_effect = lambda *args, **kwargs: args[1]
- compute_price.side_effect = lambda *args, **kwargs: args[1]
- compute.side_effect = lambda *args, **kwargs: args[1]
-
- moves = [move(1, 3), move(2, 2)]
- result = list(Move._get_anglo_saxon_move(
- moves, 1, 'in_supplier'))
- self.assertEqual(result, [(moves[0], 1, 3)])
-
- moves = [move(1, 3), move(2, 2)]
- result = list(Move._get_anglo_saxon_move(
- moves, 2, 'in_supplier'))
- self.assertEqual(result,
- [(moves[0], 1, 3), (moves[1], 1, 2)])
-
-
-def suite():
- suite = trytond.tests.test_tryton.suite()
- suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
- AccountStockAngloSaxonTestCase))
- suite.addTests(doctest.DocFileSuite(
- 'scenario_account_stock_anglo_saxon.rst',
- tearDown=doctest_teardown, encoding='utf-8',
- checker=doctest_checker,
- optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
- suite.addTests(doctest.DocFileSuite(
- 'scenario_account_stock_anglo_saxon_with_drop_shipment.rst',
- tearDown=doctest_teardown, encoding='utf-8',
- checker=doctest_checker,
- optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
- return suite
diff -r 550b88793982 -r 1b0b709ad7b9 tests/test_module.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_module.py Sat Apr 16 18:30:16 2022 +0200
@@ -0,0 +1,50 @@
+# 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 unittest.mock import Mock, patch
+
+from trytond.pool import Pool
+from trytond.tests.test_tryton import ModuleTestCase, with_transaction
+
+
+class AccountStockAngloSaxonTestCase(ModuleTestCase):
+ 'Test Account Stock Anglo Saxon module'
+ module = 'account_stock_anglo_saxon'
+
+ @with_transaction()
+ def test_get_anglo_saxon_move(self):
+ 'Test _get_anglo_saxon_move'
+ pool = Pool()
+ Move = pool.get('stock.move')
+ Uom = pool.get('product.uom')
+ Currency = pool.get('currency.currency')
+
+ def move(quantity, price):
+ move = Mock()
+ move.quantity = quantity
+ move.unit_price = price
+ move.cost_price = price
+ move.in_anglo_saxon_quantity = 0
+ move.out_anglo_saxon_quantity = 0
+ return move
+
+ with patch.object(Uom, 'compute_qty') as compute_qty, \
+ patch.object(Uom, 'compute_price') as compute_price, \
+ patch.object(Currency, 'compute') as compute:
+ compute_qty.side_effect = lambda *args, **kwargs: args[1]
+ compute_price.side_effect = lambda *args, **kwargs: args[1]
+ compute.side_effect = lambda *args, **kwargs: args[1]
+
+ moves = [move(1, 3), move(2, 2)]
+ result = list(Move._get_anglo_saxon_move(
+ moves, 1, 'in_supplier'))
+ self.assertEqual(result, [(moves[0], 1, 3)])
+
+ moves = [move(1, 3), move(2, 2)]
+ result = list(Move._get_anglo_saxon_move(
+ moves, 2, 'in_supplier'))
+ self.assertEqual(result,
+ [(moves[0], 1, 3), (moves[1], 1, 2)])
+
+
+del ModuleTestCase
diff -r 550b88793982 -r 1b0b709ad7b9 tests/test_scenario.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_scenario.py Sat Apr 16 18:30:16 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 550b88793982 -r 1b0b709ad7b9 tox.ini
--- a/tox.ini Sun Apr 10 19:11:38 2022 +0200
+++ b/tox.ini Sat Apr 16 18:30:16 2022 +0200
@@ -2,8 +2,9 @@
envlist = {py37,py38,py39,py310}-{sqlite,postgresql}
[testenv]
+extras = test
commands =
- coverage run --include=.*/account_stock_anglo_saxon/* setup.py test
+ coverage run --include=.*/account_stock_anglo_saxon/* -m unittest discover
-s tests
coverage report --include=.*/account_stock_anglo_saxon/* --omit=*/tests/*
deps =
coverage