diff --git a/.appveyor.yml b/.appveyor.yml index e300d19..57be9e6 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -14,7 +14,7 @@ install: - conda config --set always_yes yes --set changeps1 no - conda update -q conda - conda info -a - - conda create -q -n test-environment --channel=conda-forge mmtf-python numpy scipy pandas pytest looseversion python=%PYTHON_VERSION% + - conda create -q -n test-environment --channel=conda-forge mmtf-python numpy scipy pandas pytest looseversion importlib_resources python=%PYTHON_VERSION% - activate test-environment test_script: diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index b43841a..926e674 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -5,7 +5,7 @@ name: Publish BioPandas to PyPI / GitHub on: pull_request: - branches: [ main ] + branches: [main] jobs: test-style: @@ -13,42 +13,42 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.x' - cache: 'pip' + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + cache: "pip" - - name: Install package dependencies for testing - run: pip install .[test] + - name: Install package dependencies for testing + run: pip install .[test] - - name: Run all the pytest tests - run: flake8 ./biopandas + - name: Run all the pytest tests + run: flake8 ./biopandas test-pytest: name: Run pytest tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.x' - cache: 'pip' + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + cache: "pip" - - name: Install package dependencies for testing - run: pip install .[test] + - name: Install package dependencies for testing + run: pip install .[test] - - name: Run all the pytest tests - run: pytest ./biopandas -sv + - name: Run all the pytest tests + run: pytest -sv build-n-publish: needs: [test-pytest] # only runs if tests are passing - if: startsWith(github.ref, 'refs/tags/v') # Check if the tag starts with 'v' + if: startsWith(github.ref, 'refs/tags/v') # Check if the tag starts with 'v' name: Build and publish to PyPI runs-on: ubuntu-latest diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1439afa..56db5e0 100755 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -8,6 +8,7 @@ The CHANGELOG for the current development version is available at - Feature: added method to `PandasMmcif` that allow to select by model ids. PR #[145](https://github.com/BioPandas/biopandas/pull/145)) - Dev: switched testing framework entirely to pytest. Drops nose dependency due to version conflicts with Python 3.12 (`nose`) and 3.8 (`nose`) PR #[146](https://github.com/BioPandas/biopandas/pull/146)) +- Avoid inclusion of test scripts and test data in the PyPI release of the Biopandas library. PR #[148](https://github.com/BioPandas/biopandas/pull/148). Addresses issue [#147](https://github.com/BioPandas/biopandas/issues/147) ### 0.5.0dev1 (31/7/2023) diff --git a/biopandas/mmcif/tests/__init__.py b/tests/__init__.py similarity index 100% rename from biopandas/mmcif/tests/__init__.py rename to tests/__init__.py diff --git a/biopandas/mmtf/tests/__init__.py b/tests/mmcif/__init__.py similarity index 100% rename from biopandas/mmtf/tests/__init__.py rename to tests/mmcif/__init__.py diff --git a/biopandas/mmcif/tests/data/1ehz.cif b/tests/mmcif/data/1ehz.cif similarity index 100% rename from biopandas/mmcif/tests/data/1ehz.cif rename to tests/mmcif/data/1ehz.cif diff --git a/biopandas/mmcif/tests/data/1t48.cif b/tests/mmcif/data/1t48.cif similarity index 100% rename from biopandas/mmcif/tests/data/1t48.cif rename to tests/mmcif/data/1t48.cif diff --git a/biopandas/mmcif/tests/data/1t49.cif b/tests/mmcif/data/1t49.cif similarity index 100% rename from biopandas/mmcif/tests/data/1t49.cif rename to tests/mmcif/data/1t49.cif diff --git a/biopandas/mmcif/tests/data/2d7t.cif b/tests/mmcif/data/2d7t.cif similarity index 100% rename from biopandas/mmcif/tests/data/2d7t.cif rename to tests/mmcif/data/2d7t.cif diff --git a/biopandas/mmcif/tests/data/2jyf.cif.gz b/tests/mmcif/data/2jyf.cif.gz similarity index 100% rename from biopandas/mmcif/tests/data/2jyf.cif.gz rename to tests/mmcif/data/2jyf.cif.gz diff --git a/biopandas/mmcif/tests/data/3eiy.cif b/tests/mmcif/data/3eiy.cif similarity index 100% rename from biopandas/mmcif/tests/data/3eiy.cif rename to tests/mmcif/data/3eiy.cif diff --git a/biopandas/mmcif/tests/data/3eiy.cif.gz b/tests/mmcif/data/3eiy.cif.gz similarity index 100% rename from biopandas/mmcif/tests/data/3eiy.cif.gz rename to tests/mmcif/data/3eiy.cif.gz diff --git a/biopandas/mmcif/tests/data/3eiy_stripped_ele.cif b/tests/mmcif/data/3eiy_stripped_ele.cif similarity index 100% rename from biopandas/mmcif/tests/data/3eiy_stripped_ele.cif rename to tests/mmcif/data/3eiy_stripped_ele.cif diff --git a/biopandas/mmcif/tests/data/4eiy.cif b/tests/mmcif/data/4eiy.cif similarity index 100% rename from biopandas/mmcif/tests/data/4eiy.cif rename to tests/mmcif/data/4eiy.cif diff --git a/biopandas/mmcif/tests/data/5mtn_multichain.cif b/tests/mmcif/data/5mtn_multichain.cif similarity index 100% rename from biopandas/mmcif/tests/data/5mtn_multichain.cif rename to tests/mmcif/data/5mtn_multichain.cif diff --git a/biopandas/mmcif/tests/data/AF-Q5VSL9-F1-model_v2.cif b/tests/mmcif/data/AF-Q5VSL9-F1-model_v2.cif similarity index 100% rename from biopandas/mmcif/tests/data/AF-Q5VSL9-F1-model_v2.cif rename to tests/mmcif/data/AF-Q5VSL9-F1-model_v2.cif diff --git a/biopandas/mmcif/tests/data/AF-Q5VSL9-F1-model_v3.cif b/tests/mmcif/data/AF-Q5VSL9-F1-model_v3.cif similarity index 100% rename from biopandas/mmcif/tests/data/AF-Q5VSL9-F1-model_v3.cif rename to tests/mmcif/data/AF-Q5VSL9-F1-model_v3.cif diff --git a/biopandas/mmcif/tests/data/AF-Q5VSL9-F1-model_v4.cif b/tests/mmcif/data/AF-Q5VSL9-F1-model_v4.cif similarity index 100% rename from biopandas/mmcif/tests/data/AF-Q5VSL9-F1-model_v4.cif rename to tests/mmcif/data/AF-Q5VSL9-F1-model_v4.cif diff --git a/biopandas/mmcif/tests/test_amino3to1.py b/tests/mmcif/test_amino3to1.py similarity index 96% rename from biopandas/mmcif/tests/test_amino3to1.py rename to tests/mmcif/test_amino3to1.py index 83a671c..1effebe 100644 --- a/biopandas/mmcif/tests/test_amino3to1.py +++ b/tests/mmcif/test_amino3to1.py @@ -4,14 +4,23 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import numpy as np + +import tests.mmcif.data from biopandas.mmcif import PandasMmcif +TEST_DATA = pkg_resources.files(tests.mmcif.data) + def test_defaults(): - TESTDATA_1t48 = os.path.join(os.path.dirname(__file__), "data", "1t48.cif") + TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48.cif")) p1t48 = PandasMmcif() p1t48.read_mmcif(TESTDATA_1t48) expect_res = [ @@ -309,7 +318,7 @@ def test_defaults(): def test_sameindex(): - TESTDATA_1t48 = os.path.join(os.path.dirname(__file__), "data", "1t48.cif") + TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48.cif")) p1t48 = PandasMmcif() p1t48.read_mmcif(TESTDATA_1t48) p1t48.df["ATOM"].index = np.zeros(p1t48.df["ATOM"].shape[0], dtype=int) @@ -608,9 +617,7 @@ def test_sameindex(): def test_multichain(): - TESTDATA_5mtn = os.path.join( - os.path.dirname(__file__), "data", "5mtn_multichain.cif" - ) + TESTDATA_5mtn = str(TEST_DATA.joinpath("5mtn_multichain.cif")) mtn = PandasMmcif() mtn.read_mmcif(TESTDATA_5mtn) expect_res_a = [ @@ -818,7 +825,7 @@ def test_multichain(): def test_pdb_with_insertion_codes(): - PDB_2D7T_PATH = os.path.join(os.path.dirname(__file__), "data", "2d7t.cif") + PDB_2D7T_PATH = str(TEST_DATA.joinpath("2d7t.cif")) ppdb = PandasMmcif().read_mmcif(PDB_2D7T_PATH) sequence = ppdb.amino3to1() diff --git a/biopandas/mmcif/tests/test_assign_df.py b/tests/mmcif/test_assign_df.py similarity index 67% rename from biopandas/mmcif/tests/test_assign_df.py rename to tests/mmcif/test_assign_df.py index 2706637..b012d60 100644 --- a/biopandas/mmcif/tests/test_assign_df.py +++ b/tests/mmcif/test_assign_df.py @@ -4,16 +4,22 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources + +import tests.mmcif.data from biopandas.mmcif import PandasMmcif -from biopandas.testutils import assert_raises +from tests.testutils import assert_raises -TESTDATA_FILENAME = os.path.join(os.path.dirname(__file__), "data", "3eiy.cif") +TEST_DATA = pkg_resources.files(tests.mmcif.data) def test_overwrite_df(): - data_path = os.path.join(os.path.dirname(__file__), "data", "3eiy.cif") + data_path = str(TEST_DATA.joinpath("3eiy.cif")) pdb = PandasMmcif().read_mmcif(data_path) def overwrite(): diff --git a/biopandas/mmcif/tests/test_distance.py b/tests/mmcif/test_distance.py similarity index 77% rename from biopandas/mmcif/tests/test_distance.py rename to tests/mmcif/test_distance.py index e7cd116..df45be9 100644 --- a/biopandas/mmcif/tests/test_distance.py +++ b/tests/mmcif/test_distance.py @@ -4,14 +4,23 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import pandas as pd + +import tests.mmcif.data from biopandas.mmcif import PandasMmcif +TEST_DATA = pkg_resources.files(tests.mmcif.data) + def test_equal(): - TESTDATA_1t48 = os.path.join(os.path.dirname(__file__), "data", "1t48.cif") + TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48.cif")) p1t48 = PandasMmcif() p1t48.read_mmcif(TESTDATA_1t48) @@ -25,7 +34,7 @@ def test_equal(): def test_deprecated_str_arg(): - TESTDATA_1t48 = os.path.join(os.path.dirname(__file__), "data", "1t48.cif") + TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48.cif")) p1t48 = PandasMmcif() p1t48.read_mmcif(TESTDATA_1t48) @@ -39,7 +48,7 @@ def test_deprecated_str_arg(): def test_use_external_df(): - TESTDATA_1t48 = os.path.join(os.path.dirname(__file__), "data", "1t48.cif") + TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48.cif")) p1t48 = PandasMmcif() p1t48.read_mmcif(TESTDATA_1t48) diff --git a/biopandas/mmcif/tests/test_multiple_models.py b/tests/mmcif/test_multiple_models.py similarity index 63% rename from biopandas/mmcif/tests/test_multiple_models.py rename to tests/mmcif/test_multiple_models.py index e8cf496..084fd15 100644 --- a/biopandas/mmcif/tests/test_multiple_models.py +++ b/tests/mmcif/test_multiple_models.py @@ -4,22 +4,35 @@ # License: BSD 3 clause # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources + +import tests.mmcif.data from biopandas.mmcif import PandasMmcif -TESTDATA_FILENAME = os.path.join(os.path.dirname(__file__), "data", "2jyf.cif.gz") +TEST_DATA = pkg_resources.files(tests.mmcif.data) + +TESTDATA_FILENAME = str(TEST_DATA.joinpath("2jyf.cif.gz")) + def test_label_models(): biopandas_structure = PandasMmcif().read_mmcif(TESTDATA_FILENAME) biopandas_structure.label_models() assert "model_id" in biopandas_structure.df["ATOM"].columns + def test_get_model(): biopandas_structure = PandasMmcif().read_mmcif(TESTDATA_FILENAME) MODEL_INDEX = 1 new_biopandas_structure = biopandas_structure.get_model(MODEL_INDEX) - assert new_biopandas_structure.df["ATOM"]["pdbx_PDB_model_num"].all() == MODEL_INDEX + assert ( + new_biopandas_structure.df["ATOM"]["pdbx_PDB_model_num"].all() + == MODEL_INDEX + ) def test_get_models(): @@ -27,4 +40,7 @@ def test_get_models(): MODEL_INDICES = [1, 3, 5] new_biopandas_structure = biopandas_structure.get_models(MODEL_INDICES) - assert new_biopandas_structure.df["ATOM"]["pdbx_PDB_model_num"].all() in MODEL_INDICES \ No newline at end of file + assert ( + new_biopandas_structure.df["ATOM"]["pdbx_PDB_model_num"].all() + in MODEL_INDICES + ) diff --git a/biopandas/mmcif/tests/test_read_mmcif.py b/tests/mmcif/test_read_mmcif.py similarity index 93% rename from biopandas/mmcif/tests/test_read_mmcif.py rename to tests/mmcif/test_read_mmcif.py index bfba806..e2a907b 100644 --- a/biopandas/mmcif/tests/test_read_mmcif.py +++ b/tests/mmcif/test_read_mmcif.py @@ -5,36 +5,35 @@ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources from pathlib import Path from urllib.error import HTTPError import pandas as pd import pytest +from pandas.testing import assert_frame_equal + +import tests.mmcif.data from biopandas.mmcif import PandasMmcif from biopandas.pdb import PandasPdb -from biopandas.testutils import assert_raises -from pandas.testing import assert_frame_equal +from tests.testutils import assert_raises + +TEST_DATA = pkg_resources.files(tests.mmcif.data) -TESTDATA_FILENAME = os.path.join(os.path.dirname(__file__), "data", "3eiy.cif") +TESTDATA_FILENAME = str(TEST_DATA.joinpath("3eiy.cif")) # Not clear on how ANISOU records are handled in mmCIF files so skipping -# TESTDATA_FILENAME2 = os.path.join( -# os.path.dirname(__file__), "data", "4eiy_anisouchunk.cif" -# ) -TESTDATA_FILENAME2 = os.path.join( - os.path.dirname(__file__), "data", "4eiy.cif" -) -TESTDATA_FILENAME_GZ = os.path.join( - os.path.dirname(__file__), "data", "3eiy.cif.gz" -) - -TESTDATA_FILENAME_AF2_V4 = os.path.join( - os.path.dirname(__file__), "data", "AF-Q5VSL9-F1-model_v4.cif" -) -TESTDATA_FILENAME_AF2_V3 = os.path.join( - os.path.dirname(__file__), "data", "AF-Q5VSL9-F1-model_v3.cif" -) +# TESTDATA_FILENAME2 = str(TEST_DATA.joinpath("4eiy_anisouchunk.cif")) +TESTDATA_FILENAME2 = str(TEST_DATA.joinpath("4eiy.cif")) +TESTDATA_FILENAME_GZ = str(TEST_DATA.joinpath("3eiy.cif.gz")) + +TESTDATA_FILENAME_AF2_V4 = str(TEST_DATA.joinpath("AF-Q5VSL9-F1-model_v4.cif")) +TESTDATA_FILENAME_AF2_V3 = str(TEST_DATA.joinpath("AF-Q5VSL9-F1-model_v3.cif")) ATOM_DF_COLUMNS = [ "B_iso_or_equiv", diff --git a/biopandas/mmcif/tests/test_rmsd.py b/tests/mmcif/test_rmsd.py similarity index 77% rename from biopandas/mmcif/tests/test_rmsd.py rename to tests/mmcif/test_rmsd.py index 054f3b2..0c21bbf 100644 --- a/biopandas/mmcif/tests/test_rmsd.py +++ b/tests/mmcif/test_rmsd.py @@ -4,17 +4,26 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import pytest + +import tests.mmcif.data from biopandas.mmcif import PandasMmcif -TESTDATA_1t48 = os.path.join(os.path.dirname(__file__), "data", "1t48.cif") -TESTDATA_1t49 = os.path.join(os.path.dirname(__file__), "data", "1t49.cif") -# TESTDATA_lig1 = os.path.join(os.path.dirname(__file__), "data", "lig_conf_1.pdb") -# TESTDATA_lig2 = os.path.join(os.path.dirname(__file__), "data", "lig_conf_2.pdb") +TEST_DATA = pkg_resources.files(tests.mmcif.data) + +TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48.cif")) +TESTDATA_1t49 = str(TEST_DATA.joinpath("1t49.cif")) +# TESTDATA_lig1 = str(TEST_DATA.joinpath("lig_conf_1.pdb")) +# TESTDATA_lig2 = str(TEST_DATA.joinpath("lig_conf_2.pdb")) -TESTDATA_rna = os.path.join(os.path.dirname(__file__), "data", "1ehz.cif") +TESTDATA_rna = str(TEST_DATA.joinpath("1ehz.cif")) p1t48 = PandasMmcif() p1t48.read_mmcif(TESTDATA_1t48) diff --git a/biopandas/pdb/tests/__init__.py b/tests/mmtf/__init__.py similarity index 100% rename from biopandas/pdb/tests/__init__.py rename to tests/mmtf/__init__.py diff --git a/biopandas/mmtf/tests/data/1ehz.mmtf b/tests/mmtf/data/1ehz.mmtf similarity index 100% rename from biopandas/mmtf/tests/data/1ehz.mmtf rename to tests/mmtf/data/1ehz.mmtf diff --git a/biopandas/mmtf/tests/data/1t48.mmtf b/tests/mmtf/data/1t48.mmtf similarity index 100% rename from biopandas/mmtf/tests/data/1t48.mmtf rename to tests/mmtf/data/1t48.mmtf diff --git a/biopandas/mmtf/tests/data/1t49.mmtf b/tests/mmtf/data/1t49.mmtf similarity index 100% rename from biopandas/mmtf/tests/data/1t49.mmtf rename to tests/mmtf/data/1t49.mmtf diff --git a/biopandas/mmtf/tests/data/2d7t.mmtf b/tests/mmtf/data/2d7t.mmtf similarity index 100% rename from biopandas/mmtf/tests/data/2d7t.mmtf rename to tests/mmtf/data/2d7t.mmtf diff --git a/biopandas/mmtf/tests/data/2jyf.mmtf b/tests/mmtf/data/2jyf.mmtf similarity index 100% rename from biopandas/mmtf/tests/data/2jyf.mmtf rename to tests/mmtf/data/2jyf.mmtf diff --git a/biopandas/mmtf/tests/data/3eiy.mmtf b/tests/mmtf/data/3eiy.mmtf similarity index 100% rename from biopandas/mmtf/tests/data/3eiy.mmtf rename to tests/mmtf/data/3eiy.mmtf diff --git a/biopandas/mmtf/tests/data/3eiy.mmtf.gz b/tests/mmtf/data/3eiy.mmtf.gz similarity index 100% rename from biopandas/mmtf/tests/data/3eiy.mmtf.gz rename to tests/mmtf/data/3eiy.mmtf.gz diff --git a/biopandas/mmtf/tests/data/4CUP.mmtf b/tests/mmtf/data/4CUP.mmtf similarity index 100% rename from biopandas/mmtf/tests/data/4CUP.mmtf rename to tests/mmtf/data/4CUP.mmtf diff --git a/biopandas/mmtf/tests/data/4eiy.mmtf b/tests/mmtf/data/4eiy.mmtf similarity index 100% rename from biopandas/mmtf/tests/data/4eiy.mmtf rename to tests/mmtf/data/4eiy.mmtf diff --git a/biopandas/mmtf/tests/data/5mtn.mmtf b/tests/mmtf/data/5mtn.mmtf similarity index 100% rename from biopandas/mmtf/tests/data/5mtn.mmtf rename to tests/mmtf/data/5mtn.mmtf diff --git a/biopandas/mmtf/tests/test_amino3to1.py b/tests/mmtf/test_amino3to1.py similarity index 96% rename from biopandas/mmtf/tests/test_amino3to1.py rename to tests/mmtf/test_amino3to1.py index 081265f..ea0c51f 100644 --- a/biopandas/mmtf/tests/test_amino3to1.py +++ b/tests/mmtf/test_amino3to1.py @@ -4,16 +4,23 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import numpy as np + +import tests.mmtf.data from biopandas.mmtf import PandasMmtf +TEST_DATA = pkg_resources.files(tests.mmtf.data) + def test_defaults(): - TESTDATA_1t48 = os.path.join( - os.path.dirname(__file__), "data", "1t48.mmtf" - ) + TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48.mmtf")) p1t48 = PandasMmtf() p1t48.read_mmtf(TESTDATA_1t48) expect_res = [ @@ -321,9 +328,7 @@ def test_defaults(): def test_sameindex(): - TESTDATA_1t48 = os.path.join( - os.path.dirname(__file__), "data", "1t48.mmtf" - ) + TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48.mmtf")) p1t48 = PandasMmtf() p1t48.read_mmtf(TESTDATA_1t48) p1t48.df["ATOM"].index = np.zeros(p1t48.df["ATOM"].shape[0], dtype=int) @@ -632,9 +637,7 @@ def test_sameindex(): def test_multichain(): - TESTDATA_5mtn = os.path.join( - os.path.dirname(__file__), "data", "5mtn.mmtf" - ) + TESTDATA_5mtn = str(TEST_DATA.joinpath("5mtn.mmtf")) mtn = PandasMmtf() mtn.read_mmtf(TESTDATA_5mtn) expect_res_a = [ @@ -842,9 +845,7 @@ def test_multichain(): def test_pdb_with_insertion_codes(): - PDB_2D7T_PATH = os.path.join( - os.path.dirname(__file__), "data", "2d7t.mmtf" - ) + PDB_2D7T_PATH = str(TEST_DATA.joinpath("2d7t.mmtf")) ppdb = PandasMmtf().read_mmtf(PDB_2D7T_PATH) sequence = ppdb.amino3to1() diff --git a/biopandas/mmtf/tests/test_assign_df.py b/tests/mmtf/test_assign_df.py similarity index 61% rename from biopandas/mmtf/tests/test_assign_df.py rename to tests/mmtf/test_assign_df.py index f9dd1bd..72d2363 100644 --- a/biopandas/mmtf/tests/test_assign_df.py +++ b/tests/mmtf/test_assign_df.py @@ -4,19 +4,24 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources + +import tests.mmtf.data from biopandas.mmtf import PandasMmtf -from biopandas.testutils import assert_raises +from tests.testutils import assert_raises + +TEST_DATA = pkg_resources.files(tests.mmtf.data) -TESTDATA_FILENAME = os.path.join( - os.path.dirname(__file__), "data", "3eiy.mmtf" -) +TESTDATA_FILENAME = str(TEST_DATA.joinpath("3eiy.mmtf")) def test_overwrite_df(): - data_path = os.path.join(os.path.dirname(__file__), "data", "3eiy.mmtf") - pdb = PandasMmtf().read_mmtf(data_path) + pdb = PandasMmtf().read_mmtf(TESTDATA_FILENAME) def overwrite(): pdb.df = "bla" diff --git a/biopandas/mmtf/tests/test_distance.py b/tests/mmtf/test_distance.py similarity index 77% rename from biopandas/mmtf/tests/test_distance.py rename to tests/mmtf/test_distance.py index 96291e3..856feff 100644 --- a/biopandas/mmtf/tests/test_distance.py +++ b/tests/mmtf/test_distance.py @@ -4,16 +4,23 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import pandas as pd + +import tests.mmtf.data from biopandas.mmtf import PandasMmtf +TEST_DATA = pkg_resources.files(tests.mmtf.data) + def test_equal(): - TESTDATA_1t48 = os.path.join( - os.path.dirname(__file__), "data", "1t48.mmtf" - ) + TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48.mmtf")) p1t48 = PandasMmtf() p1t48.read_mmtf(TESTDATA_1t48) @@ -27,9 +34,7 @@ def test_equal(): def test_deprecated_str_arg(): - TESTDATA_1t48 = os.path.join( - os.path.dirname(__file__), "data", "1t48.mmtf" - ) + TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48.mmtf")) p1t48 = PandasMmtf() p1t48.read_mmtf(TESTDATA_1t48) @@ -43,9 +48,7 @@ def test_deprecated_str_arg(): def test_use_external_df(): - TESTDATA_1t48 = os.path.join( - os.path.dirname(__file__), "data", "1t48.mmtf" - ) + TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48.mmtf")) p1t48 = PandasMmtf() p1t48.read_mmtf(TESTDATA_1t48) diff --git a/biopandas/mmtf/tests/test_multiple_models.py b/tests/mmtf/test_multiple_models.py similarity index 83% rename from biopandas/mmtf/tests/test_multiple_models.py rename to tests/mmtf/test_multiple_models.py index 30be1cc..55ed818 100644 --- a/biopandas/mmtf/tests/test_multiple_models.py +++ b/tests/mmtf/test_multiple_models.py @@ -4,14 +4,23 @@ # License: BSD 3 clause # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas + +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import os -from biopandas.mmtf import PandasMmtf from pandas.testing import assert_frame_equal -TESTDATA_FILENAME = os.path.join( - os.path.dirname(__file__), "data", "2jyf.mmtf" -) +import tests.mmtf.data +from biopandas.mmtf import PandasMmtf + +TEST_DATA = pkg_resources.files(tests.mmtf.data) + +TESTDATA_FILENAME = str(TEST_DATA.joinpath("2jyf.mmtf")) def test_label_models(): diff --git a/biopandas/mmtf/tests/test_read_mmtf.py b/tests/mmtf/test_read_mmtf.py similarity index 80% rename from biopandas/mmtf/tests/test_read_mmtf.py rename to tests/mmtf/test_read_mmtf.py index 045ff1d..cba1b73 100644 --- a/biopandas/mmtf/tests/test_read_mmtf.py +++ b/tests/mmtf/test_read_mmtf.py @@ -4,32 +4,29 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import unittest import pandas as pd + +import tests.mmtf.data +import tests.pdb.data from biopandas.mmtf import PandasMmtf from biopandas.pdb import PandasPdb -MMTF_TESTDATA_FILENAME = os.path.join( - os.path.dirname(__file__), "data", "3eiy.mmtf" -) -MMTF_TESTDATA_FILENAME_GZ = os.path.join( - os.path.dirname(__file__), "data", "3eiy.mmtf.gz" -) - -PDB_TESTDATA_FILENAME = os.path.join( - os.path.dirname(__file__), "..", "..", "pdb", "tests", "data", "3eiy.pdb" -) -PDB_TESTDATA_FILENAME_GZ = os.path.join( - os.path.dirname(__file__), - "..", - "..", - "pdb", - "tests", - "data", - "3eiy.pdb.gz", -) +TEST_DATA = pkg_resources.files(tests.mmtf.data) +PDB_TEST_DATA = pkg_resources.files(tests.pdb.data) + +MMTF_TESTDATA_FILENAME = str(TEST_DATA.joinpath("3eiy.mmtf")) +MMTF_TESTDATA_FILENAME_GZ = str(TEST_DATA.joinpath("3eiy.mmtf.gz")) + +PDB_TESTDATA_FILENAME = str(PDB_TEST_DATA.joinpath("3eiy.pdb")) +PDB_TESTDATA_FILENAME_GZ = str(PDB_TEST_DATA.joinpath("3eiy.pdb.gz")) ATOM_DF_COLUMNS = [ diff --git a/biopandas/mmtf/tests/test_rmsd.py b/tests/mmtf/test_rmsd.py similarity index 80% rename from biopandas/mmtf/tests/test_rmsd.py rename to tests/mmtf/test_rmsd.py index 1131009..32538af 100644 --- a/biopandas/mmtf/tests/test_rmsd.py +++ b/tests/mmtf/test_rmsd.py @@ -4,17 +4,26 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import pytest + +import tests.mmtf.data from biopandas.mmtf import PandasMmtf -TESTDATA_1t48 = os.path.join(os.path.dirname(__file__), "data", "1t48.mmtf") -TESTDATA_1t49 = os.path.join(os.path.dirname(__file__), "data", "1t49.mmtf") -# TESTDATA_lig1 = os.path.join(os.path.dirname(__file__), "data", "lig_conf_1.pdb") -# TESTDATA_lig2 = os.path.join(os.path.dirname(__file__), "data", "lig_conf_2.pdb") +TEST_DATA = pkg_resources.files(tests.mmtf.data) + +TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48.mmtf")) +TESTDATA_1t49 = str(TEST_DATA.joinpath("1t49.mmtf")) +# TESTDATA_lig1 = str(TEST_DATA.joinpath("lig_conf_1.pdb")) +# TESTDATA_lig2 = str(TEST_DATA.joinpath("lig_conf_2.pdb")) -TESTDATA_rna = os.path.join(os.path.dirname(__file__), "data", "1ehz.mmtf") +TESTDATA_rna = str(TEST_DATA.joinpath("1ehz.mmtf")) p1t48 = PandasMmtf() p1t48.read_mmtf(TESTDATA_1t48) diff --git a/biopandas/mmtf/tests/test_write_mmtf.py b/tests/mmtf/test_write_mmtf.py similarity index 99% rename from biopandas/mmtf/tests/test_write_mmtf.py rename to tests/mmtf/test_write_mmtf.py index 69452e8..f516f6c 100644 --- a/biopandas/mmtf/tests/test_write_mmtf.py +++ b/tests/mmtf/test_write_mmtf.py @@ -2,9 +2,10 @@ import unittest import pandas as pd -from biopandas.mmtf.pandas_mmtf import PandasMmtf, write_mmtf from pandas.testing import assert_frame_equal +from biopandas.mmtf.pandas_mmtf import PandasMmtf, write_mmtf + @unittest.skip(reason="PDB No longer serves MMTF files.") def test_write_mmtf_bp(): diff --git a/tests/mol2/__init__.py b/tests/mol2/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/biopandas/mol2/tests/data/1b5e_1.mol2 b/tests/mol2/data/1b5e_1.mol2 similarity index 100% rename from biopandas/mol2/tests/data/1b5e_1.mol2 rename to tests/mol2/data/1b5e_1.mol2 diff --git a/biopandas/mol2/tests/data/1b5e_2.mol2 b/tests/mol2/data/1b5e_2.mol2 similarity index 100% rename from biopandas/mol2/tests/data/1b5e_2.mol2 rename to tests/mol2/data/1b5e_2.mol2 diff --git a/biopandas/mol2/tests/data/40_mol2_files.mol2 b/tests/mol2/data/40_mol2_files.mol2 similarity index 100% rename from biopandas/mol2/tests/data/40_mol2_files.mol2 rename to tests/mol2/data/40_mol2_files.mol2 diff --git a/biopandas/mol2/tests/data/40_mol2_files.mol2.gz b/tests/mol2/data/40_mol2_files.mol2.gz similarity index 100% rename from biopandas/mol2/tests/data/40_mol2_files.mol2.gz rename to tests/mol2/data/40_mol2_files.mol2.gz diff --git a/biopandas/mol2/tests/data/empty_line.mol2 b/tests/mol2/data/empty_line.mol2 similarity index 100% rename from biopandas/mol2/tests/data/empty_line.mol2 rename to tests/mol2/data/empty_line.mol2 diff --git a/biopandas/mol2/tests/test_mol2_io.py b/tests/mol2/test_mol2_io.py similarity index 66% rename from biopandas/mol2/tests/test_mol2_io.py rename to tests/mol2/test_mol2_io.py index b6c4c98..5591829 100644 --- a/biopandas/mol2/tests/test_mol2_io.py +++ b/tests/mol2/test_mol2_io.py @@ -4,26 +4,29 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources + +import tests.mol2.data from biopandas.mol2.mol2_io import split_multimol2 -from biopandas.testutils import assert_raises +from tests.testutils import assert_raises -this_dir = os.path.dirname(os.path.realpath(__file__)) +TEST_DATA = pkg_resources.files(tests.mol2.data) def test_split_multimol2(): all_mol2 = [] - for i in split_multimol2( - os.path.join(this_dir, "data", "40_mol2_files.mol2") - ): + for i in split_multimol2(str(TEST_DATA.joinpath("40_mol2_files.mol2"))): all_mol2.append(i[0]) assert all_mol2[1] == "ZINC04084113" assert len(all_mol2) == 40 def test_split_multimol2_wrong_format(): - expect = ( "Wrong file format;" "allowed file formats are .mol2 and .mol2.gz." ) @@ -36,9 +39,7 @@ def run_code(): def test_split_multimol2_gz(): all_mol2 = [] - for i in split_multimol2( - os.path.join(this_dir, "data", "40_mol2_files.mol2.gz") - ): + for i in split_multimol2(str(TEST_DATA.joinpath("40_mol2_files.mol2.gz"))): all_mol2.append(i[0]) assert all_mol2[1].decode() == "ZINC04084113" assert len(all_mol2) == 40 diff --git a/biopandas/mol2/tests/test_pandas_mol2.py b/tests/mol2/test_pandas_mol2.py similarity index 74% rename from biopandas/mol2/tests/test_pandas_mol2.py rename to tests/mol2/test_pandas_mol2.py index ba88dd0..b7b2867 100644 --- a/biopandas/mol2/tests/test_pandas_mol2.py +++ b/tests/mol2/test_pandas_mol2.py @@ -1,4 +1,4 @@ -""" Utility function for reading Tripos MOL2 files from files""" +"""Utility function for reading Tripos MOL2 files from files""" # BioPandas # Author: Sebastian Raschka @@ -6,20 +6,25 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources + +import tests.mol2.data from biopandas.mol2 import PandasMol2 from biopandas.mol2.mol2_io import split_multimol2 -from biopandas.testutils import assert_raises +from tests.testutils import assert_raises -this_dir = os.path.dirname(os.path.realpath(__file__)) +TEST_DATA = pkg_resources.files(tests.mol2.data) def test_read_mol2(): - - data_path_1 = os.path.join(this_dir, "data", "40_mol2_files.mol2") - data_path_2 = os.path.join(this_dir, "data", "40_mol2_files.mol2.gz") - data_path_3 = os.path.join(this_dir, "data", "empty_line.mol2") + data_path_1 = str(TEST_DATA.joinpath("40_mol2_files.mol2")) + data_path_2 = str(TEST_DATA.joinpath("40_mol2_files.mol2.gz")) + data_path_3 = str(TEST_DATA.joinpath("empty_line.mol2")) for data_path in (data_path_1, data_path_2): pdmol = PandasMol2().read_mol2(data_path) @@ -46,8 +51,7 @@ def test_read_mol2(): def test_read_mol2_from_list(): - - data_path = os.path.join(this_dir, "data", "40_mol2_files.mol2") + data_path = str(TEST_DATA.joinpath("40_mol2_files.mol2")) mol2 = next(split_multimol2(data_path)) pdmol = PandasMol2().read_mol2_from_list( @@ -58,8 +62,8 @@ def test_read_mol2_from_list(): def test_rmsd(): - data_path_1 = os.path.join(this_dir, "data", "1b5e_1.mol2") - data_path_2 = os.path.join(this_dir, "data", "1b5e_2.mol2") + data_path_1 = str(TEST_DATA.joinpath("1b5e_1.mol2")) + data_path_2 = str(TEST_DATA.joinpath("1b5e_2.mol2")) pdmol_1 = PandasMol2().read_mol2(data_path_1) pdmol_2 = PandasMol2().read_mol2(data_path_2) @@ -69,14 +73,14 @@ def test_rmsd(): def test_distance(): - data_path = os.path.join(this_dir, "data", "1b5e_1.mol2") + data_path = str(TEST_DATA.joinpath("1b5e_1.mol2")) pdmol = PandasMol2().read_mol2(data_path) assert round(pdmol.distance().values[0], 3) == 31.185 def test_distance_external_df(): - data_path = os.path.join(this_dir, "data", "1b5e_1.mol2") + data_path = str(TEST_DATA.joinpath("1b5e_1.mol2")) pdmol = PandasMol2().read_mol2(data_path) new_df = pdmol.df.iloc[1:, :].copy() @@ -84,7 +88,7 @@ def test_distance_external_df(): def test_overwrite_df(): - data_path = os.path.join(this_dir, "data", "1b5e_1.mol2") + data_path = str(TEST_DATA.joinpath("1b5e_1.mol2")) pdmol = PandasMol2().read_mol2(data_path) def overwrite(): diff --git a/tests/pdb/__init__.py b/tests/pdb/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/biopandas/pdb/tests/data/1ehz-rna_short.pdb b/tests/pdb/data/1ehz-rna_short.pdb similarity index 100% rename from biopandas/pdb/tests/data/1ehz-rna_short.pdb rename to tests/pdb/data/1ehz-rna_short.pdb diff --git a/biopandas/pdb/tests/data/1t48_995.pdb b/tests/pdb/data/1t48_995.pdb similarity index 100% rename from biopandas/pdb/tests/data/1t48_995.pdb rename to tests/pdb/data/1t48_995.pdb diff --git a/biopandas/pdb/tests/data/1t49_995.pdb b/tests/pdb/data/1t49_995.pdb similarity index 100% rename from biopandas/pdb/tests/data/1t49_995.pdb rename to tests/pdb/data/1t49_995.pdb diff --git a/biopandas/pdb/tests/data/2d7t.pdb b/tests/pdb/data/2d7t.pdb similarity index 100% rename from biopandas/pdb/tests/data/2d7t.pdb rename to tests/pdb/data/2d7t.pdb diff --git a/biopandas/pdb/tests/data/2jyf.pdb b/tests/pdb/data/2jyf.pdb similarity index 100% rename from biopandas/pdb/tests/data/2jyf.pdb rename to tests/pdb/data/2jyf.pdb diff --git a/biopandas/pdb/tests/data/3eiy.pdb b/tests/pdb/data/3eiy.pdb similarity index 100% rename from biopandas/pdb/tests/data/3eiy.pdb rename to tests/pdb/data/3eiy.pdb diff --git a/biopandas/pdb/tests/data/3eiy.pdb.gz b/tests/pdb/data/3eiy.pdb.gz similarity index 100% rename from biopandas/pdb/tests/data/3eiy.pdb.gz rename to tests/pdb/data/3eiy.pdb.gz diff --git a/biopandas/pdb/tests/data/3eiy_stripped_no_ele.pdb b/tests/pdb/data/3eiy_stripped_no_ele.pdb similarity index 100% rename from biopandas/pdb/tests/data/3eiy_stripped_no_ele.pdb rename to tests/pdb/data/3eiy_stripped_no_ele.pdb diff --git a/biopandas/pdb/tests/data/4eiy_anisouchunk.pdb b/tests/pdb/data/4eiy_anisouchunk.pdb similarity index 100% rename from biopandas/pdb/tests/data/4eiy_anisouchunk.pdb rename to tests/pdb/data/4eiy_anisouchunk.pdb diff --git a/biopandas/pdb/tests/data/5mtn_multichain.pdb b/tests/pdb/data/5mtn_multichain.pdb similarity index 100% rename from biopandas/pdb/tests/data/5mtn_multichain.pdb rename to tests/pdb/data/5mtn_multichain.pdb diff --git a/biopandas/pdb/tests/data/AF-Q5VSL9-F1-model_v2.pdb b/tests/pdb/data/AF-Q5VSL9-F1-model_v2.pdb similarity index 100% rename from biopandas/pdb/tests/data/AF-Q5VSL9-F1-model_v2.pdb rename to tests/pdb/data/AF-Q5VSL9-F1-model_v2.pdb diff --git a/biopandas/pdb/tests/data/AF-Q5VSL9-F1-model_v3.pdb b/tests/pdb/data/AF-Q5VSL9-F1-model_v3.pdb similarity index 100% rename from biopandas/pdb/tests/data/AF-Q5VSL9-F1-model_v3.pdb rename to tests/pdb/data/AF-Q5VSL9-F1-model_v3.pdb diff --git a/biopandas/pdb/tests/data/AF-Q5VSL9-F1-model_v4.pdb b/tests/pdb/data/AF-Q5VSL9-F1-model_v4.pdb similarity index 100% rename from biopandas/pdb/tests/data/AF-Q5VSL9-F1-model_v4.pdb rename to tests/pdb/data/AF-Q5VSL9-F1-model_v4.pdb diff --git a/biopandas/pdb/tests/data/lig_conf_1.pdb b/tests/pdb/data/lig_conf_1.pdb similarity index 100% rename from biopandas/pdb/tests/data/lig_conf_1.pdb rename to tests/pdb/data/lig_conf_1.pdb diff --git a/biopandas/pdb/tests/data/lig_conf_2.pdb b/tests/pdb/data/lig_conf_2.pdb similarity index 100% rename from biopandas/pdb/tests/data/lig_conf_2.pdb rename to tests/pdb/data/lig_conf_2.pdb diff --git a/biopandas/pdb/tests/test_amino3to1.py b/tests/pdb/test_amino3to1.py similarity index 94% rename from biopandas/pdb/tests/test_amino3to1.py rename to tests/pdb/test_amino3to1.py index cabc9e4..276e2e3 100644 --- a/biopandas/pdb/tests/test_amino3to1.py +++ b/tests/pdb/test_amino3to1.py @@ -4,16 +4,23 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import numpy as np + +import tests.pdb.data from biopandas.pdb import PandasPdb +TEST_DATA = pkg_resources.files(tests.pdb.data) + def test_defaults(): - TESTDATA_1t48 = os.path.join( - os.path.dirname(__file__), "data", "1t48_995.pdb" - ) + TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48_995.pdb")) p1t48 = PandasPdb() p1t48.read_pdb(TESTDATA_1t48) expect_res = [ @@ -149,9 +156,7 @@ def test_defaults(): def test_sameindex(): - TESTDATA_1t48 = os.path.join( - os.path.dirname(__file__), "data", "1t48_995.pdb" - ) + TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48_995.pdb")) p1t48 = PandasPdb() p1t48.read_pdb(TESTDATA_1t48) print(p1t48) @@ -290,9 +295,7 @@ def test_sameindex(): def test_multichain(): - TESTDATA_5mtn = os.path.join( - os.path.dirname(__file__), "data", "5mtn_multichain.pdb" - ) + TESTDATA_5mtn = str(TEST_DATA.joinpath("5mtn_multichain.pdb")) mtn = PandasPdb() mtn.read_pdb(TESTDATA_5mtn) expect_res_a = [ @@ -500,8 +503,7 @@ def test_multichain(): def test_pdb_with_insertion_codes(): - - PDB_2D7T_PATH = os.path.join(os.path.dirname(__file__), "data", "2d7t.pdb") + PDB_2D7T_PATH = str(TEST_DATA.joinpath("2d7t.pdb")) ppdb = PandasPdb().read_pdb(PDB_2D7T_PATH) sequence = ppdb.amino3to1() diff --git a/biopandas/pdb/tests/test_assign_df.py b/tests/pdb/test_assign_df.py similarity index 60% rename from biopandas/pdb/tests/test_assign_df.py rename to tests/pdb/test_assign_df.py index f339609..84bb93c 100644 --- a/biopandas/pdb/tests/test_assign_df.py +++ b/tests/pdb/test_assign_df.py @@ -4,17 +4,24 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources + +import tests.pdb.data from biopandas.pdb import PandasPdb -from biopandas.testutils import assert_raises +from tests.testutils import assert_raises + +TEST_DATA = pkg_resources.files(tests.pdb.data) -TESTDATA_FILENAME = os.path.join(os.path.dirname(__file__), "data", "3eiy.pdb") +TESTDATA_FILENAME = str(TEST_DATA.joinpath("3eiy.pdb")) def test_overwrite_df(): - data_path = os.path.join(os.path.dirname(__file__), "data", "3eiy.pdb") - pdb = PandasPdb().read_pdb(data_path) + pdb = PandasPdb().read_pdb(TESTDATA_FILENAME) def overwrite(): pdb.df = "bla" diff --git a/biopandas/pdb/tests/test_distance.py b/tests/pdb/test_distance.py similarity index 76% rename from biopandas/pdb/tests/test_distance.py rename to tests/pdb/test_distance.py index aec7f2e..4c92f2c 100644 --- a/biopandas/pdb/tests/test_distance.py +++ b/tests/pdb/test_distance.py @@ -4,16 +4,23 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import pandas as pd + +import tests.pdb.data from biopandas.pdb import PandasPdb +TEST_DATA = pkg_resources.files(tests.pdb.data) + def test_equal(): - TESTDATA_1t48 = os.path.join( - os.path.dirname(__file__), "data", "1t48_995.pdb" - ) + TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48_995.pdb")) p1t48 = PandasPdb() p1t48.read_pdb(TESTDATA_1t48) @@ -27,9 +34,7 @@ def test_equal(): def test_deprecated_str_arg(): - TESTDATA_1t48 = os.path.join( - os.path.dirname(__file__), "data", "1t48_995.pdb" - ) + TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48_995.pdb")) p1t48 = PandasPdb() p1t48.read_pdb(TESTDATA_1t48) @@ -43,9 +48,7 @@ def test_deprecated_str_arg(): def test_use_external_df(): - TESTDATA_1t48 = os.path.join( - os.path.dirname(__file__), "data", "1t48_995.pdb" - ) + TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48_995.pdb")) p1t48 = PandasPdb() p1t48.read_pdb(TESTDATA_1t48) diff --git a/biopandas/pdb/tests/test_gyradius.py b/tests/pdb/test_gyradius.py similarity index 86% rename from biopandas/pdb/tests/test_gyradius.py rename to tests/pdb/test_gyradius.py index ef4f4c8..7bba7a5 100644 --- a/biopandas/pdb/tests/test_gyradius.py +++ b/tests/pdb/test_gyradius.py @@ -4,12 +4,22 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os + +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import pytest + +import tests.pdb.data from biopandas.pdb import PandasPdb -TESTDATA_1t48 = os.path.join(os.path.dirname(__file__), "data", "1t48_995.pdb") +TEST_DATA = pkg_resources.files(tests.pdb.data) + +TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48_995.pdb")) p1t48 = PandasPdb() p1t48.read_pdb(TESTDATA_1t48) diff --git a/biopandas/pdb/tests/test_impute.py b/tests/pdb/test_impute.py similarity index 81% rename from biopandas/pdb/tests/test_impute.py rename to tests/pdb/test_impute.py index 6035450..d188ef8 100644 --- a/biopandas/pdb/tests/test_impute.py +++ b/tests/pdb/test_impute.py @@ -5,13 +5,20 @@ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources + +import tests.pdb.data from biopandas.pdb import PandasPdb -TESTDATA_FILENAME = os.path.join( - os.path.dirname(__file__), "data", "3eiy_stripped_no_ele.pdb" -) +TEST_DATA = pkg_resources.files(tests.pdb.data) + + +TESTDATA_FILENAME = str(TEST_DATA.joinpath("3eiy_stripped_no_ele.pdb")) ppdb = PandasPdb() ppdb.read_pdb(TESTDATA_FILENAME) diff --git a/biopandas/pdb/tests/test_multiple_models.py b/tests/pdb/test_multiple_models.py similarity index 78% rename from biopandas/pdb/tests/test_multiple_models.py rename to tests/pdb/test_multiple_models.py index 85f0126..36e2780 100644 --- a/biopandas/pdb/tests/test_multiple_models.py +++ b/tests/pdb/test_multiple_models.py @@ -4,11 +4,19 @@ # License: BSD 3 clause # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources + +import tests.pdb.data from biopandas.pdb import PandasPdb -TESTDATA_FILENAME = os.path.join(os.path.dirname(__file__), "data", "2jyf.pdb") +TEST_DATA = pkg_resources.files(tests.pdb.data) + +TESTDATA_FILENAME = str(TEST_DATA.joinpath("2jyf.pdb")) def test_get_index_df(): diff --git a/biopandas/pdb/tests/test_read_pdb.py b/tests/pdb/test_read_pdb.py similarity index 92% rename from biopandas/pdb/tests/test_read_pdb.py rename to tests/pdb/test_read_pdb.py index 4477830..abb5cdc 100644 --- a/biopandas/pdb/tests/test_read_pdb.py +++ b/tests/pdb/test_read_pdb.py @@ -5,29 +5,30 @@ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources from urllib.error import HTTPError import numpy as np import pandas as pd import pytest + +import tests.pdb.data from biopandas.pdb import PandasPdb -from biopandas.testutils import assert_raises - -TESTDATA_FILENAME = os.path.join(os.path.dirname(__file__), "data", "3eiy.pdb") -TESTDATA_FILENAME2 = os.path.join( - os.path.dirname(__file__), "data", "4eiy_anisouchunk.pdb" -) -TESTDATA_FILENAME_GZ = os.path.join( - os.path.dirname(__file__), "data", "3eiy.pdb.gz" -) -TESTDATA_FILENAME_AF2_V4 = os.path.join( - os.path.dirname(__file__), "data", "AF-Q5VSL9-F1-model_v4.pdb" -) - -TESTDATA_FILENAME_AF2_V3 = os.path.join( - os.path.dirname(__file__), "data", "AF-Q5VSL9-F1-model_v3.pdb" -) +from tests.testutils import assert_raises + +TEST_DATA = pkg_resources.files(tests.pdb.data) + +TESTDATA_FILENAME = str(TEST_DATA.joinpath("3eiy.pdb")) +TESTDATA_FILENAME2 = str(TEST_DATA.joinpath("4eiy_anisouchunk.pdb")) +TESTDATA_FILENAME_GZ = str(TEST_DATA.joinpath("3eiy.pdb.gz")) +TESTDATA_FILENAME_AF2_V4 = str(TEST_DATA.joinpath("AF-Q5VSL9-F1-model_v4.pdb")) + +TESTDATA_FILENAME_AF2_V3 = str(TEST_DATA.joinpath("AF-Q5VSL9-F1-model_v3.pdb")) ATOM_DF_COLUMNS = [ "record_name", diff --git a/biopandas/pdb/tests/test_rmsd.py b/tests/pdb/test_rmsd.py similarity index 77% rename from biopandas/pdb/tests/test_rmsd.py rename to tests/pdb/test_rmsd.py index 88c142b..578d1b8 100644 --- a/biopandas/pdb/tests/test_rmsd.py +++ b/tests/pdb/test_rmsd.py @@ -4,23 +4,26 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import pytest + +import tests.pdb.data from biopandas.pdb import PandasPdb -TESTDATA_1t48 = os.path.join(os.path.dirname(__file__), "data", "1t48_995.pdb") -TESTDATA_1t49 = os.path.join(os.path.dirname(__file__), "data", "1t49_995.pdb") -TESTDATA_lig1 = os.path.join( - os.path.dirname(__file__), "data", "lig_conf_1.pdb" -) -TESTDATA_lig2 = os.path.join( - os.path.dirname(__file__), "data", "lig_conf_2.pdb" -) - -TESTDATA_rna = os.path.join( - os.path.dirname(__file__), "data", "1ehz-rna_short.pdb" -) +TEST_DATA = pkg_resources.files(tests.pdb.data) + +TESTDATA_1t48 = str(TEST_DATA.joinpath("1t48_995.pdb")) +TESTDATA_1t49 = str(TEST_DATA.joinpath("1t49_995.pdb")) +TESTDATA_lig1 = str(TEST_DATA.joinpath("lig_conf_1.pdb")) +TESTDATA_lig2 = str(TEST_DATA.joinpath("lig_conf_2.pdb")) + +TESTDATA_rna = str(TEST_DATA.joinpath("1ehz-rna_short.pdb")) p1t48 = PandasPdb() p1t48.read_pdb(TESTDATA_1t48) diff --git a/biopandas/pdb/tests/test_write_pdb.py b/tests/pdb/test_write_pdb.py similarity index 90% rename from biopandas/pdb/tests/test_write_pdb.py rename to tests/pdb/test_write_pdb.py index 352e51b..f16e5ad 100644 --- a/biopandas/pdb/tests/test_write_pdb.py +++ b/tests/pdb/test_write_pdb.py @@ -4,21 +4,27 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import os import warnings import pandas as pd + +import tests.pdb.data from biopandas.pdb import PandasPdb -TESTDATA_FILENAME = os.path.join(os.path.dirname(__file__), "data", "3eiy.pdb") -TESTDATA_FILENAME2 = os.path.join( - os.path.dirname(__file__), "data", "4eiy_anisouchunk.pdb" -) -TESTDATA_FILENAME3 = os.path.join( - os.path.dirname(__file__), "data", "5mtn_multichain.pdb" -) -OUTFILE = os.path.join(os.path.dirname(__file__), "data", "tmp.pdb") -OUTFILE_GZ = os.path.join(os.path.dirname(__file__), "data", "tmp.pdb.gz") +TEST_DATA = pkg_resources.files(tests.pdb.data) + +TESTDATA_FILENAME = str(TEST_DATA.joinpath("3eiy.pdb")) +TESTDATA_FILENAME2 = str(TEST_DATA.joinpath("4eiy_anisouchunk.pdb")) +TESTDATA_FILENAME3 = str(TEST_DATA.joinpath("5mtn_multichain.pdb")) +OUTFILE = str(TEST_DATA.joinpath("tmp.pdb")) +OUTFILE_GZ = str(TEST_DATA.joinpath("tmp.pdb.gz")) hetatm = "" with open(TESTDATA_FILENAME, "r") as f: diff --git a/biopandas/testutils/__init__.py b/tests/testutils/__init__.py similarity index 100% rename from biopandas/testutils/__init__.py rename to tests/testutils/__init__.py diff --git a/biopandas/testutils/testutils.py b/tests/testutils/testutils.py similarity index 94% rename from biopandas/testutils/testutils.py rename to tests/testutils/testutils.py index 6d71643..4560679 100644 --- a/biopandas/testutils/testutils.py +++ b/tests/testutils/testutils.py @@ -15,7 +15,8 @@ def assertMultiLineEqual(first, second, preserve_newline=True, msg=None): if first != second: message = "".join( difflib.ndiff( - first.splitlines(preserve_newline), second.splitlines(preserve_newline) + first.splitlines(preserve_newline), + second.splitlines(preserve_newline), ) ) if msg: