changeset 84e7a278cc4b in modules/web_shortener:default
details:
https://hg.tryton.org/modules/web_shortener?cmd=changeset&node=84e7a278cc4b
description:
Replace test setuptools command by unittest discover
issue9215
review389851002
diffstat:
setup.py | 6 +++---
tests/__init__.py | 7 -------
tests/test_module.py | 30 ++++++++++++++++++++++++++++++
tests/test_web_shortener.py | 37 -------------------------------------
tox.ini | 3 ++-
5 files changed, 35 insertions(+), 48 deletions(-)
diffs (122 lines):
diff -r 1ae688e44424 -r 84e7a278cc4b setup.py
--- a/setup.py Thu Apr 14 09:30:18 2022 +0200
+++ b/setup.py Sat Apr 16 18:30:20 2022 +0200
@@ -137,13 +137,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]
web_shortener = trytond.modules.web_shortener
""",
- test_suite='tests',
- test_loader='trytond.test_loader:Loader',
- tests_require=tests_require,
)
diff -r 1ae688e44424 -r 84e7a278cc4b tests/__init__.py
--- a/tests/__init__.py Thu Apr 14 09:30:18 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.web_shortener.tests.test_web_shortener import suite
-except ImportError:
- from .test_web_shortener import suite
-
-__all__ = ['suite']
diff -r 1ae688e44424 -r 84e7a278cc4b 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,30 @@
+# 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 random
+import sys
+
+from trytond.pool import Pool
+from trytond.tests.test_tryton import ModuleTestCase, with_transaction
+
+
+class WebShortenerTestCase(ModuleTestCase):
+ 'Test Web Shortener module'
+ module = 'web_shortener'
+
+ @with_transaction()
+ def test_shorten(self):
+ pool = Pool()
+ ShortenedURL = pool.get('web.shortened_url')
+ expand = ShortenedURL._expand
+ shorten = ShortenedURL._shorten
+
+ self.assertEqual(expand(shorten(0)), 0)
+ self.assertEqual(expand(shorten(sys.maxsize)), sys.maxsize)
+
+ for _ in range(10):
+ x = random.randint(0, sys.maxsize)
+ self.assertEqual(expand(shorten(x)), x)
+
+
+del ModuleTestCase
diff -r 1ae688e44424 -r 84e7a278cc4b tests/test_web_shortener.py
--- a/tests/test_web_shortener.py Thu Apr 14 09:30:18 2022 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +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 random
-import sys
-import unittest
-
-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 WebShortenerTestCase(ModuleTestCase):
- 'Test Web Shortener module'
- module = 'web_shortener'
-
- @with_transaction()
- def test_shorten(self):
- pool = Pool()
- ShortenedURL = pool.get('web.shortened_url')
- expand = ShortenedURL._expand
- shorten = ShortenedURL._shorten
-
- self.assertEqual(expand(shorten(0)), 0)
- self.assertEqual(expand(shorten(sys.maxsize)), sys.maxsize)
-
- for _ in range(10):
- x = random.randint(0, sys.maxsize)
- self.assertEqual(expand(shorten(x)), x)
-
-
-def suite():
- suite = test_suite()
- suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
- WebShortenerTestCase))
- return suite
diff -r 1ae688e44424 -r 84e7a278cc4b tox.ini
--- a/tox.ini Thu Apr 14 09:30:18 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=.*/web_shortener/* setup.py test
+ coverage run --include=.*/web_shortener/* -m unittest discover -s tests
coverage report --include=.*/web_shortener/* --omit=*/tests/*
deps =
coverage