Commit c0db4c50 authored by Joseph Weston's avatar Joseph Weston
Browse files

add test for invalid value functions

Note that we only raise an error if 'params' is specified. This may
actually be incorrect; if we have a keyword-only parameter, for example
then the way in which we call the value function will always produce
an error, regardless of whether 'params' is specified or not.
parent df823b9b
......@@ -1547,6 +1547,25 @@ def test_argument_passing(vectorize):
expected_hamiltonian(**params)
)
@pytest.mark.parametrize("vectorize", [False, True])
def test_invalid_value_functions(vectorize):
invalid_value_functions = [
lambda _, *args: 1, # uses *args
lambda _, **kwargs: 1, # uses **kwargs
lambda _, d=10: 1, # has default arguments
lambda _, *, d: 1 # has keyword-only parameters
]
lat = kwant.lattice.chain(norbs=1)
for f in invalid_value_functions:
syst = builder.Builder(vectorize=vectorize)
syst[lat(0)] = f
syst = syst.finalized()
with pytest.raises(ValueError):
syst.hamiltonian_submatrix(params=dict(d=1))
def test_parameter_substitution():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment