Repository: sunpy/sunpy

Issue:
Increase test coverage for sunpy.cm
Unit tests missing are basically ones that make sure that the error messages get triggered correctly. 

The missing lines that need a unittest are:

https://codecov.io/gh/sunpy/sunpy/src/master/sunpy/cm/cm.py#L147
https://codecov.io/gh/sunpy/sunpy/src/master/sunpy/cm/color_tables.py#L76
https://codecov.io/gh/sunpy/sunpy/src/master/sunpy/cm/color_tables.py#L267
https://codecov.io/gh/sunpy/sunpy/src/master/sunpy/cm/color_tables.py#L345
https://codecov.io/gh/sunpy/sunpy/src/master/sunpy/cm/color_tables.py#L373
https://codecov.io/gh/sunpy/sunpy/src/master/sunpy/cm/color_tables.py#L533
https://codecov.io/gh/sunpy/sunpy/src/master/sunpy/cm/color_tables.py#L1025
https://codecov.io/gh/sunpy/sunpy/src/master/sunpy/cm/color_tables.py#L1078
https://codecov.io/gh/sunpy/sunpy/src/master/sunpy/cm/color_tables.py#L1102
https://codecov.io/gh/sunpy/sunpy/src/master/sunpy/cm/color_tables.py#L1359



Discussion:
@Cadair @nabobalis Currently, I am writing tests for `sunpy.cm`. I've written [something](https://github.com/swapsha96/sunpy/blob/test-cm/sunpy/cm/tests/test_cm.py), but that's nothing. Can you help me with this?

Resolving patch:
diff --git a/sunpy/visualization/colormaps/cm.py b/sunpy/visualization/colormaps/cm.py
--- a/sunpy/visualization/colormaps/cm.py
+++ b/sunpy/visualization/colormaps/cm.py
@@ -150,7 +150,7 @@ def show_colormaps(search=None):
 
     Examples
     --------
-    >>> import sunpy.cm as cm
+    >>> import sunpy.visualization.colormaps as cm
     >>> cm.show_colormaps()
     >>> cm.show_colormaps(search='aia')
     >>> cm.show_colormaps(search='171')
diff --git a/sunpy/visualization/colormaps/color_tables.py b/sunpy/visualization/colormaps/color_tables.py
--- a/sunpy/visualization/colormaps/color_tables.py
+++ b/sunpy/visualization/colormaps/color_tables.py
@@ -87,6 +87,11 @@ def aia_color_table(wavelength):
 
     Based on aia_lct.pro part of SDO/AIA on SSWIDL written by Karel
     Schrijver (2010/04/12).
+
+    Parmeters
+    ---------
+    wavelength : `int`
+        Wavelength for the desired AIA color table.
     """
     try:
         r, g, b = aia_wave_dict[wavelength]


Test patch:
diff --git a/sunpy/visualization/colormaps/tests/test_cm.py b/sunpy/visualization/colormaps/tests/test_cm.py
--- a/sunpy/visualization/colormaps/tests/test_cm.py
+++ b/sunpy/visualization/colormaps/tests/test_cm.py
@@ -1,9 +1,36 @@
 import matplotlib.pyplot as plt
+import pytest
 
 import sunpy.visualization.colormaps as cm
+import sunpy.visualization.colormaps.color_tables as ct
 
 
 # Checks that colormaps are imported by MPL
 def test_get_cmap():
     for cmap in cm.cmlist.keys():
         assert cm.cmlist[cmap] == plt.get_cmap(cmap)
+
+
+def test_invalid_show_cmaps():
+    with pytest.raises(
+            KeyError, match='No color maps found for search term'):
+        cm.show_colormaps(search='asdfghjkl')
+
+
+@pytest.mark.parametrize(
+    'f, match',
+    [[ct.aia_color_table, 'Invalid AIA wavelength.'],
+     [ct.eit_color_table, 'Invalid EIT wavelength.'],
+     [ct.sswidl_lasco_color_table, 'Invalid LASCO number.'],
+     [ct.sxt_color_table, 'Invalid SXT filter type number.'],
+     [ct.cor_color_table, 'Invalid COR number.'],
+     [ct.trace_color_table, 'Invalid TRACE filter waveband passed.'],
+     [ct.sot_color_table, 'Invalid \(or not supported\) SOT type.'],
+     [ct.iris_sji_color_table, 'Invalid IRIS SJI waveband.'],
+     [ct.stereo_hi_color_table, 'Valid HI cameras are 1 and 2'],
+     [ct.suvi_color_table, 'Invalid SUVI wavelength.']]
+)
+def test_invalid_wavelengths(f, match):
+    # Check that accessing non-existent color table values raises a ValueError
+    with pytest.raises(ValueError, match=match):
+        f(-100)