Nose is obsolete
Describe the bug
The tutorial at https://amuse.readthedocs.io/en/latest/tutorial/c_code.html guides the user to run the tests for the package using nosetests. This command is from the nose package, which is unmaintained and obsolete and doesn't work on recent Python versions. It's been succeeded by nose2, which at least for the trivial example tests seems to do work.
To Reproduce
amusifier --type=c --mode=dir NearestNeighbor
cd nearestneighbor
make
pip install nose
nosetests
Expected behavior
.
----------------------------------------------------------------------
Ran 1 test in 0.648s
OK
Logs
Traceback (most recent call last):
File "/home/lourens/NLeSC/projects/ReDiTSAp/software/Amuse-env/bin/nosetests", line 8, in <module>
sys.exit(run_exit())
File "/home/lourens/NLeSC/projects/ReDiTSAp/software/Amuse-env/lib/python3.10/site-packages/nose/core.py", line 118, in __init__
unittest.TestProgram.__init__(
File "/usr/lib/python3.10/unittest/main.py", line 100, in __init__
self.parseArgs(argv)
File "/home/lourens/NLeSC/projects/ReDiTSAp/software/Amuse-env/lib/python3.10/site-packages/nose/core.py", line 179, in parseArgs
self.createTests()
File "/home/lourens/NLeSC/projects/ReDiTSAp/software/Amuse-env/lib/python3.10/site-packages/nose/core.py", line 193, in createTests
self.test = self.testLoader.loadTestsFromNames(self.testNames)
File "/home/lourens/NLeSC/projects/ReDiTSAp/software/Amuse-env/lib/python3.10/site-packages/nose/loader.py", line 481, in loadTestsFromNames
return unittest.TestLoader.loadTestsFromNames(self, names, module)
File "/usr/lib/python3.10/unittest/loader.py", line 220, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "/usr/lib/python3.10/unittest/loader.py", line 220, in <listcomp>
suites = [self.loadTestsFromName(name, module) for name in names]
File "/home/lourens/NLeSC/projects/ReDiTSAp/software/Amuse-env/lib/python3.10/site-packages/nose/loader.py", line 431, in loadTestsFromName
return self.loadTestsFromModule(
File "/home/lourens/NLeSC/projects/ReDiTSAp/software/Amuse-env/lib/python3.10/site-packages/nose/loader.py", line 354, in loadTestsFromModule
tests.extend(self.loadTestsFromDir(module_path))
File "/home/lourens/NLeSC/projects/ReDiTSAp/software/Amuse-env/lib/python3.10/site-packages/nose/loader.py", line 195, in loadTestsFromDir
yield self.suiteClass(
File "/home/lourens/NLeSC/projects/ReDiTSAp/software/Amuse-env/lib/python3.10/site-packages/nose/suite.py", line 423, in __call__
tests = self.wrapTests(tests)
File "/home/lourens/NLeSC/projects/ReDiTSAp/software/Amuse-env/lib/python3.10/site-packages/nose/suite.py", line 541, in wrapTests
if isinstance(tests, collections.Callable) or isinstance(tests, unittest.TestSuite):
AttributeError: module 'collections' has no attribute 'Callable'
Environment (please complete the following information): Kubuntu 22.04 GCC 11.4.0
Additional context This works at least for this trivial test:
pip uninstall nosetests
pip install nose2
nose2
We've actually retired nose for testing in favour of pytest, but clearly this change hasn't propagated to all the documentation yet.
see #196
Ah, I can confirm that pytest also seems to run the tests, so it's indeed just a documentation issue. Farther down it suggests running pysetest, which I guess is some weird hybrid of the two :smile:.
I might as well add another issue about the same page here: the test doesn't work because instance.find_nearest_neighbors(x,y,z) returns only 3 values, not the n0, n1, n2, error we are expecting. Possibly the API changed?
If I remove those checks, then it still fails, because of an off-by-one indexing error. It seems like the test expects the indexes returned in n0 to be 1-based, while the C++ code returns 0-based indexes. I guess this was copy-pasted from the Fortran side maybe? Does AMUSE have a standard for whether indexes are 0- or 1-based?
In interface.py I need to write
def define_methods(self, handler):
handler.add_method(
"find_nearest_neighbors",
(
generic_unit_system.length,
generic_unit_system.length,
generic_unit_system.length
),
(
handler.INDEX,
handler.INDEX,
handler.INDEX
)
)
without the additional handler.ERROR_CODE to get test3 to work. I'm not sure however if error handling has been automated completely and manually declaring that output is no longer necessary, or if removing it disables error handling.
Oh, and the test file needs a from amuse.units import generic_unit_system to get that symbol to resolve.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 28 days if no further activity occurs. Thank you for your contributions.
Let's keep this open and consider it a documentation issue. I've been working on getting tests to run in combination with the new packaging work, so that's a separate thing, and then there's another potential separate project in removing the custom infrastructure from the tests and use the facilities that pytest offers. I've made #1044 for the latter.
Ah, thanks. I guess you need to remove stale to keep it from closing, and add keep-open to keep it from getting marked as stale?
Yes I guess so…