Skip to content

Commit

Permalink
Merge pull request #4897 from neutrinoceros/tst/migrate_test_disks
Browse files Browse the repository at this point in the history
TST: migrate test_disks.py from nose to pytest
  • Loading branch information
neutrinoceros authored Jul 1, 2024
2 parents 9c6a18f + c4ce79f commit 76feff7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
1 change: 1 addition & 0 deletions nose_ignores.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@
--ignore-file=test_minimal_representation\.py
--ignore-file=test_set_log_level\.py
--ignore-file=test_field_parsing\.py
--ignore-file=test_disks\.py
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ addopts = '''
--ignore-glob='/*/yt/data_objects/tests/test_connected_sets.py'
--ignore-glob='/*/yt/data_objects/tests/test_data_containers.py'
--ignore-glob='/*/yt/data_objects/tests/test_dataset_access.py'
--ignore-glob='/*/yt/data_objects/tests/test_disks.py'
--ignore-glob='/*/yt/data_objects/tests/test_particle_filter.py'
--ignore-glob='/*/yt/data_objects/tests/test_particle_trajectories.py'
--ignore-glob='/*/yt/data_objects/tests/test_pickling.py'
Expand Down
57 changes: 30 additions & 27 deletions yt/data_objects/tests/test_disks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from nose.tools import assert_raises
from numpy.testing import assert_equal
import pytest

from yt import YTQuantity
from yt.testing import fake_random_ds
Expand All @@ -10,50 +9,54 @@ def test_bad_disk_input():
ds = fake_random_ds(16)

# Test invalid 3d array
with assert_raises(TypeError) as ex:
with pytest.raises(
TypeError,
match=r"^Expected an array of size \(3,\), received 'list' of length 4$",
):
ds.disk(ds.domain_center, [0, 0, 1, 1], (10, "kpc"), (20, "kpc"))
desired = "Expected an array of size (3,), received 'list' of length 4"
assert_equal(str(ex.exception), desired)

# Test invalid float
with assert_raises(TypeError) as ex:
with pytest.raises(
TypeError,
match=(
r"^Expected a numeric value \(or size-1 array\), "
r"received 'unyt.array.unyt_array' of length 3$"
),
):
ds.disk(ds.domain_center, [0, 0, 1], ds.domain_center, (20, "kpc"))
desired = (
"Expected a numeric value (or size-1 array),"
" received 'unyt.array.unyt_array' of length 3"
)
assert_equal(str(ex.exception), desired)

# Test invalid float
with assert_raises(TypeError) as ex:
with pytest.raises(
TypeError,
match=(
r"^Expected a numeric value \(or tuple of format \(float, String\)\), "
r"received an inconsistent tuple '\(10, 10\)'.$"
),
):
ds.disk(ds.domain_center, [0, 0, 1], (10, 10), (20, "kpc"))
desired = (
"Expected a numeric value (or tuple of format (float, String)),"
" received an inconsistent tuple '(10, 10)'."
)
assert_equal(str(ex.exception), desired)

# Test invalid iterable
with assert_raises(TypeError) as ex:
with pytest.raises(
TypeError,
match=r"^Expected an iterable object, received 'unyt\.array\.unyt_quantity'$",
):
ds.disk(
ds.domain_center,
[0, 0, 1],
(10, "kpc"),
(20, "kpc"),
fields=YTQuantity(1, "kpc"),
)
desired = "Expected an iterable object, received 'unyt.array.unyt_quantity'"
assert_equal(str(ex.exception), desired)

# Test invalid object
with assert_raises(TypeError) as ex:
with pytest.raises(
TypeError,
match=(
r"^Expected an object of 'yt\.data_objects\.static_output\.Dataset' type, "
r"received 'yt\.data_objects\.selection_objects\.region\.YTRegion'$"
),
):
ds.disk(ds.domain_center, [0, 0, 1], (10, "kpc"), (20, "kpc"), ds=ds.all_data())
desired = (
"Expected an object of 'yt.data_objects.static_output.Dataset' "
"type, received "
"'yt.data_objects.selection_objects.region.YTRegion'"
)
assert_equal(str(ex.exception), desired)

# Test valid disk
ds.disk(ds.domain_center, [0, 0, 1], (10, "kpc"), (20, "kpc"))
Expand Down

0 comments on commit 76feff7

Please sign in to comment.