Skip to content

Commit

Permalink
Fixes #70. Statements were not assigned in raises. Have set to "_".
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-neal committed Aug 29, 2018
1 parent d990592 commit fd6bed5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
12 changes: 6 additions & 6 deletions spectrum_overload/test/test_Spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@ def test_length_checking():

with pytest.raises(ValueError):
# Wrong length should fail
Spectrum(flux=[1, 4, 5], xaxis=[2, 1])
_ = Spectrum(flux=[1, 4, 5], xaxis=[2, 1])


def test_flux_and_xaxis_cannot_pass_stings():
"""Passing a string to flux or xaxis will raise a TypeError."""
with pytest.raises(TypeError):
Spectrum(flux=[1, 2, 3], xaxis="bar")
_ = Spectrum(flux=[1, 2, 3], xaxis="bar")
with pytest.raises(TypeError):
Spectrum(flux="foo", xaxis=[1.2, 3, 4, 5])
_ = Spectrum(flux="foo", xaxis=[1.2, 3, 4, 5])
with pytest.raises(TypeError):
Spectrum(flux="foo", xaxis="bar")
_ = Spectrum(flux="foo", xaxis="bar")
spec = Spectrum(flux=[1, 1, .5, 1])
with pytest.raises(TypeError):
spec.flux = "foo"
Expand All @@ -127,7 +127,7 @@ def test_auto_generation_of_xaxis_if_none():
def test_length_of_flux_and_xaxis_must_be_equal(xaxis, flux):
"""Try assign a mismatched xaxis it should raise a ValueError."""
with pytest.raises(ValueError):
Spectrum(flux=flux, xaxis=xaxis)
_ = Spectrum(flux=flux, xaxis=xaxis)


def test_reassigning_unequal_length_fails():
Expand Down Expand Up @@ -524,4 +524,4 @@ def test_spectrum_slicing_with_colon(phoenix_spectrum):
def test_specturm_slicing_invalid_types(phoenix_spectrum, item):
"""Invalid scalars and other types."""
with pytest.raises(ValueError):
phoenix_spectrum[item]
_ = phoenix_spectrum[item]
56 changes: 28 additions & 28 deletions spectrum_overload/test/test_overloaded_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ def test_for_raise_die_to_calibration_mismatch():
s1 = Spectrum(flux=[1], xaxis=[2], calibrated=True)
s2 = Spectrum(flux=[1], xaxis=[2], calibrated=False)
with pytest.raises(SpectrumError):
s1 + s2
_ = s1 + s2
with pytest.raises(SpectrumError):
s1 - s2
_ = s1 - s2
with pytest.raises(SpectrumError):
s1 * s2
_ = s1 * s2
with pytest.raises(SpectrumError):
s1 / s2
_ = s1 / s2


def test_overload_pow():
Expand All @@ -208,17 +208,17 @@ def test_overload_pow():
)
# Can test when things are not supposed to work :)
with pytest.raises(TypeError):
spec1 ** spec2
_ = spec1 ** spec2
with pytest.raises(TypeError):
# Does not accept lists
spec1 ** [1] # This should fail
_ = spec1 ** [1] # This should fail
with pytest.raises(TypeError):
spec1 ** [1, 2] # This should fail also
_ = spec1 ** [1, 2] # This should fail also
with pytest.raises(TypeError):
# Does not accept lists
spec1 ** (2,) # This should fail as it is a tuple
_ = spec1 ** (2,) # This should fail as it is a tuple
with pytest.raises(ValueError):
spec1 ** np.array([1, 2]) # too many values
_ = spec1 ** np.array([1, 2]) # too many values
# Should also test that something works
spec4 = spec1 ** power
assert np.all(spec4.flux == np.array([4, 9, 16, 25])) # flux is squared
Expand Down Expand Up @@ -306,9 +306,9 @@ def test_addition_with_interpolation():
s5 = Spectrum(flux=[1, 2, 1, 2, 1], xaxis=[50, 51, 52, 53, 54])
# xaxis of both Spectrum do not overlap
with pytest.raises(ValueError):
s5 + s1
_ = s5 + s1
with pytest.raises(ValueError):
s1 + s5
_ = s1 + s5


def test_subtraction_with_interpolation():
Expand Down Expand Up @@ -339,9 +339,9 @@ def test_subtraction_with_interpolation():
s5 = Spectrum(flux=[1, 2, 1, 2, 1], xaxis=[50, 51, 52, 53, 54])
# xaxis of both Spectrum do not overlap
with pytest.raises(ValueError):
s5 - s1
_ = s5 - s1
with pytest.raises(ValueError):
s1 - s5
_ = s1 - s5


def test_multiplication_with_interpolation():
Expand Down Expand Up @@ -372,9 +372,9 @@ def test_multiplication_with_interpolation():
s5 = Spectrum(flux=[1, 2, 1, 2, 1], xaxis=[50, 51, 52, 53, 54])
# xaxis of both Spectrum do not overlap
with pytest.raises(ValueError):
s5 * s1
_ = s5 * s1
with pytest.raises(ValueError):
s1 * s5
_ = s1 * s5


def test_true_division_with_interpolation():
Expand Down Expand Up @@ -405,23 +405,23 @@ def test_true_division_with_interpolation():
s5 = Spectrum(flux=[1, 2, 1, 2, 1], xaxis=[50, 51, 52, 53, 54])
# xaxis of both Spectrum do not overlap
with pytest.raises(ValueError):
s5 / s1
_ = s5 / s1
with pytest.raises(ValueError):
s1 / s5
_ = s1 / s5


def test_value_error_when_spectra_do_not_overlap():
s = Spectrum(flux=[1, 2, 1, 2, 1], xaxis=[2, 4, 6, 8, 10])
u = Spectrum(flux=[1, 2, 1, 2], xaxis=[50, 51, 52, 53])

with pytest.raises(ValueError):
s + u
_ = s + u
with pytest.raises(ValueError):
s - u
_ = s - u
with pytest.raises(ValueError):
s / u
_ = s / u
with pytest.raises(ValueError):
s * u
_ = s * u


@pytest.mark.parametrize(
Expand All @@ -437,29 +437,29 @@ def test_value_error_when_spectra_do_not_overlap():
def test_operators_with_bad_types(badly_typed):
s = Spectrum(flux=[1, 2, 1, 2, 1], xaxis=[2, 4, 6, 8, 10])
with pytest.raises(TypeError):
s + badly_typed
_ = s + badly_typed
with pytest.raises(TypeError):
s - badly_typed
_ = s - badly_typed
with pytest.raises(TypeError):
s * badly_typed
_ = s * badly_typed
with pytest.raises(TypeError):
s / badly_typed
_ = s / badly_typed


@pytest.mark.parametrize("badly_typed", ["Test String", {"1": 1, "2": 2, "3": 3}])
def test_assignment_with_bad_types(badly_typed):
# Need to improve checking of what can pass into spectrum
with pytest.raises(TypeError):
Spectrum(flux=None, xaxis=badly_typed)
_ = Spectrum(flux=None, xaxis=badly_typed)
with pytest.raises(TypeError):
Spectrum(flux=badly_typed)
_ = Spectrum(flux=badly_typed)


@pytest.mark.parametrize("other", [[1, 3, 5, 6, 7], np.asarray([1, 2, 3])])
def test_operate_with_list_or_numpy_array_wrong_size(other):
a = Spectrum(xaxis=[1, 2, 3, 4], flux=[5, 6, 7, 8])
with pytest.raises(ValueError):
a + other
_ = a + other


@pytest.mark.parametrize(
Expand Down

0 comments on commit fd6bed5

Please sign in to comment.