tahiri-lab / aPhyloGeo

aPhyloGeo is a multiplatform application for the analysis of genetic and climatic conditions.
https://pypi.org/project/aphylogeo/
GNU General Public License v3.0
10 stars 6 forks source link

Failed Unit Tests #56

Open mmore500 opened 1 month ago

mmore500 commented 1 month ago

Describe the bug A clear and concise description of what the bug is.

Three tests fail when run on my local machine. Two appear to be due to floating point rounding issues. They are probably fixable by using more robust floating point comparisons. A third appears to be some other issue. The third failure is reproducible on google cloud shell https://shell.cloud.google.com.

============================= test session starts ==============================
platform linux -- Python 3.12.4, pytest-7.4.4, pluggy-1.5.0
rootdir: /home/mmore500/2024-08-05/aPhyloGeo
configfile: pyproject.toml
collected 16 items

tests/test_climatic.py ...F.F                                            [ 37%]
tests/test_genetic.py .....F....                                         [100%]

=================================== FAILURES ===================================
_______________________________ test_leastSquare _______________________________

    def test_leastSquare():
        """
        This test is used to test the Least Square distance calculation function.
        It contains the following tests:
            - leastSquare
        """

        print("Begin test_leastSquare...")

        for test_case in climatic_test_cases:
            curent_dir = Path(dir / test_case)
            trees = {}
            for filename in os.listdir(curent_dir):
                if filename.endswith(".csv"):
                    filename_without_ext = filename[0:-4]
                    actual_matrix = utils.getDissimilaritiesMatrix(df, "id", filename_without_ext)
                    trees[filename_without_ext] = utils.createTree(actual_matrix)

            expected_ls_file_csv = Path(current_file / "testFiles/leastSquare" / test_case / "leastsquare.csv")
            for tree1 in trees:
                for tree2 in trees:
                    if tree1 != tree2:
                        with open(expected_ls_file_csv, 'r', newline='') as csvfile:
                            csv_reader = csv.reader(csvfile)
                            # Read each row in the CSV file
                            for row in csv_reader:
                                if row[0] == tree1 and row[1] == tree2:
                                    # test leastSquare
                                    # expected_least_square = 2.1550089999999997
>                                   assert utils.leastSquare(trees[tree1], trees[tree2]) == float(row[2])
E                                   AssertionError: assert 2.862019083333333 == 2.8620190833333337
E                                    +  where 2.862019083333333 = <function leastSquare at 0x7fdbd357c400>(Tree(rooted=False), Tree(rooted=False))
E                                    +    where <function leastSquare at 0x7fdbd357c400> = utils.leastSquare
E                                    +  and   2.8620190833333337 = float('2.8620190833333337')

tests/test_climatic.py:132: AssertionError
----------------------------- Captured stdout call -----------------------------
Begin test_leastSquare...
______________________________ test_euclideanDist ______________________________

    def test_euclideanDist():
        """
        This test is used to test the Euclidean Bipartion distance calculation function.
        It contains the following tests:
            - euclideanDist
        """

        print("Begin test_euclideanDist...")

        for test_case in climatic_test_cases:
            curent_dir = Path(dir / test_case)
            trees = {}
            for filename in os.listdir(curent_dir):
                if filename.endswith(".csv"):
                    filename_without_ext = filename[0:-4]
                    actual_matrix = utils.getDissimilaritiesMatrix(df, "id", filename_without_ext)
                    trees[filename_without_ext] = utils.createTree(actual_matrix)

            expected_eu_file_csv = Path(current_file / "testFiles/euclideanDist" / test_case / "euclideandist.csv")
            for tree1 in trees:
                for tree2 in trees:
                    if tree1 != tree2:
                        with open(expected_eu_file_csv, 'r', newline='') as csvfile:
                            csv_reader = csv.reader(csvfile)
                            # Read each row in the CSV file
                            for row in csv_reader:
                                if row[0] == tree1 and row[1] == tree2:
                                    # test Euclidean
>                                   assert utils.euclideanDist(trees[tree1], trees[tree2]) == float(row[2])
E                                   AssertionError: assert 0.9220415367541747 == 0.9220415367541746
E                                    +  where 0.9220415367541747 = <function euclideanDist at 0x7fdbd3515300>(Tree(rooted=False), Tree(rooted=False))
E                                    +    where <function euclideanDist at 0x7fdbd3515300> = utils.euclideanDist
E                                    +  and   0.9220415367541746 = float('0.9220415367541746')

tests/test_climatic.py:196: AssertionError
----------------------------- Captured stdout call -----------------------------
Begin test_euclideanDist...
________________________ TestGenetic.test_filterResults ________________________

self = <tests.test_genetic.TestGenetic object at 0x7fdbd33de390>

    def test_filterResults(self):
        """
        This test is used to test the filterResults function.
        """

        # Test the createBootstrap function
        genetic_trees = utils.createBoostrap(self.msa, Params.bootstrap_amount)
        actual_bootstrap = [str(Phylogeny.from_tree(tree)) for tree in list(genetic_trees.values())]

        trees = Phylo.parse("tests/testFiles/createBootstrap/seq very small.xml", "phyloxml")
        expected_bootstrap = [str(tree) for tree in trees]

        for tree in actual_bootstrap:
>           assert tree in expected_bootstrap
E           assert "Phylogeny(rooted=True)\n    Clade()\n        Clade(branch_length=0.12060301507537685, name='OL989074')\n        Clade...\n                Clade(branch_length=0.0, name='OU471040')\n                Clade(branch_length=0.0, name='ON129429')" in ["Phylogeny(rooted=True)\n    Clade()\n        Clade(branch_length=0.0, name='OL989074')\n        Clade(branch_length=...n                Clade(branch_length=0.0, name='OU471040')\n                Clade(branch_length=0.0, name='ON129429')"]

tests/test_genetic.py:136: AssertionError
----------------------------- Captured stdout call -----------------------------
Creating bootstrap variations with multiplyer of :  100
---
Started:           3 / 5     60 %           
Finished:          0 / 3     0 %           
Time elapsed:      0.1  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      0.2  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      0.3  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      0.4  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      0.5  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      0.6  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      0.7  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      0.8  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      1.0  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      1.1  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      1.2  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      1.3  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      1.4  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      1.5  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      1.6  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      1.7  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      1.8  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      1.9  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      2.0  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      2.1  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      2.2  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      2.3  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      2.4  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      2.5  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      2.6  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      2.7  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          0 / 5     0 %           
Time elapsed:      2.8  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          1 / 5     20 %           
Time elapsed:      2.9  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          1 / 5     20 %           
Time elapsed:      3.0  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          2 / 5     40 %           
Time elapsed:      3.1  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          2 / 5     40 %           
Time elapsed:      3.2  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          3 / 5     60 %           
Time elapsed:      3.3  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          3 / 5     60 %           
Time elapsed:      3.4  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          3 / 5     60 %           
Time elapsed:      3.5  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          4 / 5     80 %           
Time elapsed:      3.6  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          4 / 5     80 %           
Time elapsed:      3.7  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          4 / 5     80 %           
Time elapsed:      3.8  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          5 / 5     100 %           
Time elapsed:      3.9  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          5 / 5     100 %           
Time elapsed:      4.0  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          5 / 5     100 %           
Time elapsed:      4.1  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          5 / 5     100 %           
Time elapsed:      4.2  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          5 / 5     100 %           
Time elapsed:      4.3  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          5 / 5     100 %           
Time elapsed:      4.4  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          5 / 5     100 %           
Time elapsed:      4.5  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          5 / 5     100 %           
Time elapsed:      4.6  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          5 / 5     100 %           
Time elapsed:      4.7  seconds               
---


---
Started:           5 / 5     100 %           
Finished:          5 / 5     100 %           
Time elapsed:      4.8  seconds               
---




Completed  5 tasks in  5.0 seconds
=============================== warnings summary ===============================
../env/lib64/python3.12/site-packages/ete3/webplugin/webapp.py:44
  /home/mmore500/2024-08-05/env/lib64/python3.12/site-packages/ete3/webplugin/webapp.py:44: DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13
    import cgi

../env/lib64/python3.12/site-packages/Bio/Application/__init__.py:39
  /home/mmore500/2024-08-05/env/lib64/python3.12/site-packages/Bio/Application/__init__.py:39: BiopythonDeprecationWarning: The Bio.Application modules and modules relying on it have been deprecated.

  Due to the on going maintenance burden of keeping command line application
  wrappers up to date, we have decided to deprecate and eventually remove these
  modules.

  We instead now recommend building your command line and invoking it directly
  with the subprocess module.
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED tests/test_climatic.py::test_leastSquare - AssertionError: assert 2.86...
FAILED tests/test_climatic.py::test_euclideanDist - AssertionError: assert 0....
FAILED tests/test_genetic.py::TestGenetic::test_filterResults - assert "Phylo...
================== 3 failed, 13 passed, 2 warnings in 14.60s ===================

To Reproduce

git clone https://github.com/tahiri-lab/aPhyloGeo
python3 -m venv env
source env/bin/activate
python3 -m pip install aPhyloGeo
cd aPhyloGeo
python3 -m pytest tests

Expected behavior A clear and concise description of what you expected to happen. Desktop (please complete the following information):

             .',;::::;,'.                mmore500@fedora 
         .';:cccccccccccc:;,.            --------------- 
      .;cccccccccccccccccccccc;.         OS: Fedora Linux 40 (Workstation Edition) x86_64 
    .:cccccccccccccccccccccccccc:.       Host: 20U9005MUS ThinkPad X1 Carbon Gen 8 
  .;ccccccccccccc;.:dddl:.;ccccccc;.     Kernel: 6.9.12-200.fc40.x86_64 
 .:ccccccccccccc;OWMKOOXMWd;ccccccc:.    Uptime: 1 day, 23 hours, 18 mins 
.:ccccccccccccc;KMMc;cc;xMMc:ccccccc:.   Packages: 7145 (rpm), 18 (nix-user), 52 (nix-default), 19 (flatpak) 
,cccccccccccccc;MMM.;cc;;WW::cccccccc,   Shell: zsh 5.9 
:cccccccccccccc;MMM.;cccccccccccccccc:   Resolution: 1920x1080 
:ccccccc;oxOOOo;MMM0OOk.;cccccccccccc:   DE: GNOME 46.3.1 
cccccc:0MMKxdd:;MMMkddc.;cccccccccccc;   WM: Mutter 
ccccc:XM0';cccc;MMM.;cccccccccccccccc'   WM Theme: Nordic 
ccccc;MMo;ccccc;MMW.;ccccccccccccccc;    Theme: Nordic [GTK2/3] 
ccccc;0MNc.ccc.xMMd:ccccccccccccccc;     Icons: Adwaita [GTK2/3] 
cccccc;dNMWXXXWM0::cccccccccccccc:,      Terminal: tmux 
cccccccc;.:odl:.;cccccccccccccc:,.       CPU: Intel i7-10510U (8) @ 4.900GHz 
:cccccccccccccccccccccccccccc:'.         GPU: Intel CometLake-U GT2 [UHD Graphics] 
.:cccccccccccccccccccccc:;,..            Memory: 6152MiB / 15644MiB 
  '::cccccccccccccc::;,.
python -m pip freeze         
aphylogeo==1.0.0
bio==1.7.1
biopython==1.84
biothings-client==0.3.1
certifi==2024.7.4
charset-normalizer==3.3.2
Cython==3.0.11
DendroPy==4.6.4
dill==0.3.8
ete3==3.1.3
gprofiler-official==1.0.0
idna==3.7
iniconfig==2.0.0
multiprocess==0.70.16
mygene==3.2.2
numpy==1.26.4
packaging==24.1
pandas==2.2.2
platformdirs==4.2.2
pluggy==1.5.0
pooch==1.8.2
psutil==5.9.8
pytest==7.4.4
python-dateutil==2.9.0.post0
pytz==2024.1
PyYAML==6.0.1
requests==2.32.3
robinson-foulds==1.2
six==1.16.0
textdistance==4.6.3
tqdm==4.66.5
tzdata==2024.1
urllib3==2.2.2
mmore500 commented 1 month ago

As a related issue, the tests fail if not run from the root directory. For example, if run from inside tests/

============================= test session starts ==============================
platform linux -- Python 3.12.4, pytest-7.4.4, pluggy-1.5.0
rootdir: /home/mmore500/2024-08-05/aPhyloGeo
configfile: pyproject.toml
collected 10 items / 1 error

==================================== ERRORS ====================================
___________________ ERROR collecting tests/test_climatic.py ____________________
test_climatic.py:13: in <module>
    df = pd.read_csv("./datasets/example/geo.csv")
../../env/lib64/python3.12/site-packages/pandas/io/parsers/readers.py:1026: in read_csv
    return _read(filepath_or_buffer, kwds)
../../env/lib64/python3.12/site-packages/pandas/io/parsers/readers.py:620: in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
../../env/lib64/python3.12/site-packages/pandas/io/parsers/readers.py:1620: in __init__
    self._engine = self._make_engine(f, self.engine)
../../env/lib64/python3.12/site-packages/pandas/io/parsers/readers.py:1880: in _make_engine
    self.handles = get_handle(
../../env/lib64/python3.12/site-packages/pandas/io/common.py:873: in get_handle
    handle = open(
E   FileNotFoundError: [Errno 2] No such file or directory: './datasets/example/geo.csv'
=============================== warnings summary ===============================
../../env/lib64/python3.12/site-packages/ete3/webplugin/webapp.py:44
  /home/mmore500/2024-08-05/env/lib64/python3.12/site-packages/ete3/webplugin/webapp.py:44: DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13
    import cgi

../../env/lib64/python3.12/site-packages/Bio/Application/__init__.py:39
  /home/mmore500/2024-08-05/env/lib64/python3.12/site-packages/Bio/Application/__init__.py:39: BiopythonDeprecationWarning: The Bio.Application modules and modules relying on it have been deprecated.

  Due to the on going maintenance burden of keeping command line application
  wrappers up to date, we have decided to deprecate and eventually remove these
  modules.

  We instead now recommend building your command line and invoking it directly
  with the subprocess module.
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
ERROR test_climatic.py - FileNotFoundError: [Errno 2] No such file or directo...
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
========================= 2 warnings, 1 error in 1.11s =========================
mmore500 commented 1 month ago

This issue is part of JOSS review https://github.com/openjournals/joss-reviews/issues/6579