opencobra / swiglpk

Simple swig bindings for the GNU Linear Programming Kit
GNU General Public License v3.0
28 stars 10 forks source link

Not clear how to run tests #108

Open Viech opened 1 day ago

Viech commented 1 day ago

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 commented 1 day ago

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

Midnighter commented 22 hours ago

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 commented 5 hours ago

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 commented 5 hours ago

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