Fix #9 - Update tests to unittest style
I think te
target in Makefile
could be dropped as well.
Merge request reports
Activity
The modifications inside this branch cause
make test
to fail in some circumstances:Gentoo + python-2.7:
PYTHONPATH=.:.libs /usr/bin/python2.7 -m unittest discover test ..................................................................................................................... ---------------------------------------------------------------------- Ran 117 tests in 0.006s OK
Gentoo + python-3.6:
PYTHONPATH=.:.libs /usr/bin/python3.6 -m unittest discover test E..................................................................................................................... ====================================================================== ERROR: pretty_isds (unittest.loader._FailedTest) ---------------------------------------------------------------------- ImportError: Failed to import test module: pretty_isds Traceback (most recent call last): File "/usr/lib64/python3.6/unittest/loader.py", line 462, in _find_test_path package = self._get_module_from_name(name) File "/usr/lib64/python3.6/unittest/loader.py", line 369, in _get_module_from_name __import__(name) File "/home/karel/git_repos/libisds-python/test/pretty_isds/__init__.py", line 24, in <module> from dataclasses import dataclass ModuleNotFoundError: No module named 'dataclasses' ---------------------------------------------------------------------- Ran 118 tests in 0.013s FAILED (errors=1)
Fedora + python-2.7:
PYTHONPATH=.:.libs /usr/bin/python2.7 -m unittest discover test EEEEEEEEEEEEEE ====================================================================== ERROR: test_isds_db_owner_info_test (unittest.loader.ModuleImportFailure) ---------------------------------------------------------------------- ImportError: Failed to import test module: test_isds_db_owner_info_test Traceback (most recent call last): File "/usr/lib64/python2.7/unittest/loader.py", line 254, in _find_tests module = self._get_module_from_name(name) File "/usr/lib64/python2.7/unittest/loader.py", line 232, in _get_module_from_name __import__(name) File "/home/karel/git_repos/libisds-python/test/test_isds_db_owner_info_test.py", line 7, in <module> import isds File "/home/karel/git_repos/libisds-python/test/isds/__init__.py", line 953 SyntaxError: Non-ASCII character '\xc4' in file /home/karel/git_repos/libisds-python/test/isds/__init__.py on line 954, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details ====================================================================== ERROR: test_isds_address_test (unittest.loader.ModuleImportFailure) ---------------------------------------------------------------------- ImportError: Failed to import test module: test_isds_address_test Traceback (most recent call last): File "/usr/lib64/python2.7/unittest/loader.py", line 254, in _find_tests module = self._get_module_from_name(name) File "/usr/lib64/python2.7/unittest/loader.py", line 232, in _get_module_from_name __import__(name) File "/home/karel/git_repos/libisds-python/test/test_isds_address_test.py", line 11, in <module> ad = isds.isds_address() AttributeError: 'module' object has no attribute 'isds_address' ====================================================================== ERROR: test_isds_db_user_info_test (unittest.loader.ModuleImportFailure) ---------------------------------------------------------------------- ImportError: Failed to import test module: test_isds_db_user_info_test Traceback (most recent call last): File "/usr/lib64/python2.7/unittest/loader.py", line 254, in _find_tests module = self._get_module_from_name(name) File "/usr/lib64/python2.7/unittest/loader.py", line 232, in _get_module_from_name __import__(name) File "/home/karel/git_repos/libisds-python/test/test_isds_db_user_info_test.py", line 11, in <module> ui = isds.isds_db_user_info() AttributeError: 'module' object has no attribute 'isds_db_user_info' ... ====================================================================== ERROR: test_isds_envelope_test (unittest.loader.ModuleImportFailure) ---------------------------------------------------------------------- ImportError: Failed to import test module: test_isds_envelope_test Traceback (most recent call last): File "/usr/lib64/python2.7/unittest/loader.py", line 254, in _find_tests module = self._get_module_from_name(name) File "/usr/lib64/python2.7/unittest/loader.py", line 232, in _get_module_from_name __import__(name) File "/home/karel/git_repos/libisds-python/test/test_isds_envelope_test.py", line 11, in <module> env = isds.isds_envelope() AttributeError: 'module' object has no attribute 'isds_envelope' ---------------------------------------------------------------------- Ran 14 tests in 0.001s FAILED (errors=14)
Fedora + python-3.7:
PYTHONPATH=.:.libs /usr/bin/python3.7 -m unittest discover test ..................................................................................................................... ---------------------------------------------------------------------- Ran 117 tests in 0.008s OK
Edited by Karel Slaný152 152 # Wrapper code generated by SWIG 4 expects _isds.so to be located in same 153 153 # place as __init__.py . 154 154 test: _isds.la 155 rm -rf test/isds test/_isds.so 156 cd test && mkdir isds && ln -s ../../isds.py isds/__init__.py && ln -s ../.libs/_isds.so _isds.so 157 cd test/isds && ln -s ../_isds.so _isds.so 158 rm -rf test/pretty_isds 159 cd test && mkdir pretty_isds && ln -s ../../pretty_isds.py pretty_isds/__init__.py 160 cd test && PYTHON=$(PYTHON) ./test_all.sh I would rather use the old construction rather than the new fancy stuff:
- SWIG-4 tends to generate somewhat different code. One of the consequences is that
isds.py
searches for_isds.so
in slightly different locations when created with SWIG-3 and SWIG-4 - I use ./test_all.sh to also run the test manually from within the
make te
environment. This is especially useful when writing new tests when you don't wan to run all the test.
What should be the benefits of using
PYTHONPATH=.:.libs $(PYTHON) -m unittest discover test
?- SWIG-4 tends to generate somewhat different code. One of the consequences is that
Ad 1: There indeed is a somewhat obscure code to import
_isds.so
. Can you provide more details/a snippet o differences between SWIG-3 a 4?Ad 2: I'd like all tests to be wrapped in
tox
environment.This is especially useful when writing new tests when you don't wan to run all the test.
There's a standard command for that
PYTHONPATH=.:.libs python -m unittest test.test_new_stuff
What should be the benefits of using...
As noted above: a possibility to integrate test in tox & standard testing of partial tests. Also the old construction doesn't seem to correspond to the actually installed code, e.g. in
python3-libisds
theisds
is a module, not a package.Edited by Vlastimil Zima
Weird. Anyway, I don't seem to have
test/pretty_isds/__init__.py
, which triggers error on Gentoo/P3.6.Edit: Found it. But it shouldn't be linked in P3.6, should it?
Edited by Vlastimil ZimaFedora+python2.7 boils down to:
PYTHONPATH=.:.libs /usr/bin/python2.7 -m unittest discover test EEEEEEEEEEEEEE ====================================================================== ERROR: test_isds_db_owner_info_test (unittest.loader.ModuleImportFailure) ---------------------------------------------------------------------- ImportError: Failed to import test module: test_isds_db_owner_info_test Traceback (most recent call last): File "/usr/lib64/python2.7/unittest/loader.py", line 254, in _find_tests module = self._get_module_from_name(name) File "/usr/lib64/python2.7/unittest/loader.py", line 232, in _get_module_from_name __import__(name) File "/home/karel/git_repos/libisds-python/test/test_isds_db_owner_info_test.py", line 7, in <module> import isds File "isds.py", line 956 SyntaxError: Non-ASCII character '\xc4' in file isds.py on line 957, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
The problem boils down to PEP 236. SWIG does not write encoding information into the generated Python code. When I manually add
# -*- coding: utf-8 -*-
at the beginning ofisds.py
then the tests pass.I'm going to modify
Makefile.in
to add the line manually.Edited by Karel Slaný
added 1 commit
- 136d00dd - Fixed failing tests on Fedora with python-2.7.
Looks that it now passes my basic test environments. Going to build in OBS whether the test pass there.
mentioned in commit 7e74e6bc
changed milestone to %0.0.0