From 7e343bec2e5367746b9991758e1b6688842de450 Mon Sep 17 00:00:00 2001 From: Jordi Date: Thu, 15 Feb 2024 15:28:14 +0100 Subject: [PATCH] Change test_arraytable.py to pytest format. --- tests/redundant/test_arraytable.py | 42 ++++++++++++++++++++++++ tests/test_arraytable.py | 51 ++++++++++++++---------------- 2 files changed, 65 insertions(+), 28 deletions(-) create mode 100644 tests/redundant/test_arraytable.py diff --git a/tests/redundant/test_arraytable.py b/tests/redundant/test_arraytable.py new file mode 100644 index 000000000..e4e7c3392 --- /dev/null +++ b/tests/redundant/test_arraytable.py @@ -0,0 +1,42 @@ +import unittest + +import numpy as np + +from ete4 import ArrayTable +from .. import datasets as ds + + +class Test_Core_ArrayTable(unittest.TestCase): + """Tests reading clustering or phylogenetic profile data.""" + + def test_arraytable_parser(self): + """Test reading numeric tables.""" + A = ArrayTable(ds.expression) + + self.assertEqual(A.get_row_vector("A").tolist(), + [-1.23, -0.81, 1.79, 0.78,-0.42,-0.69, 0.58]) + self.assertEqual(A.get_several_row_vectors(["A", "C"]).tolist(), + [[-1.23, -0.81, 1.79, 0.78, -0.42, -0.69, 0.58], + [-2.19, 0.13, 0.65, -0.51, 0.52, 1.04, 0.36]]) + + self.assertEqual(A.get_several_column_vectors(["col2", "col7"]).tolist(), + [[-0.81, -0.94, 0.13, -0.98, -0.83, -1.11, -1.17, -1.25], + [0.58, 1.12, 0.36, 0.93, 0.65, 0.48, 0.26, 0.77]]) + + self.assertEqual(A.get_column_vector("col4").tolist(), + [0.78, 0.36, -0.51, -0.76, 0.07, -0.14, 0.23, -0.3]) + + A.remove_column("col4") + self.assertTrue(A.get_column_vector("col4") is None) + + Abis = A.merge_columns({"merged1": ["col1", "col2"], + "merged2": ["col5", "col6"]}, "mean") + + self.assertTrue((np.round(Abis.get_column_vector("merged1"), 3) == + [-1.02, -1.35, -1.03, -1.1, -1.15, -1.075, -1.37, -1.39]).all()) + # Continue this...... + # Sure. C'mon Jaime, you can do it! + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_arraytable.py b/tests/test_arraytable.py index 1dace9a29..46ebb4be3 100644 --- a/tests/test_arraytable.py +++ b/tests/test_arraytable.py @@ -1,4 +1,6 @@ -import unittest +""" +Tests reading clustering or phylogenetic profile data. +""" import numpy as np @@ -6,37 +8,30 @@ from . import datasets as ds -class Test_Core_ArrayTable(unittest.TestCase): - """Tests reading clustering or phylogenetic profile data.""" +def test_arraytable_parser(): + """Test reading numeric tables and simple manipulations.""" + A = ArrayTable(ds.expression) - def test_arraytable_parser(self): - """Test reading numeric tables.""" - A = ArrayTable(ds.expression) + assert (A.get_row_vector("A").tolist() == + [-1.23, -0.81, 1.79, 0.78,-0.42,-0.69, 0.58]) - self.assertEqual(A.get_row_vector("A").tolist(), - [-1.23, -0.81, 1.79, 0.78,-0.42,-0.69, 0.58]) - self.assertEqual(A.get_several_row_vectors(["A", "C"]).tolist(), - [[-1.23, -0.81, 1.79, 0.78, -0.42, -0.69, 0.58], - [-2.19, 0.13, 0.65, -0.51, 0.52, 1.04, 0.36]]) + assert (A.get_several_row_vectors(["A", "C"]).tolist() == + [[-1.23, -0.81, 1.79, 0.78, -0.42, -0.69, 0.58], + [-2.19, 0.13, 0.65, -0.51, 0.52, 1.04, 0.36]]) - self.assertEqual(A.get_several_column_vectors(["col2", "col7"]).tolist(), - [[-0.81, -0.94, 0.13, -0.98, -0.83, -1.11, -1.17, -1.25], - [0.58, 1.12, 0.36, 0.93, 0.65, 0.48, 0.26, 0.77]]) + assert (A.get_column_vector("col4").tolist() == + [0.78, 0.36, -0.51, -0.76, 0.07, -0.14, 0.23, -0.3]) - self.assertEqual(A.get_column_vector("col4").tolist(), - [0.78, 0.36, -0.51, -0.76, 0.07, -0.14, 0.23, -0.3]) + assert (A.get_several_column_vectors(["col2", "col7"]).tolist() == + [[-0.81, -0.94, 0.13, -0.98, -0.83, -1.11, -1.17, -1.25], + [0.58, 1.12, 0.36, 0.93, 0.65, 0.48, 0.26, 0.77]]) - A.remove_column("col4") - self.assertTrue(A.get_column_vector("col4") is None) + A.remove_column("col4") + assert A.get_column_vector("col4") is None - Abis = A.merge_columns({"merged1": ["col1", "col2"], - "merged2": ["col5", "col6"]}, "mean") + Abis = A.merge_columns({"merged1": ["col1", "col2"], + "merged2": ["col5", "col6"]}, "mean") + assert (np.round(Abis.get_column_vector("merged1"), 3).tolist() == + [-1.02, -1.35, -1.03, -1.1, -1.15, -1.075, -1.37, -1.39]) - self.assertTrue((np.round(Abis.get_column_vector("merged1"), 3) == - [-1.02, -1.35, -1.03, -1.1, -1.15, -1.075, -1.37, -1.39]).all()) - # Continue this...... - # Sure. C'mon Jaime, you can do it! - - -if __name__ == '__main__': - unittest.main() + # TODO: More tests. Jaime, you can do it!