import matplotlib
matplotlib.use('Agg')

import numpy as np
from astropy.tests.helper import pytest

from .. import FITSFigure


def test_grid_addremove():
    data = np.zeros((16, 16))
    f = FITSFigure(data)
    f.add_grid()
    f.remove_grid()
    f.add_grid()
    f.close()


def test_grid_showhide():
    data = np.zeros((16, 16))
    f = FITSFigure(data)
    f.add_grid()
    f.grid.hide()
    f.grid.show()
    f.close()


def test_grid_spacing():
    data = np.zeros((16, 16))
    f = FITSFigure(data)
    f.add_grid()
    f.grid.set_xspacing(1.)
    f.grid.set_xspacing('tick')
    with pytest.raises(ValueError):
        f.grid.set_xspacing('auto')
    f.grid.set_yspacing(2.)
    f.grid.set_yspacing('tick')
    with pytest.raises(ValueError):
        f.grid.set_yspacing('auto')
    f.close()


def test_grid_color():
    data = np.zeros((16, 16))
    f = FITSFigure(data)
    f.add_grid()
    f.grid.set_color('black')
    f.grid.set_color('#003344')
    f.grid.set_color((1.0, 0.4, 0.3))
    f.close()


def test_grid_alpha():
    data = np.zeros((16, 16))
    f = FITSFigure(data)
    f.add_grid()
    f.grid.set_alpha(0.0)
    f.grid.set_alpha(0.3)
    f.grid.set_alpha(1.0)
    f.close()


def test_grid_linestyle():
    data = np.zeros((16, 16))
    f = FITSFigure(data)
    f.add_grid()
    f.grid.set_linestyle('solid')
    f.grid.set_linestyle('dashed')
    f.grid.set_linestyle('dotted')
    f.close()


def test_grid_linewidth():
    data = np.zeros((16, 16))
    f = FITSFigure(data)
    f.add_grid()
    f.grid.set_linewidth(0)
    f.grid.set_linewidth(2)
    f.grid.set_linewidth(5)
    f.close()

[((2, 0, 2, 21), 'matplotlib.use', 'matplotlib.use', ({(2, 15, 2, 20): '"""Agg"""'}, {}), "('Agg')", False, 'import matplotlib\n'), ((11, 11, 11, 29), 'numpy.zeros', 'np.zeros', ({(11, 20, 11, 28): '(16, 16)'}, {}), '((16, 16))', True, 'import numpy as np\n'), ((20, 11, 20, 29), 'numpy.zeros', 'np.zeros', ({(20, 20, 20, 28): '(16, 16)'}, {}), '((16, 16))', True, 'import numpy as np\n'), ((29, 11, 29, 29), 'numpy.zeros', 'np.zeros', ({(29, 20, 29, 28): '(16, 16)'}, {}), '((16, 16))', True, 'import numpy as np\n'), ((44, 11, 44, 29), 'numpy.zeros', 'np.zeros', ({(44, 20, 44, 28): '(16, 16)'}, {}), '((16, 16))', True, 'import numpy as np\n'), ((54, 11, 54, 29), 'numpy.zeros', 'np.zeros', ({(54, 20, 54, 28): '(16, 16)'}, {}), '((16, 16))', True, 'import numpy as np\n'), ((64, 11, 64, 29), 'numpy.zeros', 'np.zeros', ({(64, 20, 64, 28): '(16, 16)'}, {}), '((16, 16))', True, 'import numpy as np\n'), ((74, 11, 74, 29), 'numpy.zeros', 'np.zeros', ({(74, 20, 74, 28): '(16, 16)'}, {}), '((16, 16))', True, 'import numpy as np\n'), ((34, 9, 34, 34), 'astropy.tests.helper.pytest.raises', 'pytest.raises', ({(34, 23, 34, 33): 'ValueError'}, {}), '(ValueError)', False, 'from astropy.tests.helper import pytest\n'), ((38, 9, 38, 34), 'astropy.tests.helper.pytest.raises', 'pytest.raises', ({(38, 23, 38, 33): 'ValueError'}, {}), '(ValueError)', False, 'from astropy.tests.helper import pytest\n')]