Skip to content

Commit

Permalink
Merge pull request #921: Move AugurError to new errors.py, replace Ru…
Browse files Browse the repository at this point in the history
…ntimeError
  • Loading branch information
victorlin authored May 27, 2022
2 parents 5916362 + 2ad9b2b commit e204d3e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
3 changes: 2 additions & 1 deletion augur/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
from textwrap import dedent
from types import SimpleNamespace

from .errors import AugurError
from .io import print_err
from .utils import AugurError, first_line
from .utils import first_line

recursion_limit = os.environ.get("AUGUR_RECURSION_LIMIT")
if recursion_limit:
Expand Down
2 changes: 2 additions & 0 deletions augur/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class AugurError(Exception):
pass
3 changes: 2 additions & 1 deletion augur/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
from typing import Collection

from .dates import numeric_date, numeric_date_type, SUPPORTED_DATE_HELP_TEXT, is_date_ambiguous, get_numerical_dates
from .errors import AugurError
from .index import index_sequences, index_vcf
from .io import open_file, read_metadata, read_sequences, write_sequences, is_vcf as filename_is_vcf, write_vcf
from .utils import AugurError, read_strains
from .utils import read_strains

comment_char = '#'

Expand Down
2 changes: 1 addition & 1 deletion augur/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .io import open_file, read_sequences, write_sequences
from .dates import get_numerical_date_from_value
from .utils import AugurError
from .errors import AugurError

forbidden_characters = str.maketrans(
{' ': None,
Expand Down
7 changes: 4 additions & 3 deletions augur/util_support/node_data_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from augur.__version__ import __version__
from augur.__version__ import is_augur_version_compatible
from augur.errors import AugurError
from augur.validate import validate_json, ValidateError, load_json_schema


Expand Down Expand Up @@ -58,19 +59,19 @@ def validate(self):
self.fname,
)
except ValidateError as err:
raise RuntimeError(
raise AugurError(
f"{self.fname} contains an `annotations` attribute of an invalid JSON format. Was it "
"produced by different version of augur the one you are currently using "
f" ({__version__})? Please check the program that produced that JSON file."
) from err

if not isinstance(self.nodes, dict):
raise RuntimeError(
raise AugurError(
f"`nodes` value in {self.fname} is not a dictionary. Please check the formatting of this JSON!"
)

if self.is_generated_by_incompatible_augur:
raise RuntimeError(
raise AugurError(
f"Augur version incompatibility detected: the JSON {self.fname} was generated by "
f"{self.generated_by}, which is incompatible with the current augur version "
f"({__version__}). We suggest you rerun the pipeline using the current version of "
Expand Down
5 changes: 0 additions & 5 deletions augur/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
from augur.util_support.node_data_reader import NodeDataReader


class AugurError(Exception):
pass



def get_json_name(args, default=None):
if args.output_node_data:
return args.output_node_data
Expand Down
7 changes: 4 additions & 3 deletions tests/util_support/test_node_data_file.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json

from augur.__version__ import __version__
from augur.errors import AugurError
from augur.util_support.node_data_file import NodeDataFile

import pytest
Expand Down Expand Up @@ -45,7 +46,7 @@ def test_validate_valid(self, build_node_data_file):
)

def test_validate_invalid_annotation(self, build_node_data_file):
with pytest.raises(RuntimeError, match="annotations.*invalid JSON format"):
with pytest.raises(AugurError, match="annotations.*invalid JSON format"):
build_node_data_file(
"""
{
Expand All @@ -56,11 +57,11 @@ def test_validate_invalid_annotation(self, build_node_data_file):
)

def test_validate_nodes_not_dict(self, build_node_data_file):
with pytest.raises(RuntimeError, match="is not a dictionary"):
with pytest.raises(AugurError, match="is not a dictionary"):
build_node_data_file('{ "nodes": "hhh" }')

def test_validate_incompatible_augur_version(self, build_node_data_file):
with pytest.raises(RuntimeError, match="incompatibility detected"):
with pytest.raises(AugurError, match="incompatibility detected"):
build_node_data_file(
"""
{
Expand Down

0 comments on commit e204d3e

Please sign in to comment.