changeset 88ab5fa150e7 in modules/product_image:default
details:
https://hg.tryton.org/modules/product_image?cmd=changeset&node=88ab5fa150e7
description:
Replace test setuptools command by unittest discover
issue9215
review389851002
diffstat:
setup.py | 6 ++--
tests/__init__.py | 8 -------
tests/test_module.py | 44 ++++++++++++++++++++++++++++++++++++++
tests/test_product_image.py | 51 ---------------------------------------------
tox.ini | 3 +-
5 files changed, 49 insertions(+), 63 deletions(-)
diffs (151 lines):
diff -r 6d0ab795abf3 -r 88ab5fa150e7 setup.py
--- a/setup.py Sun Apr 10 19:11:39 2022 +0200
+++ b/setup.py Sat Apr 16 18:30:18 2022 +0200
@@ -143,13 +143,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]
product_image = trytond.modules.product_image
""", # noqa: E501
- test_suite='tests',
- test_loader='trytond.test_loader:Loader',
- tests_require=tests_require,
)
diff -r 6d0ab795abf3 -r 88ab5fa150e7 tests/__init__.py
--- a/tests/__init__.py Sun Apr 10 19:11:39 2022 +0200
+++ b/tests/__init__.py Sat Apr 16 18:30:18 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.product_image.tests.test_product_image import \
- suite # noqa: E501
-except ImportError:
- from .test_product_image import suite
-
-__all__ = ['suite']
diff -r 6d0ab795abf3 -r 88ab5fa150e7 tests/test_module.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_module.py Sat Apr 16 18:30:18 2022 +0200
@@ -0,0 +1,44 @@
+# 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 io
+import urllib.request
+
+import PIL.Image
+
+from trytond.pool import Pool
+from trytond.tests.test_tryton import ModuleTestCase, with_transaction
+
+
+class ProductImageTestCase(ModuleTestCase):
+ 'Test Product Image module'
+ module = 'product_image'
+
+ @with_transaction()
+ def test_image(self):
+ "Test image"
+ pool = Pool()
+ Image = pool.get('product.image')
+ Template = pool.get('product.template')
+ Uom = pool.get('product.uom')
+
+ template = Template(name="Template")
+ template.default_uom, = Uom.search([], limit=1)
+ template.save()
+
+ image = Image(template=template)
+ image.image = urllib.request.urlopen(
+ 'https://picsum.photos/200').read()
+ image.save()
+
+ self.assertEqual(template.image_url, None)
+ template.code = "CODE"
+ template.save()
+ self.assertRegex(
+ template.image_url,
+ r'/product/image/CODE/.*/Template\?s=64')
+
+ img = PIL.Image.open(io.BytesIO(image.get(size=100)))
+ self.assertEqual(img.size, (100, 100))
+
+
+del ModuleTestCase
diff -r 6d0ab795abf3 -r 88ab5fa150e7 tests/test_product_image.py
--- a/tests/test_product_image.py Sun Apr 10 19:11:39 2022 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +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 io
-import unittest
-import urllib.request
-
-import PIL.Image
-
-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 ProductImageTestCase(ModuleTestCase):
- 'Test Product Image module'
- module = 'product_image'
-
- @with_transaction()
- def test_image(self):
- "Test image"
- pool = Pool()
- Image = pool.get('product.image')
- Template = pool.get('product.template')
- Uom = pool.get('product.uom')
-
- template = Template(name="Template")
- template.default_uom, = Uom.search([], limit=1)
- template.save()
-
- image = Image(template=template)
- image.image = urllib.request.urlopen(
- 'https://picsum.photos/200').read()
- image.save()
-
- self.assertEqual(template.image_url, None)
- template.code = "CODE"
- template.save()
- self.assertRegex(
- template.image_url,
- r'/product/image/CODE/.*/Template\?s=64')
-
- img = PIL.Image.open(io.BytesIO(image.get(size=100)))
- self.assertEqual(img.size, (100, 100))
-
-
-def suite():
- suite = test_suite()
- suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
- ProductImageTestCase))
- return suite
diff -r 6d0ab795abf3 -r 88ab5fa150e7 tox.ini
--- a/tox.ini Sun Apr 10 19:11:39 2022 +0200
+++ b/tox.ini Sat Apr 16 18:30:18 2022 +0200
@@ -2,8 +2,9 @@
envlist = {py37,py38,py39,py310}-{sqlite,postgresql}
[testenv]
+extras = test
commands =
- coverage run --include=.*/product_image/* setup.py test
+ coverage run --include=.*/product_image/* -m unittest discover -s tests
coverage report --include=.*/product_image/* --omit=*/tests/*
deps =
coverage