Repository: cogent3/cogent3
Pull request #1140 (2022-08-29 19:23:10)

DEV: fix _repr for user functions and enable xfail marked tests


Patch:
diff --git a/src/cogent3/app/align.py b/src/cogent3/app/align.py
index 6ec39e7a4..88157e466 100644
--- a/src/cogent3/app/align.py
+++ b/src/cogent3/app/align.py
@@ -18,12 +18,7 @@ from cogent3.evolve.models import get_model
 
 from .composable import NotCompleted, define_app
 from .tree import quick_tree, scale_branches
-from .typing import (
-    AlignedSeqsType,
-    SeqsCollectionType,
-    SerialisableType,
-    UnalignedSeqsType,
-)
+from .typing import AlignedSeqsType, SerialisableType, UnalignedSeqsType
 
 
 __author__ = "Gavin Huttley"
diff --git a/src/cogent3/app/composable.py b/src/cogent3/app/composable.py
index a01fdf86f..33e3ec2ea 100644
--- a/src/cogent3/app/composable.py
+++ b/src/cogent3/app/composable.py
@@ -886,7 +886,16 @@ def _add(self, other):
 
 def _repr(self):
     val = f"{self.input!r} + " if self.app_type is not LOADER and self.input else ""
-    data = ", ".join(f"{k}={v!r}" for k, v in self._init_vals.items())
+    all_args = deepcopy(self._init_vals)
+    args_items = all_args.get("args")
+    data = ", ".join(f"{k}={v!r}" for k, v in args_items.items()) if args_items else ""
+    all_args.pop("args", None)
+    kwargs_items = all_args.get("kwargs")
+    data += (
+        ", ".join(f"{k}={v!r}" for k, v in kwargs_items.items()) if kwargs_items else ""
+    )
+    all_args.pop("kwargs", None)
+    data += ", ".join(f"{k}={v!r}" for k, v in all_args.items())
     data = f"{val}{self.__class__.__name__}({data})"
     data = textwrap.fill(data, width=80, break_long_words=False, break_on_hyphens=False)
     return data
diff --git a/src/cogent3/app/io.py b/src/cogent3/app/io.py
index c88187a4a..aa55373a1 100644
--- a/src/cogent3/app/io.py
+++ b/src/cogent3/app/io.py
@@ -42,9 +42,6 @@ from .data_store import (
     make_record_for_json,
 )
 from .typing import (
-    ALIGNED_TYPE,
-    IDENTIFIER_TYPE,
-    SEQUENCE_TYPE,
     AlignedSeqsType,
     IdentifierType,
     SeqsCollectionType,
diff --git a/src/cogent3/app/translate.py b/src/cogent3/app/translate.py
index 73e86e062..a0d5724a5 100644
--- a/src/cogent3/app/translate.py
+++ b/src/cogent3/app/translate.py
@@ -6,7 +6,7 @@ from cogent3.core.genetic_code import get_code
 from cogent3.core.moltype import get_moltype
 
 from .composable import NotCompleted, define_app
-from .typing import SeqsCollectionType, SerialisableType, UnalignedSeqsType
+from .typing import SeqsCollectionType, SerialisableType
 
 
 __author__ = "Gavin Huttley"
diff --git a/src/cogent3/app/tree.py b/src/cogent3/app/tree.py
index f4bb04790..c412e1752 100644
--- a/src/cogent3/app/tree.py
+++ b/src/cogent3/app/tree.py
@@ -3,16 +3,8 @@ from typing import Union
 from cogent3 import make_tree
 from cogent3.phylo.nj import gnj
 
-from .composable import Composable, define_app
-from .typing import (
-    PAIRWISE_DISTANCE_TYPE,
-    SERIALISABLE_TYPE,
-    TREE_TYPE,
-    AlignedSeqsType,
-    PairwiseDistanceType,
-    SerialisableType,
-    TreeType,
-)
+from .composable import define_app
+from .typing import PairwiseDistanceType, SerialisableType, TreeType
 
 
 __author__ = "Gavin Huttley"
diff --git a/src/cogent3/app/typing.py b/src/cogent3/app/typing.py
index e6e55f066..696cadbf2 100644
--- a/src/cogent3/app/typing.py
+++ b/src/cogent3/app/typing.py
@@ -9,7 +9,7 @@ from typing_extensions import get_args, get_origin
 
 __author__ = "Gavin Huttley"
 __copyright__ = "Copyright 2007-2022, The Cogent Project"
-__credits__ = ["Gavin Huttley"]
+__credits__ = ["Gavin Huttley", "Nick Shahmaras"]
 __license__ = "BSD-3"
 __version__ = "2022.5.25a1"
 __maintainer__ = "Gavin Huttley"


Test patch:
diff --git a/tests/test_app/test_align.py b/tests/test_app/test_align.py
index 97eff5b7c..8637b145a 100644
--- a/tests/test_app/test_align.py
+++ b/tests/test_app/test_align.py
@@ -1,7 +1,5 @@
 from unittest import TestCase, main
 
-import pytest
-
 from cogent3 import (
     DNA,
     get_moltype,
diff --git a/tests/test_app/test_composable.py b/tests/test_app/test_composable.py
index 685d25f73..c979f661e 100644
--- a/tests/test_app/test_composable.py
+++ b/tests/test_app/test_composable.py
@@ -4,7 +4,7 @@ import pickle
 
 from pickle import dumps, loads
 from tempfile import TemporaryDirectory
-from unittest import TestCase, main
+from unittest import main
 from unittest.mock import Mock
 
 import pytest
@@ -495,19 +495,16 @@ def test_appify_pickle():
     assert loaded(list(range(10))) == list(range(6))
 
 
-@pytest.mark.xfail
 def test_user_function_repr():
     got = repr(bar(num=3))
     assert got == "bar(num=3)"
 
 
-@pytest.mark.xfail
 def test_user_function_str():
     got = str(bar(num=3))
     assert got == "bar(num=3)"
 
 
-@pytest.mark.xfail
 def test_user_function_with_args_kwargs():
     """correctly handles definition with args, kwargs"""
     from math import log
diff --git a/tests/test_app/test_data_store.py b/tests/test_app/test_data_store.py
index 3638b1c6f..6ece4fa60 100644
--- a/tests/test_app/test_data_store.py
+++ b/tests/test_app/test_data_store.py
@@ -8,8 +8,6 @@ from pathlib import Path
 from tempfile import TemporaryDirectory
 from unittest import TestCase, main, skipIf
 
-import pytest
-
 from cogent3 import load_aligned_seqs
 from cogent3.app.data_store import (
     IGNORE,
@@ -30,7 +28,7 @@ from cogent3.parse.fasta import MinimalFastaParser
 
 __author__ = "Gavin Huttley"
 __copyright__ = "Copyright 2007-2022, The Cogent Project"
-__credits__ = ["Gavin Huttley"]
+__credits__ = ["Gavin Huttley", "Nick Shahmaras"]
 __license__ = "BSD-3"
 __version__ = "2022.8.24a1"
 __maintainer__ = "Gavin Huttley"
diff --git a/tests/test_app/test_dist.py b/tests/test_app/test_dist.py
index bb71d7aeb..dfa7ba2c8 100644
--- a/tests/test_app/test_dist.py
+++ b/tests/test_app/test_dist.py
@@ -3,8 +3,6 @@ import os
 from tempfile import TemporaryDirectory
 from unittest import TestCase, main
 
-import pytest
-
 from numpy.testing import assert_allclose
 
 from cogent3 import DNA, PROTEIN, make_unaligned_seqs
diff --git a/tests/test_app/test_evo.py b/tests/test_app/test_evo.py
index 0cdee3867..b0c9e2a30 100644
--- a/tests/test_app/test_evo.py
+++ b/tests/test_app/test_evo.py
@@ -3,8 +3,6 @@ from tempfile import TemporaryDirectory
 from unittest import TestCase, main
 from unittest.mock import MagicMock
 
-import pytest
-
 from numpy.testing import assert_allclose, assert_raises
 
 from cogent3 import load_aligned_seqs, make_aligned_seqs, make_tree
diff --git a/tests/test_app/test_init.py b/tests/test_app/test_init.py
index 6021ff7a5..16d01268f 100644
--- a/tests/test_app/test_init.py
+++ b/tests/test_app/test_init.py
@@ -4,8 +4,6 @@ import os
 from tempfile import TemporaryDirectory
 from unittest import TestCase, main
 
-import pytest
-
 from cogent3 import available_apps
 from cogent3.app import align, dist, evo, io, sample, translate, tree
 from cogent3.app.composable import LOADER, WRITER
@@ -13,7 +11,7 @@ from cogent3.app.composable import LOADER, WRITER
 
 __author__ = "Gavin Huttley"
 __copyright__ = "Copyright 2007-2022, The Cogent Project"
-__credits__ = ["Gavin Huttley"]
+__credits__ = ["Gavin Huttley", "Nick Shahmaras"]
 __license__ = "BSD-3"
 __version__ = "2022.8.24a1"
 __maintainer__ = "Gavin Huttley"
diff --git a/tests/test_app/test_io.py b/tests/test_app/test_io.py
index 0df8566e5..4f5755661 100644
--- a/tests/test_app/test_io.py
+++ b/tests/test_app/test_io.py
@@ -9,7 +9,6 @@ from tempfile import TemporaryDirectory
 from unittest import TestCase, main
 
 import numpy
-import pytest
 
 from numpy.testing import assert_allclose
 
@@ -68,7 +67,7 @@ class TestIo(TestCase):
         with TemporaryDirectory(dir=".") as dirname:
             zip_path = join(dirname, "new")
             shutil.make_archive(zip_path, "zip", self.basedir)
-            zip_path = zip_path + ".zip"  # because shutil adds the suffix
+            zip_path += ".zip"  # because shutil adds the suffix
             found = list(io_app.findall(zip_path, suffix="fasta"))
             self.assertTrue(len(found) > 1)
             found = list(io_app.findall(zip_path, suffix="fasta", limit=2))
diff --git a/tests/test_app/test_translate.py b/tests/test_app/test_translate.py
index 60808714e..cca197daf 100644
--- a/tests/test_app/test_translate.py
+++ b/tests/test_app/test_translate.py
@@ -127,7 +127,7 @@ class TestFourFoldDegen(TestCase):
         # using straight characters
         expect = set()
         for di in "GC", "GG", "CT", "CC", "TC", "CG", "AC", "GT":
-            expect.update([frozenset([di + n for n in "ACGT"])])
+            expect.update([frozenset(di + n for n in "ACGT")])
 
         for i in range(1, 3):
             got = get_fourfold_degenerate_sets(get_code(i), as_indices=False)
diff --git a/tests/test_app/test_tree.py b/tests/test_app/test_tree.py
index f5a6a7138..b05eb141f 100644
--- a/tests/test_app/test_tree.py
+++ b/tests/test_app/test_tree.py
@@ -2,8 +2,6 @@ import os
 
 from unittest import TestCase, main
 
-import pytest
-
 from cogent3 import DNA, load_aligned_seqs, make_aligned_seqs, make_tree
 from cogent3.app import dist
 from cogent3.app import tree as tree_app
diff --git a/tests/test_app/test_typing.py b/tests/test_app/test_typing.py
index 4a854aa68..a18c799b4 100644
--- a/tests/test_app/test_typing.py
+++ b/tests/test_app/test_typing.py
@@ -14,7 +14,7 @@ from cogent3.app.typing import (
 
 __author__ = "Gavin Huttley"
 __copyright__ = "Copyright 2007-2022, The Cogent Project"
-__credits__ = ["Gavin Huttley"]
+__credits__ = ["Gavin Huttley", "Nick Shahmaras"]
 __license__ = "BSD-3"
 __version__ = "2022.5.25a1"
 __maintainer__ = "Gavin Huttley"