Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not clear how to run tests #108

Open
Viech opened this issue Oct 21, 2024 · 5 comments
Open

Not clear how to run tests #108

Viech opened this issue Oct 21, 2024 · 5 comments

Comments

@Viech
Copy link
Contributor

Viech commented Oct 21, 2024

Running just nosetests after python setup.py build fails:

% nosetests
EE
======================================================================
ERROR: Failure: ImportError (cannot import name '_swiglpk' from 'swiglpk' (/home/viech/src/swiglpk/swiglpk/__init__.py))
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/usr/lib/python3.12/site-packages/nose/loader.py", line 416, in loadTestsFromName
    module = self.importer.importFromPath(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/nose/importer.py", line 162, in importFromPath
    return self.importFromDir(dir_path, fqname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/nose/importer.py", line 209, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/nose/importer.py", line 117, in load_module
    return load_package(name, filename)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/nose/importer.py", line 71, in load_package
    spec.loader.exec_module(sys.modules[name])
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/home/viech/src/swiglpk/swiglpk/__init__.py", line 1, in <module>
    from .swiglpk import *
  File "/home/viech/src/swiglpk/swiglpk/swiglpk.py", line 10, in <module>
    from . import _swiglpk
ImportError: cannot import name '_swiglpk' from 'swiglpk' (/home/viech/src/swiglpk/swiglpk/__init__.py)

======================================================================
ERROR: test_swiglpk (test_swiglpk.TestSwiglpk.test_swiglpk)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/viech/src/swiglpk/test_swiglpk.py", line 24, in test_swiglpk
    print(glp_version())
          ^^^^^^^^^^^
NameError: name 'glp_version' is not defined

----------------------------------------------------------------------
Ran 2 tests in 0.004s

FAILED (errors=2)

So does the following attempt using PYTHONPATH:

% echo $python_path
/home/viech/src/swiglpk/build/lib.linux-x86_64-cpython-312

% ls $python_path/swiglpk
glpk.i  swiglpk.py  _swiglpk.cpython-312-x86_64-linux-gnu.so  __init__.py

% PYTHONPATH=$python_path nosetests
[exact same error]

The same goes for python -m unittest:

% python -m unittest
EE
======================================================================
ERROR: swiglpk (unittest.loader._FailedTest.swiglpk)
----------------------------------------------------------------------
ImportError: Failed to import test module: swiglpk
Traceback (most recent call last):
  File "/usr/lib/python3.12/unittest/loader.py", line 429, in _find_test_path
    package = self._get_module_from_name(name)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/unittest/loader.py", line 339, in _get_module_from_name
    __import__(name)
  File "/home/viech/src/swiglpk/swiglpk/__init__.py", line 1, in <module>
    from .swiglpk import *
  File "/home/viech/src/swiglpk/swiglpk/swiglpk.py", line 10, in <module>
    from . import _swiglpk
ImportError: cannot import name '_swiglpk' from partially initialized module 'swiglpk' (most likely due to a circular import) (/home/viech/src/swiglpk/swiglpk/__init__.py)


======================================================================
ERROR: test_swiglpk (unittest.loader._FailedTest.test_swiglpk)
----------------------------------------------------------------------
ImportError: Failed to import test module: test_swiglpk
Traceback (most recent call last):
  File "/usr/lib/python3.12/unittest/loader.py", line 396, in _find_test_path
    module = self._get_module_from_name(name)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/unittest/loader.py", line 339, in _get_module_from_name
    __import__(name)
  File "/home/viech/src/swiglpk/test_swiglpk.py", line 17, in <module>
    from swiglpk import *
  File "/home/viech/src/swiglpk/swiglpk/__init__.py", line 1, in <module>
    from .swiglpk import *
  File "/home/viech/src/swiglpk/swiglpk/swiglpk.py", line 10, in <module>
    from . import _swiglpk
ImportError: cannot import name '_swiglpk' from partially initialized module 'swiglpk' (most likely due to a circular import) (/home/viech/src/swiglpk/swiglpk/__init__.py)


----------------------------------------------------------------------
Ran 2 tests in 0.000s

FAILED (errors=2)

Again with PYTHONPATH:

% PYTHONPATH=$python_path python -m unittest
[exact same error]

What is the intended way to run the tests?

@Midnighter
Copy link
Member

I'm on my phone right now, but you can look at the workflow definition to see how the tests are run there.

@Midnighter
Copy link
Member

Alright, I had a chance to check the workflows myself. We actually do not run any tests, we only build the wheels. I guess, the reason being that GLPK itself is tested and this is a very thin wrapper around it. Additionally, we do use this package for the tests in optlang, so we would notice breaks there.

Not ideal, but also not terrible. If you feel like it, you are welcome to contribute tests.

@Viech
Copy link
Contributor Author

Viech commented Oct 22, 2024

I was explicitly asked by a repository maintainer to run existing tests within my Arch User Repository package. They probably saw the test_swiglpk.py file or the reference to nosetests in tox.ini.

So I don't personally need a testbench; this issue is just about the fact that existing tests do not seem to be functioning.

@Midnighter
Copy link
Member

@cdiener any ideas? I can't prioritise fixing the tests at the moment.

@cdiener
Copy link
Member

cdiener commented Nov 20, 2024

Yeah, the tests are ancient and are not used in the CI at the moment. The reason is that we basically test the swigplk API with the optlang and cobrapy tests which are already really comprehensive. Not really clean, but nobody ever updated the tests here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants