changeset 8fc57e4d719a in modules/product_image_attribute:default
details:
https://hg.tryton.org/modules/product_image_attribute?cmd=changeset&node=8fc57e4d719a
description:
Replace test setuptools command by unittest discover
issue9215
review389851002
diffstat:
setup.py | 6 +-
tests/__init__.py | 8 ---
tests/test_module.py | 68 +++++++++++++++++++++++++++++++
tests/test_product_image_attribute.py | 75 -----------------------------------
tox.ini | 3 +-
5 files changed, 73 insertions(+), 87 deletions(-)
diffs (199 lines):
diff -r c136ca179d7a -r 8fc57e4d719a setup.py
--- a/setup.py Sun Apr 10 19:11:39 2022 +0200
+++ b/setup.py Sat Apr 16 18:30:18 2022 +0200
@@ -144,13 +144,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_attribute = trytond.modules.product_image_attribute
""", # noqa: E501
- test_suite='tests',
- test_loader='trytond.test_loader:Loader',
- tests_require=tests_require,
)
diff -r c136ca179d7a -r 8fc57e4d719a 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_attribute.tests.test_product_image_attribute
import \
- suite # noqa: E501
-except ImportError:
- from .test_product_image_attribute import suite
-
-__all__ = ['suite']
diff -r c136ca179d7a -r 8fc57e4d719a 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,68 @@
+# 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 urllib.request
+
+from trytond.pool import Pool
+from trytond.tests.test_tryton import ModuleTestCase, with_transaction
+
+
+class ProductImageAttributeTestCase(ModuleTestCase):
+ 'Test Product Image Attribute module'
+ module = 'product_image_attribute'
+
+ @with_transaction()
+ def test_image_attribute(self):
+ "Test image with attribute"
+ pool = Pool()
+ Attribute = pool.get('product.attribute')
+ AttributeSet = pool.get('product.attribute.set')
+ Image = pool.get('product.image')
+ Product = pool.get('product.product')
+ Template = pool.get('product.template')
+ Uom = pool.get('product.uom')
+
+ attribute1 = Attribute(name='attr1', string="Attribute 1")
+ attribute1.type_ = 'char'
+ attribute1.save()
+ attribute2 = Attribute(name='attr2', string="Attribute 2")
+ attribute2.type_ = 'integer'
+ attribute2.save()
+ attribute_set = AttributeSet(name="Attribute Set")
+ attribute_set.attributes = [attribute1, attribute2]
+ attribute_set.save()
+ template = Template(name="Template")
+ template.default_uom, = Uom.search([], limit=1)
+ template.attribute_set = attribute_set
+ product = Product(template=template)
+ product.attributes = {
+ 'attr1': 'foo',
+ 'attr2': 2,
+ }
+ product.save()
+ image1 = Image(template=template)
+ image1.image = urllib.request.urlopen(
+ 'https://picsum.photos/200').read()
+ image1.save()
+ image2 = Image(template=template, product=product)
+ image2.image = urllib.request.urlopen(
+ 'https://picsum.photos/200').read()
+ image2.save()
+ image3 = Image(template=template)
+ image3.image = urllib.request.urlopen(
+ 'https://picsum.photos/200').read()
+ image3.attributes = {
+ 'attr1': 'foo',
+ }
+ image3.save()
+ image4 = Image(template=template)
+ image4.image = urllib.request.urlopen(
+ 'https://picsum.photos/200').read()
+ image4.attributes = {
+ 'attr1': 'bar',
+ }
+ image4.save()
+
+ self.assertEqual(list(product.images_used), [image2, image1, image3])
+
+
+del ModuleTestCase
diff -r c136ca179d7a -r 8fc57e4d719a tests/test_product_image_attribute.py
--- a/tests/test_product_image_attribute.py Sun Apr 10 19:11:39 2022 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +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 urllib.request
-
-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 ProductImageAttributeTestCase(ModuleTestCase):
- 'Test Product Image Attribute module'
- module = 'product_image_attribute'
-
- @with_transaction()
- def test_image_attribute(self):
- "Test image with attribute"
- pool = Pool()
- Attribute = pool.get('product.attribute')
- AttributeSet = pool.get('product.attribute.set')
- Image = pool.get('product.image')
- Product = pool.get('product.product')
- Template = pool.get('product.template')
- Uom = pool.get('product.uom')
-
- attribute1 = Attribute(name='attr1', string="Attribute 1")
- attribute1.type_ = 'char'
- attribute1.save()
- attribute2 = Attribute(name='attr2', string="Attribute 2")
- attribute2.type_ = 'integer'
- attribute2.save()
- attribute_set = AttributeSet(name="Attribute Set")
- attribute_set.attributes = [attribute1, attribute2]
- attribute_set.save()
- template = Template(name="Template")
- template.default_uom, = Uom.search([], limit=1)
- template.attribute_set = attribute_set
- product = Product(template=template)
- product.attributes = {
- 'attr1': 'foo',
- 'attr2': 2,
- }
- product.save()
- image1 = Image(template=template)
- image1.image = urllib.request.urlopen(
- 'https://picsum.photos/200').read()
- image1.save()
- image2 = Image(template=template, product=product)
- image2.image = urllib.request.urlopen(
- 'https://picsum.photos/200').read()
- image2.save()
- image3 = Image(template=template)
- image3.image = urllib.request.urlopen(
- 'https://picsum.photos/200').read()
- image3.attributes = {
- 'attr1': 'foo',
- }
- image3.save()
- image4 = Image(template=template)
- image4.image = urllib.request.urlopen(
- 'https://picsum.photos/200').read()
- image4.attributes = {
- 'attr1': 'bar',
- }
- image4.save()
-
- self.assertEqual(list(product.images_used), [image2, image1, image3])
-
-
-def suite():
- suite = test_suite()
- suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
- ProductImageAttributeTestCase))
- return suite
diff -r c136ca179d7a -r 8fc57e4d719a 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_attribute/* setup.py test
+ coverage run --include=.*/product_image_attribute/* -m unittest discover
-s tests
coverage report --include=.*/product_image_attribute/* --omit=*/tests/*
deps =
coverage