Skip to content

Commit

Permalink
switch tests to use raises
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Moodie committed Jun 6, 2020
1 parent 1ca1cde commit 70bda53
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
26 changes: 13 additions & 13 deletions tests/test_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def test_override_from_testfile(test_DeltaModel):
assert test_DeltaModel.Length == 10


@pytest.mark.xfail(raises=FileNotFoundError, strict=True)
def test_error_if_no_file_found():
delta = DeltaModel(input_file='./nonexisting_file.yaml')
with pytest.raises(FileNotFoundError):
delta = DeltaModel(input_file='./nonexisting_file.yaml')


def test_override_single_default(tmp_path):
Expand All @@ -49,24 +49,24 @@ def test_override_two_defaults(tmp_path):
assert delta.Np_sed == 2


@pytest.mark.xfail(raises=TypeError, strict=True)
def test_override_bad_type_float_string(tmp_path):
file_name = 'user_parameters.yaml'
p, f = utilities.create_temporary_file(tmp_path, file_name)
utilities.write_parameter_to_file(f, 'out_dir', tmp_path / 'out_dir')
utilities.write_parameter_to_file(f, 'S0', 'a string?!')
f.close()
delta = DeltaModel(input_file=p)
with pytest.raises(TypeError):
delta = DeltaModel(input_file=p)


@pytest.mark.xfail(raises=TypeError, strict=True)
def test_override_bad_type_int_float(tmp_path):
file_name = 'user_parameters.yaml'
p, f = utilities.create_temporary_file(tmp_path, file_name)
utilities.write_parameter_to_file(f, 'out_dir', tmp_path / 'out_dir')
utilities.write_parameter_to_file(f, 'beta', 24.4234)
f.close()
delta = DeltaModel(input_file=p)
with pytest.raises(TypeError):
delta = DeltaModel(input_file=p)


def test_not_creating_illegal_attributes(tmp_path):
Expand Down Expand Up @@ -221,14 +221,14 @@ def test_entry_point_python_main_call_timesteps(tmp_path):
assert os.path.isfile(exp_path_png)


@pytest.mark.xfail(raises=subprocess.CalledProcessError, strict=True)
def test_error_if_no_timesteps(tmp_path):
file_name = 'user_parameters.yaml'
p, f = utilities.create_temporary_file(tmp_path, file_name)
utilities.write_parameter_to_file(f, 'out_dir', tmp_path / 'test')
f.close()
subprocess.check_output(['python', '-m', 'pyDeltaRCM',
'--config', p])
with pytest.raises(subprocess.CalledProcessError):
subprocess.check_output(['python', '-m', 'pyDeltaRCM',
'--config', p])


import pyDeltaRCM as _pyimportedalias
Expand All @@ -250,18 +250,18 @@ def test_version_call():
from pyDeltaRCM import preprocessor


@pytest.mark.xfail(raises=ValueError, strict=True)
def test_python_highlevelapi_call_without_args():
pp = preprocessor.Preprocessor()
with pytest.raises(ValueError):
pp = preprocessor.Preprocessor()


@pytest.mark.xfail(raises=ValueError, strict=True)
def test_python_highlevelapi_call_without_timesteps(tmp_path):
file_name = 'user_parameters.yaml'
p, f = utilities.create_temporary_file(tmp_path, file_name)
utilities.write_parameter_to_file(f, 'out_dir', tmp_path / 'test')
f.close()
pp = preprocessor.Preprocessor(p)
with pytest.raises(ValueError):
pp = preprocessor.Preprocessor(p)


def test_python_highlevelapi_call_with_args(tmp_path):
Expand Down
1 change: 0 additions & 1 deletion tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def test_finalize(test_DeltaModel):
assert test_DeltaModel._is_finalized == True


# @pytest.mark.xfail(raises=RuntimeError, strict=True)
def test_multifinalization_error(test_DeltaModel):
err_delta = test_DeltaModel
err_delta.update()
Expand Down
2 changes: 0 additions & 2 deletions tests/test_water_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,3 @@ def test_calculate_new_ind(test_DeltaModel):
test_DeltaModel.jwalk.flatten(),
test_DeltaModel.eta.shape)
assert np.all(new_inds == np.array([14, 15]))

# assert test_DeltaModel.calculate_new_ind(old_ind, new_cell) == 14

0 comments on commit 70bda53

Please sign in to comment.