changeset 38dfb5ebb358 in modules/stock_split:default
details:
https://hg.tryton.org/modules/stock_split?cmd=changeset&node=38dfb5ebb358
description:
Replace test setuptools command by unittest discover
issue9215
review389851002
diffstat:
setup.py | 6 +-
tests/__init__.py | 7 ---
tests/test_module.py | 90 ++++++++++++++++++++++++++++++++++++++++
tests/test_scenario.py | 22 +++++++++
tests/test_stock_split.py | 103 ----------------------------------------------
tox.ini | 3 +-
6 files changed, 117 insertions(+), 114 deletions(-)
diffs (274 lines):
diff -r a1b85f92a988 -r 38dfb5ebb358 setup.py
--- a/setup.py Sun Apr 10 19:11:40 2022 +0200
+++ b/setup.py Sat Apr 16 18:30:20 2022 +0200
@@ -138,13 +138,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_split = trytond.modules.stock_split
""",
- test_suite='tests',
- test_loader='trytond.test_loader:Loader',
- tests_require=tests_require,
)
diff -r a1b85f92a988 -r 38dfb5ebb358 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,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.stock_split.tests.test_stock_split import suite
-except ImportError:
- from .test_stock_split import suite
-
-__all__ = ['suite']
diff -r a1b85f92a988 -r 38dfb5ebb358 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,90 @@
+# 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.company.tests import (
+ CompanyTestMixin, create_company, set_company)
+from trytond.pool import Pool
+from trytond.tests.test_tryton import ModuleTestCase, with_transaction
+
+
+class StockSplitTestCase(CompanyTestMixin, ModuleTestCase):
+ 'Test Stock Lot module'
+ module = 'stock_split'
+
+ @with_transaction()
+ def test_split(self):
+ 'Test split'
+ 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')
+
+ unit, = Uom.search([('name', '=', 'Unit')])
+ template, = Template.create([{
+ 'name': 'Test Split',
+ 'type': 'goods',
+ 'default_uom': unit.id,
+ }])
+ product, = Product.create([{
+ 'template': template.id,
+ }])
+ input_, = Location.search([('code', '=', 'IN')])
+ storage, = Location.search([('code', '=', 'STO')])
+ company = create_company()
+ with set_company(company):
+
+ def create_move(quantity):
+ move, = Move.create([{
+ 'product': product.id,
+ 'uom': unit.id,
+ 'quantity': quantity,
+ 'from_location': input_.id,
+ 'to_location': storage.id,
+ 'company': company.id,
+ }])
+ return move
+
+ move = create_move(10)
+ moves = move.split(5, unit)
+ self.assertEqual(len(moves), 2)
+ self.assertEqual([m.quantity for m in moves], [5, 5])
+
+ move = create_move(13)
+ moves = move.split(5, unit)
+ self.assertEqual(len(moves), 3)
+ self.assertEqual([m.quantity for m in moves], [5, 5, 3])
+
+ move = create_move(7)
+ moves = move.split(8, unit)
+ self.assertEqual(moves, [move])
+ self.assertEqual(move.quantity, 7)
+
+ move = create_move(20)
+ moves = move.split(5, unit, count=2)
+ self.assertEqual(len(moves), 3)
+ self.assertEqual([m.quantity for m in moves], [5, 5, 10])
+
+ move = create_move(20)
+ moves = move.split(5, unit, count=4)
+ self.assertEqual(len(moves), 4)
+ self.assertEqual([m.quantity for m in moves], [5, 5, 5, 5])
+
+ move = create_move(10)
+ moves = move.split(5, unit, count=3)
+ self.assertEqual(len(moves), 2)
+ self.assertEqual([m.quantity for m in moves], [5, 5])
+
+ move = create_move(10)
+ Move.write([move], {
+ 'state': 'assigned',
+ })
+ moves = move.split(5, unit)
+ self.assertEqual(len(moves), 2)
+ self.assertEqual([m.quantity for m in moves], [5, 5])
+ self.assertEqual([m.state for m in moves],
+ ['assigned', 'assigned'])
+
+
+del ModuleTestCase
diff -r a1b85f92a988 -r 38dfb5ebb358 tests/test_scenario.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_scenario.py Sat Apr 16 18:30:20 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 a1b85f92a988 -r 38dfb5ebb358 tests/test_stock_split.py
--- a/tests/test_stock_split.py Sun Apr 10 19:11:40 2022 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,103 +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.company.tests import (
- CompanyTestMixin, create_company, set_company)
-from trytond.pool import Pool
-from trytond.tests.test_tryton import (
- ModuleTestCase, doctest_checker, doctest_teardown, with_transaction)
-
-
-class StockSplitTestCase(CompanyTestMixin, ModuleTestCase):
- 'Test Stock Lot module'
- module = 'stock_split'
-
- @with_transaction()
- def test_split(self):
- 'Test split'
- 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')
-
- unit, = Uom.search([('name', '=', 'Unit')])
- template, = Template.create([{
- 'name': 'Test Split',
- 'type': 'goods',
- 'default_uom': unit.id,
- }])
- product, = Product.create([{
- 'template': template.id,
- }])
- input_, = Location.search([('code', '=', 'IN')])
- storage, = Location.search([('code', '=', 'STO')])
- company = create_company()
- with set_company(company):
-
- def create_move(quantity):
- move, = Move.create([{
- 'product': product.id,
- 'uom': unit.id,
- 'quantity': quantity,
- 'from_location': input_.id,
- 'to_location': storage.id,
- 'company': company.id,
- }])
- return move
-
- move = create_move(10)
- moves = move.split(5, unit)
- self.assertEqual(len(moves), 2)
- self.assertEqual([m.quantity for m in moves], [5, 5])
-
- move = create_move(13)
- moves = move.split(5, unit)
- self.assertEqual(len(moves), 3)
- self.assertEqual([m.quantity for m in moves], [5, 5, 3])
-
- move = create_move(7)
- moves = move.split(8, unit)
- self.assertEqual(moves, [move])
- self.assertEqual(move.quantity, 7)
-
- move = create_move(20)
- moves = move.split(5, unit, count=2)
- self.assertEqual(len(moves), 3)
- self.assertEqual([m.quantity for m in moves], [5, 5, 10])
-
- move = create_move(20)
- moves = move.split(5, unit, count=4)
- self.assertEqual(len(moves), 4)
- self.assertEqual([m.quantity for m in moves], [5, 5, 5, 5])
-
- move = create_move(10)
- moves = move.split(5, unit, count=3)
- self.assertEqual(len(moves), 2)
- self.assertEqual([m.quantity for m in moves], [5, 5])
-
- move = create_move(10)
- Move.write([move], {
- 'state': 'assigned',
- })
- moves = move.split(5, unit)
- self.assertEqual(len(moves), 2)
- self.assertEqual([m.quantity for m in moves], [5, 5])
- self.assertEqual([m.state for m in moves],
- ['assigned', 'assigned'])
-
-
-def suite():
- suite = trytond.tests.test_tryton.suite()
- suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
- StockSplitTestCase))
- suite.addTests(doctest.DocFileSuite('scenario_stock_split_shipment.rst',
- tearDown=doctest_teardown, encoding='utf-8',
- checker=doctest_checker,
- optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
- return suite
diff -r a1b85f92a988 -r 38dfb5ebb358 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_split/* setup.py test
+ coverage run --include=.*/stock_split/* -m unittest discover -s tests
coverage report --include=.*/stock_split/* --omit=*/tests/*
deps =
coverage