Repository: widdowquinn/pyani

Issue:
Tests fail after #217
#### Summary:

PR #217 causes tests to fail

#### Description:

```
tests/test_anim.py::test_deltadir_parsing FAILED                         [ 20%]
tests/test_anim.py::test_deltafile_parsing PASSED                        [ 21%]
tests/test_anim.py::test_maxmatch_single FAILED                          [ 22%]
tests/test_anim.py::test_mummer_multiple FAILED                          [ 23%]
tests/test_anim.py::test_mummer_single FAILED                            [ 24%]
tests/test_anim.py::test_mummer_job_generation FAILED                    [ 25%]
tests/test_cli_parsing.py::test_createdb PASSED                          [ 26%]
tests/test_cli_parsing.py::test_download_single_genome PASSED            [ 27%]
tests/test_concordance.py::test_anim_concordance FAILED                  [ 28%]
[...]
tests/test_legacy_scripts.py::test_legacy_anim_sns FAILED                [ 58%]
tests/test_legacy_scripts.py::test_legacy_anim_mpl FAILED                [ 60%]
```

#### pyani Version:

v0.3.0a

#### Python Version:

3.8


Discussion:

Patch:
diff --git a/pyani/anim.py b/pyani/anim.py
index a5eb4df..c53fc09 100644
--- a/pyani/anim.py
+++ b/pyani/anim.py
@@ -52,9 +52,11 @@ counts, average nucleotide identity (ANI) percentages, and minimum aligned
 percentage (of whole genome) for each pairwise comparison.
 """
 
+import logging
 import platform
 import re
 import subprocess
+import sys
 
 from logging import Logger
 from pathlib import Path
@@ -63,10 +65,16 @@ from typing import Dict, Iterable, List, Optional, Tuple
 from . import pyani_config
 from . import pyani_files
 from . import pyani_jobs
+from . import PyaniException
 
 from .pyani_tools import ANIResults
 
 
+class PyaniANImException(PyaniException):
+
+    """ANIm-specific exception for pyani."""
+
+
 # Get a list of FASTA files from the input directory
 def get_fasta_files(dirname: Path = Path(".")) -> Iterable:
     """Return iterable of FASTA files in the passed directory.
@@ -205,7 +213,7 @@ def construct_nucmer_cmdline(
     fname1, fname2 = Path(fname1), Path(fname2)
 
     # Compile commands
-    outsubdir = outdir / pyani_config.ALIGNDIR["ANIm"] / fname1.stem
+    outsubdir = outdir / pyani_config.ALIGNDIR["ANIm"]
     outsubdir.mkdir(exist_ok=True)
     outprefix = outsubdir / f"{fname1.stem}_vs_{fname2.stem}"
     if maxmatch:
@@ -317,17 +325,16 @@ def process_deltadir(
     May throw a ZeroDivisionError if one or more NUCmer runs failed, or a
     very distant sequence was included in the analysis.
     """
+    logger = logging.getLogger(__name__)
+
     # Process directory to identify input files - as of v0.2.4 we use the
     # .filter files that result from delta-filter (1:1 alignments)
-    deltafiles = sorted(delta_dir.glob("*/*.filter"))
-    import sys
+    deltafiles = sorted(delta_dir.glob("*.filter"))
 
-    sys.exit(f"{delta_dir} has {len(deltafiles)} files to load")
+    logger.info("%s has %d files to load", delta_dir, len(deltafiles))
     if not deltafiles:
-        sys.exit(f"{delta_dir} empty? No filter files found")
-    if not logger:
-        logger = logging.getLogger(__name__)
-    logger.debug(f"Found {len(deltafiles)} filter files in {delta_dir}")
+        logger.error("%s empty? No filter files found", delta_dir)
+        raise PyaniANImException(f"{delta_dir} contains no filter files.")
 
     # Hold data in ANIResults object
     results = ANIResults(list(org_lengths.keys()), "ANIm")


Test patch:
diff --git a/tests/test_anim.py b/tests/test_anim.py
index d83c552..8df6db3 100644
--- a/tests/test_anim.py
+++ b/tests/test_anim.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 # (c) The James Hutton Institute 2017-2019
-# (c) University of Strathclyde 2019-2020
+# (c) University of Strathclyde 2019-2021
 # Author: Leighton Pritchard
 #
 # Contact:
@@ -18,7 +18,7 @@
 # The MIT License
 #
 # Copyright (c) 2017-2019 The James Hutton Institute
-# Copyright (c) 2019-2020 University of Strathclyde
+# Copyright (c) 2019-2021 University of Strathclyde
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
 # of this software and associated documentation files (the "Software"), to deal
@@ -44,8 +44,6 @@ These tests are intended to be run from the repository root using:
 pytest -v
 """
 
-import os
-
 from pathlib import Path
 from typing import List, NamedTuple, Tuple
 
@@ -54,7 +52,7 @@ import pytest
 
 from pandas.util.testing import assert_frame_equal
 
-from pyani import anim, pyani_files, pyani_tools
+from pyani import anim, pyani_files
 
 
 class DeltaDir(NamedTuple):