From 7c1c146589b5cd5d155c60b73fe65a2541bbc0b6 Mon Sep 17 00:00:00 2001 From: Grigorev Rostislav Date: Sat, 20 Jul 2024 13:50:15 +0200 Subject: [PATCH 1/6] move tests to dir and rewrite paths --- {biopandas/mmcif/tests => tests}/__init__.py | 0 .../mmtf/tests => tests/mmcif}/__init__.py | 0 .../mmcif/tests => tests/mmcif}/data/1ehz.cif | 0 .../mmcif/tests => tests/mmcif}/data/1t48.cif | 0 .../mmcif/tests => tests/mmcif}/data/1t49.cif | 0 .../mmcif/tests => tests/mmcif}/data/2d7t.cif | 0 .../tests => tests/mmcif}/data/2jyf.cif.gz | Bin .../mmcif/tests => tests/mmcif}/data/3eiy.cif | 0 .../tests => tests/mmcif}/data/3eiy.cif.gz | Bin .../mmcif}/data/3eiy_stripped_ele.cif | 0 .../mmcif/tests => tests/mmcif}/data/4eiy.cif | 0 .../mmcif}/data/5mtn_multichain.cif | 0 .../mmcif}/data/AF-Q5VSL9-F1-model_v2.cif | 0 .../mmcif}/data/AF-Q5VSL9-F1-model_v3.cif | 0 .../mmcif}/data/AF-Q5VSL9-F1-model_v4.cif | 0 .../tests => tests/mmcif}/test_amino3to1.py | 24 +++++----- .../tests => tests/mmcif}/test_assign_df.py | 9 ++-- .../tests => tests/mmcif}/test_distance.py | 16 ++++--- .../mmcif}/test_multiple_models.py | 13 ++++-- .../tests => tests/mmcif}/test_read_mmcif.py | 42 +++++++----------- .../mmcif/tests => tests/mmcif}/test_rmsd.py | 20 +++++---- .../pdb/tests => tests/mmtf}/__init__.py | 0 .../mmtf/tests => tests/mmtf}/data/1ehz.mmtf | Bin .../mmtf/tests => tests/mmtf}/data/1t48.mmtf | Bin .../mmtf/tests => tests/mmtf}/data/1t49.mmtf | Bin .../mmtf/tests => tests/mmtf}/data/2d7t.mmtf | Bin .../mmtf/tests => tests/mmtf}/data/2jyf.mmtf | Bin .../mmtf/tests => tests/mmtf}/data/3eiy.mmtf | Bin .../tests => tests/mmtf}/data/3eiy.mmtf.gz | Bin .../mmtf/tests => tests/mmtf}/data/4CUP.mmtf | Bin .../mmtf/tests => tests/mmtf}/data/4eiy.mmtf | Bin .../mmtf/tests => tests/mmtf}/data/5mtn.mmtf | Bin .../tests => tests/mmtf}/test_amino3to1.py | 30 +++++-------- .../tests => tests/mmtf}/test_assign_df.py | 14 +++--- .../tests => tests/mmtf}/test_distance.py | 22 ++++----- .../mmtf}/test_multiple_models.py | 12 +++-- .../tests => tests/mmtf}/test_read_mmtf.py | 32 +++++-------- .../mmtf/tests => tests/mmtf}/test_rmsd.py | 20 +++++---- .../tests => tests/mmtf}/test_write_mmtf.py | 3 +- tests/mol2/__init__.py | 0 .../tests => tests/mol2}/data/1b5e_1.mol2 | 0 .../tests => tests/mol2}/data/1b5e_2.mol2 | 0 .../mol2}/data/40_mol2_files.mol2 | 0 .../mol2}/data/40_mol2_files.mol2.gz | Bin .../tests => tests/mol2}/data/empty_line.mol2 | 0 .../mol2/tests => tests/mol2}/test_mol2_io.py | 20 +++------ .../tests => tests/mol2}/test_pandas_mol2.py | 33 +++++++------- tests/pdb/__init__.py | 0 .../pdb}/data/1ehz-rna_short.pdb | 0 .../pdb/tests => tests/pdb}/data/1t48_995.pdb | 0 .../pdb/tests => tests/pdb}/data/1t49_995.pdb | 0 .../pdb/tests => tests/pdb}/data/2d7t.pdb | 0 .../pdb/tests => tests/pdb}/data/2jyf.pdb | 0 .../pdb/tests => tests/pdb}/data/3eiy.pdb | 0 .../pdb/tests => tests/pdb}/data/3eiy.pdb.gz | Bin .../pdb}/data/3eiy_stripped_no_ele.pdb | 0 .../pdb}/data/4eiy_anisouchunk.pdb | 0 .../pdb}/data/5mtn_multichain.pdb | 0 .../pdb}/data/AF-Q5VSL9-F1-model_v2.pdb | 0 .../pdb}/data/AF-Q5VSL9-F1-model_v3.pdb | 0 .../pdb}/data/AF-Q5VSL9-F1-model_v4.pdb | 0 .../tests => tests/pdb}/data/lig_conf_1.pdb | 0 .../tests => tests/pdb}/data/lig_conf_2.pdb | 0 .../pdb/tests => tests/pdb}/test_amino3to1.py | 29 +++++------- .../pdb/tests => tests/pdb}/test_assign_df.py | 12 ++--- .../pdb/tests => tests/pdb}/test_distance.py | 22 ++++----- .../pdb/tests => tests/pdb}/test_gyradius.py | 9 +++- .../pdb/tests => tests/pdb}/test_impute.py | 10 +++-- .../pdb}/test_multiple_models.py | 7 ++- .../pdb/tests => tests/pdb}/test_read_pdb.py | 32 ++++++------- .../pdb/tests => tests/pdb}/test_rmsd.py | 30 +++++-------- .../pdb/tests => tests/pdb}/test_write_pdb.py | 27 +++++------ {biopandas => tests}/testutils/__init__.py | 0 {biopandas => tests}/testutils/testutils.py | 0 74 files changed, 227 insertions(+), 261 deletions(-) rename {biopandas/mmcif/tests => tests}/__init__.py (100%) rename {biopandas/mmtf/tests => tests/mmcif}/__init__.py (100%) rename {biopandas/mmcif/tests => tests/mmcif}/data/1ehz.cif (100%) rename {biopandas/mmcif/tests => tests/mmcif}/data/1t48.cif (100%) rename {biopandas/mmcif/tests => tests/mmcif}/data/1t49.cif (100%) rename {biopandas/mmcif/tests => tests/mmcif}/data/2d7t.cif (100%) rename {biopandas/mmcif/tests => tests/mmcif}/data/2jyf.cif.gz (100%) rename {biopandas/mmcif/tests => tests/mmcif}/data/3eiy.cif (100%) rename {biopandas/mmcif/tests => tests/mmcif}/data/3eiy.cif.gz (100%) rename {biopandas/mmcif/tests => tests/mmcif}/data/3eiy_stripped_ele.cif (100%) rename {biopandas/mmcif/tests => tests/mmcif}/data/4eiy.cif (100%) rename {biopandas/mmcif/tests => tests/mmcif}/data/5mtn_multichain.cif (100%) rename {biopandas/mmcif/tests => tests/mmcif}/data/AF-Q5VSL9-F1-model_v2.cif (100%) rename {biopandas/mmcif/tests => tests/mmcif}/data/AF-Q5VSL9-F1-model_v3.cif (100%) rename {biopandas/mmcif/tests => tests/mmcif}/data/AF-Q5VSL9-F1-model_v4.cif (100%) rename {biopandas/mmcif/tests => tests/mmcif}/test_amino3to1.py (95%) rename {biopandas/mmcif/tests => tests/mmcif}/test_assign_df.py (75%) rename {biopandas/mmcif/tests => tests/mmcif}/test_distance.py (76%) rename {biopandas/mmcif/tests => tests/mmcif}/test_multiple_models.py (76%) rename {biopandas/mmcif/tests => tests/mmcif}/test_read_mmcif.py (91%) rename {biopandas/mmcif/tests => tests/mmcif}/test_rmsd.py (76%) rename {biopandas/pdb/tests => tests/mmtf}/__init__.py (100%) rename {biopandas/mmtf/tests => tests/mmtf}/data/1ehz.mmtf (100%) rename {biopandas/mmtf/tests => tests/mmtf}/data/1t48.mmtf (100%) rename {biopandas/mmtf/tests => tests/mmtf}/data/1t49.mmtf (100%) rename {biopandas/mmtf/tests => tests/mmtf}/data/2d7t.mmtf (100%) rename {biopandas/mmtf/tests => tests/mmtf}/data/2jyf.mmtf (100%) rename {biopandas/mmtf/tests => tests/mmtf}/data/3eiy.mmtf (100%) rename {biopandas/mmtf/tests => tests/mmtf}/data/3eiy.mmtf.gz (100%) rename {biopandas/mmtf/tests => tests/mmtf}/data/4CUP.mmtf (100%) rename {biopandas/mmtf/tests => tests/mmtf}/data/4eiy.mmtf (100%) rename {biopandas/mmtf/tests => tests/mmtf}/data/5mtn.mmtf (100%) rename {biopandas/mmtf/tests => tests/mmtf}/test_amino3to1.py (95%) rename {biopandas/mmtf/tests => tests/mmtf}/test_assign_df.py (68%) rename {biopandas/mmtf/tests => tests/mmtf}/test_distance.py (75%) rename {biopandas/mmtf/tests => tests/mmtf}/test_multiple_models.py (89%) rename {biopandas/mmtf/tests => tests/mmtf}/test_read_mmtf.py (83%) rename {biopandas/mmtf/tests => tests/mmtf}/test_rmsd.py (78%) rename {biopandas/mmtf/tests => tests/mmtf}/test_write_mmtf.py (99%) create mode 100644 tests/mol2/__init__.py rename {biopandas/mol2/tests => tests/mol2}/data/1b5e_1.mol2 (100%) rename {biopandas/mol2/tests => tests/mol2}/data/1b5e_2.mol2 (100%) rename {biopandas/mol2/tests => tests/mol2}/data/40_mol2_files.mol2 (100%) rename {biopandas/mol2/tests => tests/mol2}/data/40_mol2_files.mol2.gz (100%) rename {biopandas/mol2/tests => tests/mol2}/data/empty_line.mol2 (100%) rename {biopandas/mol2/tests => tests/mol2}/test_mol2_io.py (64%) rename {biopandas/mol2/tests => tests/mol2}/test_pandas_mol2.py (73%) create mode 100644 tests/pdb/__init__.py rename {biopandas/pdb/tests => tests/pdb}/data/1ehz-rna_short.pdb (100%) rename {biopandas/pdb/tests => tests/pdb}/data/1t48_995.pdb (100%) rename {biopandas/pdb/tests => tests/pdb}/data/1t49_995.pdb (100%) rename {biopandas/pdb/tests => tests/pdb}/data/2d7t.pdb (100%) rename {biopandas/pdb/tests => tests/pdb}/data/2jyf.pdb (100%) rename {biopandas/pdb/tests => tests/pdb}/data/3eiy.pdb (100%) rename {biopandas/pdb/tests => tests/pdb}/data/3eiy.pdb.gz (100%) rename {biopandas/pdb/tests => tests/pdb}/data/3eiy_stripped_no_ele.pdb (100%) rename {biopandas/pdb/tests => tests/pdb}/data/4eiy_anisouchunk.pdb (100%) rename {biopandas/pdb/tests => tests/pdb}/data/5mtn_multichain.pdb (100%) rename {biopandas/pdb/tests => tests/pdb}/data/AF-Q5VSL9-F1-model_v2.pdb (100%) rename {biopandas/pdb/tests => tests/pdb}/data/AF-Q5VSL9-F1-model_v3.pdb (100%) rename {biopandas/pdb/tests => tests/pdb}/data/AF-Q5VSL9-F1-model_v4.pdb (100%) rename {biopandas/pdb/tests => tests/pdb}/data/lig_conf_1.pdb (100%) rename {biopandas/pdb/tests => tests/pdb}/data/lig_conf_2.pdb (100%) rename {biopandas/pdb/tests => tests/pdb}/test_amino3to1.py (92%) rename {biopandas/pdb/tests => tests/pdb}/test_assign_df.py (67%) rename {biopandas/pdb/tests => tests/pdb}/test_distance.py (74%) rename {biopandas/pdb/tests => tests/pdb}/test_gyradius.py (90%) rename {biopandas/pdb/tests => tests/pdb}/test_impute.py (86%) rename {biopandas/pdb/tests => tests/pdb}/test_multiple_models.py (85%) rename {biopandas/pdb/tests => tests/pdb}/test_read_pdb.py (91%) rename {biopandas/pdb/tests => tests/pdb}/test_rmsd.py (71%) rename {biopandas/pdb/tests => tests/pdb}/test_write_pdb.py (88%) rename {biopandas => tests}/testutils/__init__.py (100%) rename {biopandas => tests}/testutils/testutils.py (100%) 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 95% rename from biopandas/mmcif/tests/test_amino3to1.py rename to tests/mmcif/test_amino3to1.py index 83a671c..7935b22 100644 --- a/biopandas/mmcif/tests/test_amino3to1.py +++ b/tests/mmcif/test_amino3to1.py @@ -4,14 +4,18 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +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 +313,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 +612,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 = [ @@ -805,12 +807,8 @@ def test_multichain(): expect_chain = ["A" for _ in range(88)] + ["B" for _ in range(94)] got_chain = list(transl["auth_asym_id"].values) - got_res_a = list( - transl.loc[transl["auth_asym_id"] == "A", "auth_comp_id"].values - ) - got_res_b = list( - transl.loc[transl["auth_asym_id"] == "B", "auth_comp_id"].values - ) + got_res_a = list(transl.loc[transl["auth_asym_id"] == "A", "auth_comp_id"].values) + got_res_b = list(transl.loc[transl["auth_asym_id"] == "B", "auth_comp_id"].values) assert expect_chain == got_chain assert expect_res_a == got_res_a @@ -818,7 +816,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 75% rename from biopandas/mmcif/tests/test_assign_df.py rename to tests/mmcif/test_assign_df.py index 2706637..e79bf1f 100644 --- a/biopandas/mmcif/tests/test_assign_df.py +++ b/tests/mmcif/test_assign_df.py @@ -4,16 +4,17 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +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 76% rename from biopandas/mmcif/tests/test_distance.py rename to tests/mmcif/test_distance.py index e7cd116..120ff6e 100644 --- a/biopandas/mmcif/tests/test_distance.py +++ b/tests/mmcif/test_distance.py @@ -4,14 +4,18 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +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 +29,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,14 +43,12 @@ 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) new_df = p1t48.df["ATOM"].iloc[:-1, :].copy() dist = PandasMmcif.distance_df(df=new_df, xyz=(70.785, 15.477, 23.359)) - expect = pd.Series( - [2.533259, 1.520502, 0.000000, 1.257597], index=[12, 13, 14, 15] - ) + expect = pd.Series([2.533259, 1.520502, 0.000000, 1.257597], index=[12, 13, 14, 15]) assert dist[dist < 3].all() == expect.all() diff --git a/biopandas/mmcif/tests/test_multiple_models.py b/tests/mmcif/test_multiple_models.py similarity index 76% rename from biopandas/mmcif/tests/test_multiple_models.py rename to tests/mmcif/test_multiple_models.py index e8cf496..c61d26d 100644 --- a/biopandas/mmcif/tests/test_multiple_models.py +++ b/tests/mmcif/test_multiple_models.py @@ -4,17 +4,22 @@ # License: BSD 3 clause # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +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 @@ -27,4 +32,6 @@ 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 91% rename from biopandas/mmcif/tests/test_read_mmcif.py rename to tests/mmcif/test_read_mmcif.py index bfba806..e2c2cbe 100644 --- a/biopandas/mmcif/tests/test_read_mmcif.py +++ b/tests/mmcif/test_read_mmcif.py @@ -5,36 +5,30 @@ # Code Repository: https://github.com/rasbt/biopandas -import os +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 -TESTDATA_FILENAME = os.path.join(os.path.dirname(__file__), "data", "3eiy.cif") +TEST_DATA = pkg_resources.files(tests.mmcif.data) + +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", @@ -337,9 +331,7 @@ def test_mmcif_pdb_conversion(): ) assert_frame_equal( pdb.df["HETATM"].drop(columns=["line_idx"]), - mmcif_pdb.df["HETATM"] - .drop(columns=["line_idx"]) - .reset_index(drop=True), + mmcif_pdb.df["HETATM"].drop(columns=["line_idx"]).reset_index(drop=True), ) # single chain test @@ -353,7 +345,5 @@ def test_mmcif_pdb_conversion(): ) assert_frame_equal( pdb.df["HETATM"].drop(columns=["line_idx"]), - mmcif_pdb.df["HETATM"] - .drop(columns=["line_idx"]) - .reset_index(drop=True), + mmcif_pdb.df["HETATM"].drop(columns=["line_idx"]).reset_index(drop=True), ) diff --git a/biopandas/mmcif/tests/test_rmsd.py b/tests/mmcif/test_rmsd.py similarity index 76% rename from biopandas/mmcif/tests/test_rmsd.py rename to tests/mmcif/test_rmsd.py index 054f3b2..83cc246 100644 --- a/biopandas/mmcif/tests/test_rmsd.py +++ b/tests/mmcif/test_rmsd.py @@ -4,17 +4,21 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +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) @@ -48,9 +52,7 @@ def test_invalid_query(): def test_protein(): - r = PandasMmcif.rmsd( - p1t48.df["ATOM"], p1t49.df["ATOM"], s="c-alpha", invert=False - ) + r = PandasMmcif.rmsd(p1t48.df["ATOM"], p1t49.df["ATOM"], s="c-alpha", invert=False) assert r == 0.4923, r 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 95% rename from biopandas/mmtf/tests/test_amino3to1.py rename to tests/mmtf/test_amino3to1.py index 081265f..b87c299 100644 --- a/biopandas/mmtf/tests/test_amino3to1.py +++ b/tests/mmtf/test_amino3to1.py @@ -4,16 +4,18 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +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 +323,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 +632,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 = [ @@ -829,12 +827,8 @@ def test_multichain(): expect_chain = ["A" for _ in range(88)] + ["B" for _ in range(94)] got_chain = list(transl["chain_id"].values) - got_res_a = list( - transl.loc[transl["chain_id"] == "A", "residue_name"].values - ) - got_res_b = list( - transl.loc[transl["chain_id"] == "B", "residue_name"].values - ) + got_res_a = list(transl.loc[transl["chain_id"] == "A", "residue_name"].values) + got_res_b = list(transl.loc[transl["chain_id"] == "B", "residue_name"].values) assert expect_chain == got_chain assert expect_res_a == got_res_a @@ -842,9 +836,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 68% rename from biopandas/mmtf/tests/test_assign_df.py rename to tests/mmtf/test_assign_df.py index f9dd1bd..0f17858 100644 --- a/biopandas/mmtf/tests/test_assign_df.py +++ b/tests/mmtf/test_assign_df.py @@ -4,19 +4,19 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +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 -TESTDATA_FILENAME = os.path.join( - os.path.dirname(__file__), "data", "3eiy.mmtf" -) +TEST_DATA = pkg_resources.files(tests.mmtf.data) + +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 75% rename from biopandas/mmtf/tests/test_distance.py rename to tests/mmtf/test_distance.py index 96291e3..2af9a5c 100644 --- a/biopandas/mmtf/tests/test_distance.py +++ b/tests/mmtf/test_distance.py @@ -4,16 +4,18 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +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 +29,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,16 +43,12 @@ 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) new_df = p1t48.df["ATOM"].iloc[:-1, :].copy() dist = PandasMmtf.distance_df(df=new_df, xyz=(70.785, 15.477, 23.359)) - expect = pd.Series( - [2.533259, 1.520502, 0.000000, 1.257597], index=[12, 13, 14, 15] - ) + expect = pd.Series([2.533259, 1.520502, 0.000000, 1.257597], index=[12, 13, 14, 15]) assert dist[dist < 3].all() == expect.all() diff --git a/biopandas/mmtf/tests/test_multiple_models.py b/tests/mmtf/test_multiple_models.py similarity index 89% rename from biopandas/mmtf/tests/test_multiple_models.py rename to tests/mmtf/test_multiple_models.py index 30be1cc..cffe774 100644 --- a/biopandas/mmtf/tests/test_multiple_models.py +++ b/tests/mmtf/test_multiple_models.py @@ -4,14 +4,18 @@ # License: BSD 3 clause # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas + +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 83% rename from biopandas/mmtf/tests/test_read_mmtf.py rename to tests/mmtf/test_read_mmtf.py index 045ff1d..f2cd4ba 100644 --- a/biopandas/mmtf/tests/test_read_mmtf.py +++ b/tests/mmtf/test_read_mmtf.py @@ -4,32 +4,24 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +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 78% rename from biopandas/mmtf/tests/test_rmsd.py rename to tests/mmtf/test_rmsd.py index 1131009..cbca792 100644 --- a/biopandas/mmtf/tests/test_rmsd.py +++ b/tests/mmtf/test_rmsd.py @@ -4,17 +4,21 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +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) @@ -51,9 +55,7 @@ def test_invalid_query(): def test_protein(): - r = PandasMmtf.rmsd( - p1t48.df["ATOM"], p1t49.df["ATOM"], s="c-alpha", invert=False - ) + r = PandasMmtf.rmsd(p1t48.df["ATOM"], p1t49.df["ATOM"], s="c-alpha", invert=False) assert r == 0.4785, r 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 64% rename from biopandas/mol2/tests/test_mol2_io.py rename to tests/mol2/test_mol2_io.py index b6c4c98..4d371c8 100644 --- a/biopandas/mol2/tests/test_mol2_io.py +++ b/tests/mol2/test_mol2_io.py @@ -4,29 +4,25 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +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." - ) + expect = "Wrong file format;" "allowed file formats are .mol2 and .mol2.gz." def run_code(): next(split_multimol2("40_mol2_files.pdb")) @@ -36,9 +32,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 73% rename from biopandas/mol2/tests/test_pandas_mol2.py rename to tests/mol2/test_pandas_mol2.py index ba88dd0..3bea78f 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,20 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +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,20 +46,17 @@ 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( - mol2_lines=mol2[1], mol2_code=mol2[0] - ) + pdmol = PandasMol2().read_mol2_from_list(mol2_lines=mol2[1], mol2_code=mol2[0]) assert pdmol.df.shape == (65, 9) assert pdmol.code == "ZINC38611810" 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 +66,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 +81,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 92% rename from biopandas/pdb/tests/test_amino3to1.py rename to tests/pdb/test_amino3to1.py index cabc9e4..e91170f 100644 --- a/biopandas/pdb/tests/test_amino3to1.py +++ b/tests/pdb/test_amino3to1.py @@ -4,16 +4,18 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +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 +151,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 +290,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 = [ @@ -487,12 +485,8 @@ def test_multichain(): expect_chain = ["A" for _ in range(88)] + ["B" for _ in range(94)] got_chain = list(transl["chain_id"].values) - got_res_a = list( - transl.loc[transl["chain_id"] == "A", "residue_name"].values - ) - got_res_b = list( - transl.loc[transl["chain_id"] == "B", "residue_name"].values - ) + got_res_a = list(transl.loc[transl["chain_id"] == "A", "residue_name"].values) + got_res_b = list(transl.loc[transl["chain_id"] == "B", "residue_name"].values) assert expect_chain == got_chain assert expect_res_a == got_res_a @@ -500,8 +494,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 67% rename from biopandas/pdb/tests/test_assign_df.py rename to tests/pdb/test_assign_df.py index f339609..630b1cb 100644 --- a/biopandas/pdb/tests/test_assign_df.py +++ b/tests/pdb/test_assign_df.py @@ -4,17 +4,19 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +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 -TESTDATA_FILENAME = os.path.join(os.path.dirname(__file__), "data", "3eiy.pdb") +TEST_DATA = pkg_resources.files(tests.pdb.data) + +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 74% rename from biopandas/pdb/tests/test_distance.py rename to tests/pdb/test_distance.py index aec7f2e..ebadb1c 100644 --- a/biopandas/pdb/tests/test_distance.py +++ b/tests/pdb/test_distance.py @@ -4,16 +4,18 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +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 +29,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,16 +43,12 @@ 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) new_df = p1t48.df["ATOM"].iloc[:-1, :].copy() dist = PandasPdb.distance_df(df=new_df, xyz=(70.785, 15.477, 23.359)) - expect = pd.Series( - [2.533259, 1.520502, 0.000000, 1.257597], index=[12, 13, 14, 15] - ) + expect = pd.Series([2.533259, 1.520502, 0.000000, 1.257597], index=[12, 13, 14, 15]) assert dist[dist < 3].all() == expect.all() diff --git a/biopandas/pdb/tests/test_gyradius.py b/tests/pdb/test_gyradius.py similarity index 90% rename from biopandas/pdb/tests/test_gyradius.py rename to tests/pdb/test_gyradius.py index ef4f4c8..43399e7 100644 --- a/biopandas/pdb/tests/test_gyradius.py +++ b/tests/pdb/test_gyradius.py @@ -4,12 +4,17 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os + +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 86% rename from biopandas/pdb/tests/test_impute.py rename to tests/pdb/test_impute.py index 6035450..ef7f37f 100644 --- a/biopandas/pdb/tests/test_impute.py +++ b/tests/pdb/test_impute.py @@ -5,13 +5,15 @@ # Code Repository: https://github.com/rasbt/biopandas -import os +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 85% rename from biopandas/pdb/tests/test_multiple_models.py rename to tests/pdb/test_multiple_models.py index 85f0126..6a2f2e7 100644 --- a/biopandas/pdb/tests/test_multiple_models.py +++ b/tests/pdb/test_multiple_models.py @@ -4,11 +4,14 @@ # License: BSD 3 clause # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +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 91% rename from biopandas/pdb/tests/test_read_pdb.py rename to tests/pdb/test_read_pdb.py index 4477830..d388bf2 100644 --- a/biopandas/pdb/tests/test_read_pdb.py +++ b/tests/pdb/test_read_pdb.py @@ -5,29 +5,26 @@ # Code Repository: https://github.com/rasbt/biopandas +import importlib.resources as pkg_resources import os 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", @@ -103,8 +100,7 @@ def test__read_pdb_raises(): Test if ValueError is raised for wrong file formats.""" expect = ( - "Wrong file format; allowed file formats are " - ".pdb, .pdb.gz, .ent, .ent.gz" + "Wrong file format; allowed file formats are " ".pdb, .pdb.gz, .ent, .ent.gz" ) def run_code_1(): diff --git a/biopandas/pdb/tests/test_rmsd.py b/tests/pdb/test_rmsd.py similarity index 71% rename from biopandas/pdb/tests/test_rmsd.py rename to tests/pdb/test_rmsd.py index 88c142b..1ed1cf0 100644 --- a/biopandas/pdb/tests/test_rmsd.py +++ b/tests/pdb/test_rmsd.py @@ -4,23 +4,21 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import os +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" -) +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 = os.path.join( - os.path.dirname(__file__), "data", "1ehz-rna_short.pdb" -) +TESTDATA_rna = str(TEST_DATA.joinpath("1ehz-rna_short.pdb")) p1t48 = PandasPdb() p1t48.read_pdb(TESTDATA_1t48) @@ -54,9 +52,7 @@ def test_invalid_query(): def test_protein(): - r = PandasPdb.rmsd( - p1t48.df["ATOM"], p1t49.df["ATOM"], s="c-alpha", invert=False - ) + r = PandasPdb.rmsd(p1t48.df["ATOM"], p1t49.df["ATOM"], s="c-alpha", invert=False) assert r == 0.4785, r @@ -70,9 +66,7 @@ def test_rna_and_nonmatching_indices(): def test_ligand(): - r = PandasPdb.rmsd( - pl1.df["HETATM"], pl2.df["HETATM"], s="hydrogen", invert=True - ) + r = PandasPdb.rmsd(pl1.df["HETATM"], pl2.df["HETATM"], s="hydrogen", invert=True) assert r == 1.9959, r diff --git a/biopandas/pdb/tests/test_write_pdb.py b/tests/pdb/test_write_pdb.py similarity index 88% rename from biopandas/pdb/tests/test_write_pdb.py rename to tests/pdb/test_write_pdb.py index 352e51b..6e79805 100644 --- a/biopandas/pdb/tests/test_write_pdb.py +++ b/tests/pdb/test_write_pdb.py @@ -4,21 +4,22 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas +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: @@ -45,9 +46,7 @@ def test_defaults(): def test_nonexpected_column(): ppdb = PandasPdb() ppdb.read_pdb(TESTDATA_FILENAME) - ppdb.df["HETATM"]["test"] = pd.Series( - "test", index=ppdb.df["HETATM"].index - ) + ppdb.df["HETATM"]["test"] = pd.Series("test", index=ppdb.df["HETATM"].index) with warnings.catch_warnings(record=True) as w: ppdb.to_pdb(path=OUTFILE, records=["HETATM"]) with open(OUTFILE, "r") as f: @@ -153,6 +152,4 @@ def test_b_factor_shift(): assert tmp_df[ tmp_df["element_symbol"].isnull() | (tmp_df["element_symbol"] == "") ].empty - assert not tmp_df[ - tmp_df["blank_4"].isnull() | (tmp_df["blank_4"] == "") - ].empty + assert not tmp_df[tmp_df["blank_4"].isnull() | (tmp_df["blank_4"] == "")].empty 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 100% rename from biopandas/testutils/testutils.py rename to tests/testutils/testutils.py From 19c3b20b167b81e8ae57168b796ae7944f9df9b9 Mon Sep 17 00:00:00 2001 From: Grigorev Rostislav Date: Sat, 20 Jul 2024 14:13:00 +0200 Subject: [PATCH 2/6] add python 3.7 test run support --- tests/mmcif/test_amino3to1.py | 7 ++++++- tests/mmcif/test_assign_df.py | 7 ++++++- tests/mmcif/test_distance.py | 7 ++++++- tests/mmcif/test_multiple_models.py | 7 ++++++- tests/mmcif/test_read_mmcif.py | 7 ++++++- tests/mmcif/test_rmsd.py | 7 ++++++- tests/mmtf/test_amino3to1.py | 7 ++++++- tests/mmtf/test_assign_df.py | 7 ++++++- tests/mmtf/test_distance.py | 7 ++++++- tests/mmtf/test_multiple_models.py | 7 ++++++- tests/mmtf/test_read_mmtf.py | 7 ++++++- tests/mmtf/test_rmsd.py | 7 ++++++- tests/mol2/test_mol2_io.py | 7 ++++++- tests/mol2/test_pandas_mol2.py | 7 ++++++- tests/pdb/test_amino3to1.py | 7 ++++++- tests/pdb/test_assign_df.py | 7 ++++++- tests/pdb/test_distance.py | 7 ++++++- tests/pdb/test_gyradius.py | 7 ++++++- tests/pdb/test_impute.py | 7 ++++++- tests/pdb/test_multiple_models.py | 7 ++++++- tests/pdb/test_read_pdb.py | 7 ++++++- tests/pdb/test_rmsd.py | 7 ++++++- tests/pdb/test_write_pdb.py | 7 ++++++- 23 files changed, 138 insertions(+), 23 deletions(-) diff --git a/tests/mmcif/test_amino3to1.py b/tests/mmcif/test_amino3to1.py index 7935b22..27a369b 100644 --- a/tests/mmcif/test_amino3to1.py +++ b/tests/mmcif/test_amino3to1.py @@ -4,7 +4,12 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +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 diff --git a/tests/mmcif/test_assign_df.py b/tests/mmcif/test_assign_df.py index e79bf1f..b012d60 100644 --- a/tests/mmcif/test_assign_df.py +++ b/tests/mmcif/test_assign_df.py @@ -4,7 +4,12 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +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 diff --git a/tests/mmcif/test_distance.py b/tests/mmcif/test_distance.py index 120ff6e..341079d 100644 --- a/tests/mmcif/test_distance.py +++ b/tests/mmcif/test_distance.py @@ -4,7 +4,12 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +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 diff --git a/tests/mmcif/test_multiple_models.py b/tests/mmcif/test_multiple_models.py index c61d26d..5dba612 100644 --- a/tests/mmcif/test_multiple_models.py +++ b/tests/mmcif/test_multiple_models.py @@ -4,7 +4,12 @@ # License: BSD 3 clause # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +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 diff --git a/tests/mmcif/test_read_mmcif.py b/tests/mmcif/test_read_mmcif.py index e2c2cbe..94b3db2 100644 --- a/tests/mmcif/test_read_mmcif.py +++ b/tests/mmcif/test_read_mmcif.py @@ -5,7 +5,12 @@ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +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 diff --git a/tests/mmcif/test_rmsd.py b/tests/mmcif/test_rmsd.py index 83cc246..d636bd6 100644 --- a/tests/mmcif/test_rmsd.py +++ b/tests/mmcif/test_rmsd.py @@ -4,7 +4,12 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import pytest diff --git a/tests/mmtf/test_amino3to1.py b/tests/mmtf/test_amino3to1.py index b87c299..4b6c6d0 100644 --- a/tests/mmtf/test_amino3to1.py +++ b/tests/mmtf/test_amino3to1.py @@ -4,7 +4,12 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +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 diff --git a/tests/mmtf/test_assign_df.py b/tests/mmtf/test_assign_df.py index 0f17858..72d2363 100644 --- a/tests/mmtf/test_assign_df.py +++ b/tests/mmtf/test_assign_df.py @@ -4,7 +4,12 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +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 diff --git a/tests/mmtf/test_distance.py b/tests/mmtf/test_distance.py index 2af9a5c..8a2097b 100644 --- a/tests/mmtf/test_distance.py +++ b/tests/mmtf/test_distance.py @@ -4,7 +4,12 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +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 diff --git a/tests/mmtf/test_multiple_models.py b/tests/mmtf/test_multiple_models.py index cffe774..55ed818 100644 --- a/tests/mmtf/test_multiple_models.py +++ b/tests/mmtf/test_multiple_models.py @@ -5,7 +5,12 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import os from pandas.testing import assert_frame_equal diff --git a/tests/mmtf/test_read_mmtf.py b/tests/mmtf/test_read_mmtf.py index f2cd4ba..cba1b73 100644 --- a/tests/mmtf/test_read_mmtf.py +++ b/tests/mmtf/test_read_mmtf.py @@ -4,7 +4,12 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +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 diff --git a/tests/mmtf/test_rmsd.py b/tests/mmtf/test_rmsd.py index cbca792..1e81935 100644 --- a/tests/mmtf/test_rmsd.py +++ b/tests/mmtf/test_rmsd.py @@ -4,7 +4,12 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import pytest diff --git a/tests/mol2/test_mol2_io.py b/tests/mol2/test_mol2_io.py index 4d371c8..7cd2cbb 100644 --- a/tests/mol2/test_mol2_io.py +++ b/tests/mol2/test_mol2_io.py @@ -4,7 +4,12 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +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 diff --git a/tests/mol2/test_pandas_mol2.py b/tests/mol2/test_pandas_mol2.py index 3bea78f..ba4ffc1 100644 --- a/tests/mol2/test_pandas_mol2.py +++ b/tests/mol2/test_pandas_mol2.py @@ -6,7 +6,12 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +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 diff --git a/tests/pdb/test_amino3to1.py b/tests/pdb/test_amino3to1.py index e91170f..4012cb1 100644 --- a/tests/pdb/test_amino3to1.py +++ b/tests/pdb/test_amino3to1.py @@ -4,7 +4,12 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +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 diff --git a/tests/pdb/test_assign_df.py b/tests/pdb/test_assign_df.py index 630b1cb..84bb93c 100644 --- a/tests/pdb/test_assign_df.py +++ b/tests/pdb/test_assign_df.py @@ -4,7 +4,12 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +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 diff --git a/tests/pdb/test_distance.py b/tests/pdb/test_distance.py index ebadb1c..42ae05c 100644 --- a/tests/pdb/test_distance.py +++ b/tests/pdb/test_distance.py @@ -4,7 +4,12 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +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 diff --git a/tests/pdb/test_gyradius.py b/tests/pdb/test_gyradius.py index 43399e7..7bba7a5 100644 --- a/tests/pdb/test_gyradius.py +++ b/tests/pdb/test_gyradius.py @@ -5,7 +5,12 @@ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import pytest diff --git a/tests/pdb/test_impute.py b/tests/pdb/test_impute.py index ef7f37f..d188ef8 100644 --- a/tests/pdb/test_impute.py +++ b/tests/pdb/test_impute.py @@ -5,7 +5,12 @@ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +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 diff --git a/tests/pdb/test_multiple_models.py b/tests/pdb/test_multiple_models.py index 6a2f2e7..36e2780 100644 --- a/tests/pdb/test_multiple_models.py +++ b/tests/pdb/test_multiple_models.py @@ -4,7 +4,12 @@ # License: BSD 3 clause # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +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 diff --git a/tests/pdb/test_read_pdb.py b/tests/pdb/test_read_pdb.py index d388bf2..e535d92 100644 --- a/tests/pdb/test_read_pdb.py +++ b/tests/pdb/test_read_pdb.py @@ -5,7 +5,12 @@ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import os from urllib.error import HTTPError diff --git a/tests/pdb/test_rmsd.py b/tests/pdb/test_rmsd.py index 1ed1cf0..56e42cc 100644 --- a/tests/pdb/test_rmsd.py +++ b/tests/pdb/test_rmsd.py @@ -4,7 +4,12 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +import sys + +if sys.version_info >= (3, 9): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources import pytest diff --git a/tests/pdb/test_write_pdb.py b/tests/pdb/test_write_pdb.py index 6e79805..0770078 100644 --- a/tests/pdb/test_write_pdb.py +++ b/tests/pdb/test_write_pdb.py @@ -4,7 +4,12 @@ # Project Website: http://rasbt.github.io/biopandas/ # Code Repository: https://github.com/rasbt/biopandas -import importlib.resources as pkg_resources +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 From cd2044fb5cf01b0d26694cb7f4f3bb54b26a4755 Mon Sep 17 00:00:00 2001 From: Grigorev Rostislav Date: Sat, 20 Jul 2024 14:18:10 +0200 Subject: [PATCH 3/6] add importlib_resources to appveyor --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: From f988a19cdeb639dd8f29b5ff14daeb39fc0040fa Mon Sep 17 00:00:00 2001 From: Grigorev Rostislav Date: Sat, 20 Jul 2024 14:24:57 +0200 Subject: [PATCH 4/6] format files with 79 line length --- tests/mmcif/test_amino3to1.py | 8 ++++++-- tests/mmcif/test_distance.py | 4 +++- tests/mmcif/test_multiple_models.py | 8 ++++++-- tests/mmcif/test_read_mmcif.py | 8 ++++++-- tests/mmcif/test_rmsd.py | 4 +++- tests/mmtf/test_amino3to1.py | 8 ++++++-- tests/mmtf/test_distance.py | 4 +++- tests/mmtf/test_rmsd.py | 4 +++- tests/mol2/test_mol2_io.py | 4 +++- tests/mol2/test_pandas_mol2.py | 4 +++- tests/pdb/test_amino3to1.py | 8 ++++++-- tests/pdb/test_distance.py | 4 +++- tests/pdb/test_read_pdb.py | 4 ++-- tests/pdb/test_rmsd.py | 8 ++++++-- tests/pdb/test_write_pdb.py | 8 ++++++-- tests/testutils/testutils.py | 3 ++- 16 files changed, 67 insertions(+), 24 deletions(-) diff --git a/tests/mmcif/test_amino3to1.py b/tests/mmcif/test_amino3to1.py index 27a369b..1effebe 100644 --- a/tests/mmcif/test_amino3to1.py +++ b/tests/mmcif/test_amino3to1.py @@ -812,8 +812,12 @@ def test_multichain(): expect_chain = ["A" for _ in range(88)] + ["B" for _ in range(94)] got_chain = list(transl["auth_asym_id"].values) - got_res_a = list(transl.loc[transl["auth_asym_id"] == "A", "auth_comp_id"].values) - got_res_b = list(transl.loc[transl["auth_asym_id"] == "B", "auth_comp_id"].values) + got_res_a = list( + transl.loc[transl["auth_asym_id"] == "A", "auth_comp_id"].values + ) + got_res_b = list( + transl.loc[transl["auth_asym_id"] == "B", "auth_comp_id"].values + ) assert expect_chain == got_chain assert expect_res_a == got_res_a diff --git a/tests/mmcif/test_distance.py b/tests/mmcif/test_distance.py index 341079d..df45be9 100644 --- a/tests/mmcif/test_distance.py +++ b/tests/mmcif/test_distance.py @@ -55,5 +55,7 @@ def test_use_external_df(): new_df = p1t48.df["ATOM"].iloc[:-1, :].copy() dist = PandasMmcif.distance_df(df=new_df, xyz=(70.785, 15.477, 23.359)) - expect = pd.Series([2.533259, 1.520502, 0.000000, 1.257597], index=[12, 13, 14, 15]) + expect = pd.Series( + [2.533259, 1.520502, 0.000000, 1.257597], index=[12, 13, 14, 15] + ) assert dist[dist < 3].all() == expect.all() diff --git a/tests/mmcif/test_multiple_models.py b/tests/mmcif/test_multiple_models.py index 5dba612..084fd15 100644 --- a/tests/mmcif/test_multiple_models.py +++ b/tests/mmcif/test_multiple_models.py @@ -29,7 +29,10 @@ 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(): @@ -38,5 +41,6 @@ def test_get_models(): new_biopandas_structure = biopandas_structure.get_models(MODEL_INDICES) assert ( - new_biopandas_structure.df["ATOM"]["pdbx_PDB_model_num"].all() in MODEL_INDICES + new_biopandas_structure.df["ATOM"]["pdbx_PDB_model_num"].all() + in MODEL_INDICES ) diff --git a/tests/mmcif/test_read_mmcif.py b/tests/mmcif/test_read_mmcif.py index 94b3db2..e2a907b 100644 --- a/tests/mmcif/test_read_mmcif.py +++ b/tests/mmcif/test_read_mmcif.py @@ -336,7 +336,9 @@ def test_mmcif_pdb_conversion(): ) assert_frame_equal( pdb.df["HETATM"].drop(columns=["line_idx"]), - mmcif_pdb.df["HETATM"].drop(columns=["line_idx"]).reset_index(drop=True), + mmcif_pdb.df["HETATM"] + .drop(columns=["line_idx"]) + .reset_index(drop=True), ) # single chain test @@ -350,5 +352,7 @@ def test_mmcif_pdb_conversion(): ) assert_frame_equal( pdb.df["HETATM"].drop(columns=["line_idx"]), - mmcif_pdb.df["HETATM"].drop(columns=["line_idx"]).reset_index(drop=True), + mmcif_pdb.df["HETATM"] + .drop(columns=["line_idx"]) + .reset_index(drop=True), ) diff --git a/tests/mmcif/test_rmsd.py b/tests/mmcif/test_rmsd.py index d636bd6..0c21bbf 100644 --- a/tests/mmcif/test_rmsd.py +++ b/tests/mmcif/test_rmsd.py @@ -57,7 +57,9 @@ def test_invalid_query(): def test_protein(): - r = PandasMmcif.rmsd(p1t48.df["ATOM"], p1t49.df["ATOM"], s="c-alpha", invert=False) + r = PandasMmcif.rmsd( + p1t48.df["ATOM"], p1t49.df["ATOM"], s="c-alpha", invert=False + ) assert r == 0.4923, r diff --git a/tests/mmtf/test_amino3to1.py b/tests/mmtf/test_amino3to1.py index 4b6c6d0..ea0c51f 100644 --- a/tests/mmtf/test_amino3to1.py +++ b/tests/mmtf/test_amino3to1.py @@ -832,8 +832,12 @@ def test_multichain(): expect_chain = ["A" for _ in range(88)] + ["B" for _ in range(94)] got_chain = list(transl["chain_id"].values) - got_res_a = list(transl.loc[transl["chain_id"] == "A", "residue_name"].values) - got_res_b = list(transl.loc[transl["chain_id"] == "B", "residue_name"].values) + got_res_a = list( + transl.loc[transl["chain_id"] == "A", "residue_name"].values + ) + got_res_b = list( + transl.loc[transl["chain_id"] == "B", "residue_name"].values + ) assert expect_chain == got_chain assert expect_res_a == got_res_a diff --git a/tests/mmtf/test_distance.py b/tests/mmtf/test_distance.py index 8a2097b..856feff 100644 --- a/tests/mmtf/test_distance.py +++ b/tests/mmtf/test_distance.py @@ -55,5 +55,7 @@ def test_use_external_df(): new_df = p1t48.df["ATOM"].iloc[:-1, :].copy() dist = PandasMmtf.distance_df(df=new_df, xyz=(70.785, 15.477, 23.359)) - expect = pd.Series([2.533259, 1.520502, 0.000000, 1.257597], index=[12, 13, 14, 15]) + expect = pd.Series( + [2.533259, 1.520502, 0.000000, 1.257597], index=[12, 13, 14, 15] + ) assert dist[dist < 3].all() == expect.all() diff --git a/tests/mmtf/test_rmsd.py b/tests/mmtf/test_rmsd.py index 1e81935..32538af 100644 --- a/tests/mmtf/test_rmsd.py +++ b/tests/mmtf/test_rmsd.py @@ -60,7 +60,9 @@ def test_invalid_query(): def test_protein(): - r = PandasMmtf.rmsd(p1t48.df["ATOM"], p1t49.df["ATOM"], s="c-alpha", invert=False) + r = PandasMmtf.rmsd( + p1t48.df["ATOM"], p1t49.df["ATOM"], s="c-alpha", invert=False + ) assert r == 0.4785, r diff --git a/tests/mol2/test_mol2_io.py b/tests/mol2/test_mol2_io.py index 7cd2cbb..5591829 100644 --- a/tests/mol2/test_mol2_io.py +++ b/tests/mol2/test_mol2_io.py @@ -27,7 +27,9 @@ def test_split_multimol2(): def test_split_multimol2_wrong_format(): - expect = "Wrong file format;" "allowed file formats are .mol2 and .mol2.gz." + expect = ( + "Wrong file format;" "allowed file formats are .mol2 and .mol2.gz." + ) def run_code(): next(split_multimol2("40_mol2_files.pdb")) diff --git a/tests/mol2/test_pandas_mol2.py b/tests/mol2/test_pandas_mol2.py index ba4ffc1..b7b2867 100644 --- a/tests/mol2/test_pandas_mol2.py +++ b/tests/mol2/test_pandas_mol2.py @@ -54,7 +54,9 @@ def test_read_mol2_from_list(): data_path = str(TEST_DATA.joinpath("40_mol2_files.mol2")) mol2 = next(split_multimol2(data_path)) - pdmol = PandasMol2().read_mol2_from_list(mol2_lines=mol2[1], mol2_code=mol2[0]) + pdmol = PandasMol2().read_mol2_from_list( + mol2_lines=mol2[1], mol2_code=mol2[0] + ) assert pdmol.df.shape == (65, 9) assert pdmol.code == "ZINC38611810" diff --git a/tests/pdb/test_amino3to1.py b/tests/pdb/test_amino3to1.py index 4012cb1..276e2e3 100644 --- a/tests/pdb/test_amino3to1.py +++ b/tests/pdb/test_amino3to1.py @@ -490,8 +490,12 @@ def test_multichain(): expect_chain = ["A" for _ in range(88)] + ["B" for _ in range(94)] got_chain = list(transl["chain_id"].values) - got_res_a = list(transl.loc[transl["chain_id"] == "A", "residue_name"].values) - got_res_b = list(transl.loc[transl["chain_id"] == "B", "residue_name"].values) + got_res_a = list( + transl.loc[transl["chain_id"] == "A", "residue_name"].values + ) + got_res_b = list( + transl.loc[transl["chain_id"] == "B", "residue_name"].values + ) assert expect_chain == got_chain assert expect_res_a == got_res_a diff --git a/tests/pdb/test_distance.py b/tests/pdb/test_distance.py index 42ae05c..4c92f2c 100644 --- a/tests/pdb/test_distance.py +++ b/tests/pdb/test_distance.py @@ -55,5 +55,7 @@ def test_use_external_df(): new_df = p1t48.df["ATOM"].iloc[:-1, :].copy() dist = PandasPdb.distance_df(df=new_df, xyz=(70.785, 15.477, 23.359)) - expect = pd.Series([2.533259, 1.520502, 0.000000, 1.257597], index=[12, 13, 14, 15]) + expect = pd.Series( + [2.533259, 1.520502, 0.000000, 1.257597], index=[12, 13, 14, 15] + ) assert dist[dist < 3].all() == expect.all() diff --git a/tests/pdb/test_read_pdb.py b/tests/pdb/test_read_pdb.py index e535d92..abb5cdc 100644 --- a/tests/pdb/test_read_pdb.py +++ b/tests/pdb/test_read_pdb.py @@ -11,7 +11,6 @@ import importlib.resources as pkg_resources else: import importlib_resources as pkg_resources -import os from urllib.error import HTTPError import numpy as np @@ -105,7 +104,8 @@ def test__read_pdb_raises(): Test if ValueError is raised for wrong file formats.""" expect = ( - "Wrong file format; allowed file formats are " ".pdb, .pdb.gz, .ent, .ent.gz" + "Wrong file format; allowed file formats are " + ".pdb, .pdb.gz, .ent, .ent.gz" ) def run_code_1(): diff --git a/tests/pdb/test_rmsd.py b/tests/pdb/test_rmsd.py index 56e42cc..578d1b8 100644 --- a/tests/pdb/test_rmsd.py +++ b/tests/pdb/test_rmsd.py @@ -57,7 +57,9 @@ def test_invalid_query(): def test_protein(): - r = PandasPdb.rmsd(p1t48.df["ATOM"], p1t49.df["ATOM"], s="c-alpha", invert=False) + r = PandasPdb.rmsd( + p1t48.df["ATOM"], p1t49.df["ATOM"], s="c-alpha", invert=False + ) assert r == 0.4785, r @@ -71,7 +73,9 @@ def test_rna_and_nonmatching_indices(): def test_ligand(): - r = PandasPdb.rmsd(pl1.df["HETATM"], pl2.df["HETATM"], s="hydrogen", invert=True) + r = PandasPdb.rmsd( + pl1.df["HETATM"], pl2.df["HETATM"], s="hydrogen", invert=True + ) assert r == 1.9959, r diff --git a/tests/pdb/test_write_pdb.py b/tests/pdb/test_write_pdb.py index 0770078..f16e5ad 100644 --- a/tests/pdb/test_write_pdb.py +++ b/tests/pdb/test_write_pdb.py @@ -51,7 +51,9 @@ def test_defaults(): def test_nonexpected_column(): ppdb = PandasPdb() ppdb.read_pdb(TESTDATA_FILENAME) - ppdb.df["HETATM"]["test"] = pd.Series("test", index=ppdb.df["HETATM"].index) + ppdb.df["HETATM"]["test"] = pd.Series( + "test", index=ppdb.df["HETATM"].index + ) with warnings.catch_warnings(record=True) as w: ppdb.to_pdb(path=OUTFILE, records=["HETATM"]) with open(OUTFILE, "r") as f: @@ -157,4 +159,6 @@ def test_b_factor_shift(): assert tmp_df[ tmp_df["element_symbol"].isnull() | (tmp_df["element_symbol"] == "") ].empty - assert not tmp_df[tmp_df["blank_4"].isnull() | (tmp_df["blank_4"] == "")].empty + assert not tmp_df[ + tmp_df["blank_4"].isnull() | (tmp_df["blank_4"] == "") + ].empty diff --git a/tests/testutils/testutils.py b/tests/testutils/testutils.py index 6d71643..4560679 100644 --- a/tests/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: From 8b2a8a7ce55b2f66b6021d6ca0d2da458bdc3566 Mon Sep 17 00:00:00 2001 From: Grigorev Rostislav Date: Sat, 20 Jul 2024 14:37:05 +0200 Subject: [PATCH 5/6] run tests from root dir in workflow --- .github/workflows/publish.yaml | 44 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) 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 From 6b8c145b8458b250301f91d0142be5c8b620f878 Mon Sep 17 00:00:00 2001 From: Arian Jamasb Date: Tue, 23 Jul 2024 00:42:42 +0200 Subject: [PATCH 6/6] docs: update changelog --- docs/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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)