Skip to content

Commit

Permalink
bugfix: explicitly pass units kwargs to fake_random_ds when using non…
Browse files Browse the repository at this point in the history
…-default fields
  • Loading branch information
neutrinoceros committed Sep 12, 2020
1 parent 56900b4 commit 48a8e3b
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 14 deletions.
4 changes: 3 additions & 1 deletion yt/data_objects/tests/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def test_clone_sphere():


def test_clone_cut_region():
ds = fake_random_ds(64, nprocs=4, fields=("density", "temperature"))
ds = fake_random_ds(
64, nprocs=4, fields=("density", "temperature"), units=("g/cm**3", "K")
)
dd = ds.all_data()
reg1 = dd.cut_region(["obj['temperature'] > 0.5", "obj['density'] < 0.75"])
reg2 = reg1.clone()
Expand Down
10 changes: 8 additions & 2 deletions yt/data_objects/tests/test_derived_quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ def test_min_location():
def test_sample_at_min_field_values():
for nprocs in [1, 2, 4, 8]:
ds = fake_random_ds(
16, nprocs=nprocs, fields=("density", "temperature", "velocity_x")
16,
nprocs=nprocs,
fields=("density", "temperature", "velocity_x"),
units=("g/cm**3", "K", "cm/s"),
)
for ad in [ds.all_data(), ds.r[0.5, :, :]]:

Expand All @@ -127,7 +130,10 @@ def test_sample_at_min_field_values():
def test_sample_at_max_field_values():
for nprocs in [1, 2, 4, 8]:
ds = fake_random_ds(
16, nprocs=nprocs, fields=("density", "temperature", "velocity_x")
16,
nprocs=nprocs,
fields=("density", "temperature", "velocity_x"),
units=("g/cm**3", "K", "cm/s"),
)
for ad in [ds.all_data(), ds.r[0.5, :, :]]:

Expand Down
5 changes: 4 additions & 1 deletion yt/data_objects/tests/test_extract_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def test_cut_region():
# We decompose in different ways
for nprocs in [1, 2, 4, 8]:
ds = fake_random_ds(
64, nprocs=nprocs, fields=("density", "temperature", "velocity_x")
64,
nprocs=nprocs,
fields=("density", "temperature", "velocity_x"),
units=("g/cm**3", "K", "cm/s"),
)
# We'll test two objects
dd = ds.all_data()
Expand Down
18 changes: 12 additions & 6 deletions yt/data_objects/tests/test_numpy_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ def test_mean_sum_integrate():


def test_min_max():
fields = ("density", "temperature")
units = ("g/cm**3", "K")
for nprocs in [-1, 1, 2, 16]:
if nprocs == -1:
ds = fake_amr_ds(fields=("density", "temperature"), particles=20)
ds = fake_amr_ds(fields=fields, particles=20)
else:
ds = fake_random_ds(
32, nprocs=nprocs, fields=("density", "temperature"), particles=20
32, nprocs=nprocs, fields=fields, units=units, particles=20
)

ad = ds.all_data()
Expand Down Expand Up @@ -128,11 +130,13 @@ def test_min_max():


def test_argmin():
fields = ("density", "temperature")
units = ("g/cm**3", "K")
for nprocs in [-1, 1, 2, 16]:
if nprocs == -1:
ds = fake_amr_ds(fields=("density", "temperature"))
ds = fake_amr_ds(fields=fields)
else:
ds = fake_random_ds(32, nprocs=nprocs, fields=("density", "temperature"))
ds = fake_random_ds(32, nprocs=nprocs, fields=fields, units=units)

ad = ds.all_data()

Expand All @@ -152,11 +156,13 @@ def test_argmin():


def test_argmax():
fields = ("density", "temperature")
units = ("g/cm**3", "K")
for nprocs in [-1, 1, 2, 16]:
if nprocs == -1:
ds = fake_amr_ds(fields=("density", "temperature"))
ds = fake_amr_ds(fields=fields)
else:
ds = fake_random_ds(32, nprocs=nprocs, fields=("density", "temperature"))
ds = fake_random_ds(32, nprocs=nprocs, fields=fields, units=units)

ad = ds.all_data()

Expand Down
4 changes: 3 additions & 1 deletion yt/data_objects/tests/test_spheres.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def test_domain_sphere():


def test_sphere_center():
ds = fake_random_ds(16, nprocs=8, fields=("density", "temperature", "velocity_x"))
fields = ("density", "temperature", "velocity_x")
units = ("g/cm**3", "K", "cm/s")
ds = fake_random_ds(16, nprocs=8, fields=fields, units=units)

# Test if we obtain same center in different ways
sp1 = ds.sphere("max", (0.25, "unitary"))
Expand Down
3 changes: 2 additions & 1 deletion yt/visualization/tests/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,8 @@ def test_line_integral_convolution_callback():

def test_accepts_all_fields_decorator():
fields = ["density", "velocity_x", "pressure", "temperature"]
ds = fake_random_ds(16, fields=fields)
units = ["g/cm**3", "cm/s", "dyn/cm**2", "K"]
ds = fake_random_ds(16, fields=fields, units=units)
plot = SlicePlot(ds, "z", fields=fields)

# mocking a class method
Expand Down
4 changes: 2 additions & 2 deletions yt/visualization/tests/test_profile_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_phase_plot_attributes():
y_field = "temperature"
z_field = "cell_mass"
decimals = 12
ds = fake_random_ds(16, fields=("density", "temperature"))
ds = fake_random_ds(16, fields=("density", "temperature"), units=("g/cm**3", "K"))
for attr_name in ATTR_ARGS.keys():
for args in ATTR_ARGS[attr_name]:
test = PhasePlotAttributeTest(
Expand Down Expand Up @@ -153,7 +153,7 @@ def test_phase_plot():
@attr(ANSWER_TEST_TAG)
def test_profile_plot_multiple_field_multiple_plot():
fields = ("density", "temperature", "dark_matter_density")
ds = fake_random_ds(16, fields=fields)
ds = fake_random_ds(16, fields=fields, units=("g/cm**3", "K", "g/cm**3"))
sphere = ds.sphere("max", (1.0, "Mpc"))
profiles = []
profiles.append(
Expand Down

0 comments on commit 48a8e3b

Please sign in to comment.