def test_xpec_tablemodel_outofbound(clean_astro_ui, make_data_path): ui.load_xstable_model('tmod', make_data_path('xspec-tablemodel-RCS.mod')) # when used in the test suite it appears that the tmod # global symbol is not created, so need to access the component tmod = ui.get_model_component('tmod') with pytest.raises(ParameterErr) as e: tmod.calc([0., .2, 1., 1.], numpy.arange(1, 5)) assert 'minimum' in str(e)
def test_load_xstable_model_fails_with_dir(): """Check that the function fails with invalid input: directory The temporary directory is used for this (the test is skipped if it does not exist). """ ui.clean() assert ui.list_model_components() == [] with pytest.raises(IOError): ui.load_xstable_model('tmpdir', tmpdir) assert ui.list_model_components() == []
def test_load_xstable_model_fails_with_dir(tmp_path): """Check that the function fails with invalid input: directory The temporary directory is used for this. """ tmpdir = tmp_path / 'load_xstable_model' tmpdir.mkdir() ui.clean() assert ui.list_model_components() == [] with pytest.raises(IOError): ui.load_xstable_model('tmpdir', str(tmpdir)) assert ui.list_model_components() == []
def test_load_xstable_model_fails_with_dev_null(): """Check that load_table_model fails with invalid input: /dev/null This simulates an empty file (and relies on the system containing a /dev/null file that reads in 0 bytes). """ ui.clean() assert ui.list_model_components() == [] # The error depends on the load function with pytest.raises(IOError): ui.load_xstable_model('devnull', '/dev/null') assert ui.list_model_components() == []
def test_load_xstable_model_fails_with_text_column(make_data_path): """Check that load_table_model fails with invalid input: text column The first column is text (and an ASCII file) so it is expected to fail. """ # Check that this file hasn't been changed (as I am re-using it for # this test) infile = make_data_path('table.txt') assert os.path.isfile(infile) ui.clean() assert ui.list_model_components() == [] # The error depends on the load function. with pytest.raises(Exception): ui.load_xstable_model('stringcol', infile) assert ui.list_model_components() == []