From 4b2626f7976d63eea4fed8b89bf21ba699c76954 Mon Sep 17 00:00:00 2001 From: "M. Eric Irrgang" Date: Thu, 10 Oct 2019 13:28:47 +0300 Subject: [PATCH] Test float and int gmxapi parameter updates. Also updates the spc_water_box test fixture resource to specify an exactly representable time step. Change-Id: I5691be2041cd769585b98638ba4b29473752ba1d --- python_packaging/src/test/conftest.py | 3 +++ python_packaging/src/test/test_fileio.py | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/python_packaging/src/test/conftest.py b/python_packaging/src/test/conftest.py index 5b1b77f45a..d9a080ead0 100644 --- a/python_packaging/src/test/conftest.py +++ b/python_packaging/src/test/conftest.py @@ -172,7 +172,10 @@ def spc_water_box(gmxcli): logging.debug(solvate.output.erroroutput.result()) raise RuntimeError('solvate failed in spc_water_box testing fixture.') + # Choose an exactly representable dt of 2^-9 ps (approximately 0.002) + dt = 2.**-9. mdp_input = [('integrator', 'md'), + ('dt', dt), ('cutoff-scheme', 'Verlet'), ('nsteps', 2), ('nstxout', 1), diff --git a/python_packaging/src/test/test_fileio.py b/python_packaging/src/test/test_fileio.py index 7df77c4947..a1a9d514ac 100644 --- a/python_packaging/src/test/test_fileio.py +++ b/python_packaging/src/test/test_fileio.py @@ -113,16 +113,22 @@ def test_write_tpr_file(spc_water_box): params = sim_input.parameters.extract() nsteps = params['nsteps'] init_step = params['init-step'] + # Choose a new nsteps to check integer parameter setting. new_nsteps = init_step + additional_steps + # Choose a new dt to check floating point parameter setting + new_dt = params['dt'] * 2. sim_input.parameters.set('nsteps', new_nsteps) + sim_input.parameters.set('dt', new_dt) _, temp_filename = tempfile.mkstemp(suffix='.tpr') gmxapi.simulation.fileio.write_tpr_file(temp_filename, input=sim_input) tprfile = TprFile(temp_filename, 'r') with tprfile as fh: params = read_tpr(fh).parameters.extract() - dt = params['dt'] + # Note that we have chosen an exactly representable dt for spc_water_box. + # Otherwise, we would have to use pytest.approx with a suitable tolerance. + assert params['dt'] == new_dt assert params['nsteps'] != nsteps assert params['nsteps'] == new_nsteps -- 2.11.4.GIT