def test_getext(self): """ Test the various different ways of specifying an extension header in the convenience functions. """ filename = self.data('test0.fits') hl, ext = _getext(filename, 'readonly', 1) assert ext == 1 pytest.raises(ValueError, _getext, filename, 'readonly', 1, 2) pytest.raises(ValueError, _getext, filename, 'readonly', (1, 2)) pytest.raises(ValueError, _getext, filename, 'readonly', 'sci', 'sci') pytest.raises(TypeError, _getext, filename, 'readonly', 1, 2, 3) hl, ext = _getext(filename, 'readonly', ext=1) assert ext == 1 hl, ext = _getext(filename, 'readonly', ext=('sci', 2)) assert ext == ('sci', 2) pytest.raises(TypeError, _getext, filename, 'readonly', 1, ext=('sci', 2), extver=3) pytest.raises(TypeError, _getext, filename, 'readonly', ext=('sci', 2), extver=3) hl, ext = _getext(filename, 'readonly', 'sci') assert ext == ('sci', 1) hl, ext = _getext(filename, 'readonly', 'sci', 1) assert ext == ('sci', 1) hl, ext = _getext(filename, 'readonly', ('sci', 1)) assert ext == ('sci', 1) hl, ext = _getext(filename, 'readonly', 'sci', extver=1, do_not_scale_image_data=True) assert ext == ('sci', 1) pytest.raises(TypeError, _getext, filename, 'readonly', 'sci', ext=1) pytest.raises(TypeError, _getext, filename, 'readonly', 'sci', 1, extver=2) hl, ext = _getext(filename, 'readonly', extname='sci') assert ext == ('sci', 1) hl, ext = _getext(filename, 'readonly', extname='sci', extver=1) assert ext == ('sci', 1) pytest.raises(TypeError, _getext, filename, 'readonly', extver=1) hl.close() # Close file handler