Skip to content

Commit

Permalink
add test + catch all exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Aug 13, 2020
1 parent bfdf2cc commit 04ab46b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
4 changes: 1 addition & 3 deletions yt/fields/field_info_container.py
@@ -1,9 +1,7 @@
from numbers import Number as numeric_type

import numpy as np
from unyt.exceptions import UnitConversionError

from yt.fields.field_exceptions import NeedsConfiguration
from yt.funcs import issue_deprecation_warning, mylog, only_on_root
from yt.geometry.geometry_handler import is_curvilinear
from yt.units.dimensions import dimensionless
Expand Down Expand Up @@ -473,7 +471,7 @@ def check_derived_fields(self, fields_to_check=None):
try:
# fd: field detector
fd = fi.get_dependencies(ds=self.ds)
except (YTFieldNotFound, NeedsConfiguration, UnitConversionError) as e:
except Exception as e:
if field in self._show_field_errors:
raise
if not isinstance(e, YTFieldNotFound):
Expand Down
24 changes: 21 additions & 3 deletions yt/fields/tests/test_field_name_container.py
@@ -1,5 +1,5 @@
from yt import load
from yt.testing import fake_amr_ds, requires_file
from yt.testing import fake_amr_ds, fake_hexahedral_ds, requires_file


def do_field_type(ft):
Expand Down Expand Up @@ -33,7 +33,25 @@ def test_field_name_container():
do_field_type(field_type)


def test_no_vertex_fields_in_structured_ds():
def test_vertex_fields_only_in_unstructured_ds():
def get_vertex_fields(ds):
return [(ft, fn) for ft, fn in ds.derived_field_list if "vertex" in fn]

ds = fake_amr_ds()
vertex_fields = [(ft, fn) for ft, fn in ds.derived_field_list if "vertex" in fn]
vertex_fields = get_vertex_fields(ds)
assert not vertex_fields

ds = fake_hexahedral_ds()
actual = get_vertex_fields(ds)
expected = [
("all", "vertex_x"),
("all", "vertex_y"),
("all", "vertex_z"),
("connect1", "vertex_x"),
("connect1", "vertex_y"),
("connect1", "vertex_z"),
("index", "vertex_x"),
("index", "vertex_y"),
("index", "vertex_z"),
]
assert actual == expected

0 comments on commit 04ab46b

Please sign in to comment.