pyTooling / pyTooling

pyTooling is a collection of arbitrary useful classes, decorators, meta-classes and exceptions.
https://pytooling.github.io/pyTooling/
Other
7 stars 1 forks source link

treelib and igraph are missing from tests/requirements.txt #90

Closed yurivict closed 1 month ago

yurivict commented 1 year ago

They are used in tests:

__________________________________________________________________________ ERROR collecting tests/performance/Graph/igraph.py ___________________________________________________________________________
ImportError while importing test module '/usr/ports/devel/py-pyTooling/work-py39/pyTooling-4.0.1/tests/performance/Graph/igraph.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
performance/Graph/igraph.py:34: in <module>
    from igraph import Graph as iGraph
E   ModuleNotFoundError: No module named 'igraph'
__________________________________________________________________________ ERROR collecting tests/performance/Tree/TreeLib.py ___________________________________________________________________________
ImportError while importing test module '/usr/ports/devel/py-pyTooling/work-py39/pyTooling-4.0.1/tests/performance/Tree/TreeLib.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
performance/Tree/TreeLib.py:32: in <module>
    from treelib import Tree as treelib_Tree
E   ModuleNotFoundError: No module named 'treelib'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=========================================================================================== 2 errors in 5.05s ===========================================================================================
Paebbels commented 1 year ago

How are you running the tests?

Performance tests are a bit special and normally not run by users. I added these additional requirements in tests/performance/requirements.txt. If you install that requirements file, it will recursively take care of others.

But I can rethink my current solution.

yurivict commented 1 year ago

It runs pytests.

This is for the 'test' command in the FreeBSD port.

It's ok if you think that there's no problem then. I didn't see the tests/performance/requirements.txt file.

Paebbels commented 1 year ago

For functionality, normal unit tests are enough. Performance tests (and benchmark tests) are just to compare my implementation to other implementations.

For the tree I'm faster. For graphs, others are faster, but the don't offer a clean API. The performance tests are for me to also see that my code doesn't degrade and to compare the code on different Python versions. Python is getting slightly faster over time.

Paebbels commented 1 year ago

The CI jobs will show you 4 testing jobs:

Here you also see the modified requirements file and the changed test directory.

It would be interesting to have a FreeBSD platform test. That's not covered yet. The macOS test could maybe serve as an example: https://github.com/pyTooling/pyTooling/blob/main/tests/unit/Common/Platform.py?ts=2#L77

A ENVIRONMENT_NAME environment variable needs to be set. This variable is generated in CI by this job: https://github.com/pyTooling/Actions/blob/dev/.github/workflows/Parameters.yml#L161

Paebbels commented 1 year ago

@yurivict anything else I try to help in supporting FreeBSD?

yurivict commented 1 year ago

anything else I try to help in supporting FreeBSD?

Thank you very much for your help!

2 tests fail on FreeBSD:

=============================================================================================== FAILURES ================================================================================================
__________________________________________________________________________________ RandomGraph.test_ShortestPathByHops __________________________________________________________________________________

self = <tests.performance.Graph.igraph.RandomGraph testMethod=test_ShortestPathByHops>

    def test_ShortestPathByHops(self):
        def wrapper(graph: iGraph, componentStartVertex: int, componentSize: int):
            def func():
                try:
                    vertexPath = graph.distances(49, 20)
                except KeyError:
                    pass

                # print(f"path length: {len(vertexPath)}")
                # self.assertEqual(6, len(vertexPath))

            return func

>       self.runFileBasedTests(self.ConstructGraphFromEdgeListFile, wrapper, self.edgeFiles)

performance/Graph/igraph.py:126: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
performance/Graph/__init__.py:104: in runFileBasedTests
    results = timeit.repeat(func(graph, edgeFile.biggestNetwork.startNodeID, edgeFile.biggestNetwork.size), repeat=20, number=50)
/usr/local/lib/python3.9/timeit.py:238: in repeat
    return Timer(stmt, setup, timer, globals).repeat(repeat, number)
/usr/local/lib/python3.9/timeit.py:205: in repeat
    t = self.timeit(number)
/usr/local/lib/python3.9/timeit.py:177: in timeit
    timing = self.inner(it, self.timer)
<timeit-src>:6: in inner
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def func():
        try:
>           vertexPath = graph.distances(49, 20)
E     AttributeError: 'Graph' object has no attribute 'distances'

performance/Graph/igraph.py:117: AttributeError
----------------------------------------------------------------------------------------- Captured stdout call ------------------------------------------------------------------------------------------

         min           mean          median        max           construct
_________________________________________________________________________________ RandomGraph.test_ShortestPathByWeight _________________________________________________________________________________

self = <tests.performance.Graph.igraph.RandomGraph testMethod=test_ShortestPathByWeight>

    def test_ShortestPathByWeight(self):
        def wrapper(graph: iGraph, componentStartVertex: int, componentSize: int):
            def func():
                try:
                    vertexPath = graph.distances(49, 20, "weight")
                except KeyError:
                    pass

                # print(f"path length: {len(vertexPath)}")
                # self.assertEqual(6, len(vertexPath))

            return func

>       self.runFileBasedTests(self.ConstructGraphFromEdgeListFile, wrapper, self.edgeFiles)

performance/Graph/igraph.py:141: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
performance/Graph/__init__.py:104: in runFileBasedTests
    results = timeit.repeat(func(graph, edgeFile.biggestNetwork.startNodeID, edgeFile.biggestNetwork.size), repeat=20, number=50)
/usr/local/lib/python3.9/timeit.py:238: in repeat
    return Timer(stmt, setup, timer, globals).repeat(repeat, number)
/usr/local/lib/python3.9/timeit.py:205: in repeat
    t = self.timeit(number)
/usr/local/lib/python3.9/timeit.py:177: in timeit
    timing = self.inner(it, self.timer)
<timeit-src>:6: in inner
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def func():
        try:
>           vertexPath = graph.distances(49, 20, "weight")
E     AttributeError: 'Graph' object has no attribute 'distances'

performance/Graph/igraph.py:132: AttributeError
----------------------------------------------------------------------------------------- Captured stdout call ------------------------------------------------------------------------------------------

         min           mean          median        max           construct
=========================================================================================== warnings summary ============================================================================================
tests/unit/Packaging/__init__.py::HelperFunctions::test_loadReadmeMD
  /usr/local/lib/python3.9/site-packages/_distutils_hack/__init__.py:18: UserWarning: Distutils was imported before Setuptools, but importing Setuptools also replaces the `distutils` module in `sys.modules`. This may lead to undesirable behaviors or errors. To avoid these issues, avoid using distutils directly, ensure that setuptools is installed in the traditional way (e.g. not an editable install), and/or make sure that setuptools is always imported before distutils.
    warnings.warn(

tests/unit/Packaging/__init__.py::HelperFunctions::test_loadReadmeMD
  /usr/local/lib/python3.9/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils.
    warnings.warn("Setuptools is replacing distutils.")

tests/unit/Graph/__init__.py::Names::test_Graph_WrongName
  /usr/local/lib/python3.9/site-packages/_pytest/unraisableexception.py:78: PytestUnraisableExceptionWarning: Exception ignored in: <function Graph.__del__ at 0x8e25f71f0>

  TypeError: Parameter 'name' is not of type 'str'.

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "/usr/ports/devel/py-pyTooling/work-py39/pyTooling-4.0.1/pyTooling/Graph/__init__.py", line 2160, in __del__
      super().__del__()
    File "/usr/ports/devel/py-pyTooling/work-py39/pyTooling-4.0.1/pyTooling/Graph/__init__.py", line 1563, in __del__
      super().__del__()
    File "/usr/ports/devel/py-pyTooling/work-py39/pyTooling-4.0.1/pyTooling/Graph/__init__.py", line 216, in __del__
      del self._dict
  AttributeError: _dict

    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))

tests/unit/Graph/__init__.py::Construction::test_StandaloneLink
tests/unit/Graph/__init__.py::Construction::test_StandaloneEdge
  /usr/local/lib/python3.9/site-packages/_pytest/unraisableexception.py:78: PytestUnraisableExceptionWarning: Exception ignored in: <function Base.__del__ at 0x8e357edc0>

  pyTooling.Graph.NotInSameGraph: Source vertex and destination vertex are not in same graph.

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "/usr/ports/devel/py-pyTooling/work-py39/pyTooling-4.0.1/pyTooling/Graph/__init__.py", line 216, in __del__
      del self._dict
  AttributeError: _dict

    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

-------------------------------------------------------------------- benchmark 'Accumulate 10 integer slots': 2 tests --------------------------------------------------------------------
Name (time in ms)                Min               Max              Mean            StdDev            Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_SlottedAccumulate_10     1.3444 (1.0)      2.6135 (1.0)      1.4677 (1.0)      0.2413 (1.0)      1.3585 (1.0)      0.0949 (1.0)        83;109  681.3257 (1.0)         721           1
test_Accumulate_10            1.9990 (1.49)     3.7893 (1.45)     2.2606 (1.54)     0.4347 (1.80)     2.0540 (1.51)     0.1286 (1.35)        75;97  442.3661 (0.65)        470           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------- benchmark 'Accumulate a single integer slot': 2 tests --------------------------------------------------------------------------
Name (time in us)                 Min                    Max                Mean              StdDev              Median                IQR            Outliers  OPS (Kops/s)            Rounds  Iterations
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_SlottedAccumulate_1     295.4100 (1.0)       1,009.5220 (1.0)      330.8213 (1.0)       81.4489 (1.0)      298.8160 (1.0)       8.9050 (1.0)       233;313        3.0228 (1.0)        1894           1
test_Accumulate_1            376.5790 (1.27)     47,549.1270 (47.10)    445.7029 (1.35)     954.9959 (11.73)    381.4750 (1.28)     15.3000 (1.72)        2;430        2.2436 (0.74)       2469           1
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------- benchmark 'Create Objects with 1 slot': 2 tests --------------------------------------------------------------------------------
Name (time in us)                    Min                     Max                Mean                StdDev              Median                IQR            Outliers  OPS (Kops/s)            Rounds  Iterations
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_CreateSlottedObjects_1     431.1100 (1.0)       55,900.1480 (1.0)      600.8969 (1.0)      2,350.5500 (1.0)      446.1820 (1.0)      17.1067 (1.0)         4;318        1.6642 (1.0)        1937           1
test_CreateObjects_1            566.1580 (1.31)     114,446.9750 (2.05)     883.5578 (1.47)     4,169.9006 (1.77)     594.5795 (1.33)     27.5205 (1.61)        4;189        1.1318 (0.68)       1220           1
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------- benchmark 'Create Objects with 10 slots': 2 tests ---------------------------------------------------------------------------------
Name (time in us)                       Min                    Max                  Mean                StdDev                Median                 IQR            Outliers       OPS            Rounds  Iterations
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_CreateSlottedObjects_10       973.1970 (1.0)      55,448.2630 (1.04)     1,167.9045 (1.0)      2,390.4779 (1.0)        985.2590 (1.0)       24.1813 (1.0)         2;154  856.2344 (1.0)         963           1
test_CreateObjects_10            1,355.6740 (1.39)     53,293.3130 (1.0)      1,794.3515 (1.54)     3,401.1983 (1.42)     1,384.5260 (1.41)     134.4557 (5.56)        3;121  557.3044 (0.65)        661           1
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Legend:
  Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
  OPS: Operations Per Second, computed as 1 / Mean
======================================================================================== short test summary info ========================================================================================
SKIPPED [1] unit/Common/Platform.py:189: Skipped 'test_UCRT64' when environment variable 'ENVIRONMENT_NAME' doesn't match. skip
SKIPPED [1] unit/Common/Platform.py:100: Skipped 'test_NativeWindows' when environment variable 'ENVIRONMENT_NAME' doesn't match. skip
SKIPPED [1] unit/Common/Platform.py:211: Skipped 'test_Clang32' when environment variable 'ENVIRONMENT_NAME' doesn't match. skip
SKIPPED [1] unit/Common/Platform.py:233: Skipped 'test_Clang64' when environment variable 'ENVIRONMENT_NAME' doesn't match. skip
SKIPPED [1] unit/Common/Platform.py:167: Skipped 'test_MinGW64' when environment variable 'ENVIRONMENT_NAME' doesn't match. skip
SKIPPED [1] unit/Common/Platform.py:123: Skipped 'test_MSYS' when environment variable 'ENVIRONMENT_NAME' doesn't match. skip
SKIPPED [1] unit/Common/Platform.py:54: Skipped 'test_NativeLinux' when environment variable 'ENVIRONMENT_NAME' doesn't match. skip
SKIPPED [1] unit/Common/Platform.py:48: Skipped when environment variable 'ENVIRONMENT_NAME' isn't set.
SKIPPED [1] unit/Common/Platform.py:145: Skipped 'test_MinGW32' when environment variable 'ENVIRONMENT_NAME' doesn't match. skip
SKIPPED [1] unit/Common/Platform.py:77: Skipped 'test_NativeMacOS' when environment variable 'ENVIRONMENT_NAME' doesn't match. skip
SKIPPED [1] unit/Tree/__init__.py:354: Not yet implemented!
SKIPPED [1] unit/Tree/__init__.py:294: Not yet implemented!
============================================================= 2 failed, 282 passed, 12 skipped, 1 xfailed, 5 warnings in 2942.16s (0:49:02) =============================================================
*** Error code 1
Paebbels commented 1 year ago

igraph is missing a property distance. What igraph version do you have?

yurivict commented 1 year ago

I have py39-python-igraph-0.9.9_3 which is old. This is likely the problem.

Paebbels commented 10 months ago

@yurivict is there anything to do from my side for this issue or can we close it?

Paebbels commented 1 month ago

Subsumed by #123.