Repository: obspy/obspy

Issue:
CNV writing phase_mapping fails

This line:
https://github.com/obspy/obspy/blob/master/obspy/io/cnv/core.py#L63

doesn't work because 

``values.update(("P", "S"))`` returns ``None``

This works:
```python
values = set(phase_mapping.values())
values.update(("P","S"))
    if values != set(("P", "S")):

```


Discussion:

Resolving patch:
diff --git a/obspy/io/cnv/core.py b/obspy/io/cnv/core.py
--- a/obspy/io/cnv/core.py
+++ b/obspy/io/cnv/core.py
@@ -60,7 +60,8 @@ def _write_cnv(catalog, filename, phase_mapping=None, ifx_list=None,
                          's': "S", 'S': "S", 'Sg': "S", 'Sn': "S", 'Sm': "S"}
     else:
         values = set(phase_mapping.values())
-        if values.update(("P", "S")) != set(("P", "S")):
+        values.update(("P", "S"))
+        if values != set(("P", "S")):
             msg = ("Values of phase mapping should only be 'P' or 'S'")
             raise ValueError(msg)
     if ifx_list is None:


Test patch:
diff --git a/obspy/io/cnv/tests/data/obspyck_20141020150701_P.cnv b/obspy/io/cnv/tests/data/obspyck_20141020150701_P.cnv
new file mode 100644
--- /dev/null
+++ b/obspy/io/cnv/tests/data/obspyck_20141020150701_P.cnv
@@ -0,0 +1,3 @@
+100527 1656 24.61 48.0471N  11.6455E   4.58   0.93 0
+UH1 P0  1.52UH2 P0  1.43UH3 P0  1.32UH4 P0  2.31
+
diff --git a/obspy/io/cnv/tests/test_core.py b/obspy/io/cnv/tests/test_core.py
--- a/obspy/io/cnv/tests/test_core.py
+++ b/obspy/io/cnv/tests/test_core.py
@@ -7,6 +7,7 @@
 import inspect
 import os
 import unittest
+import warnings
 
 from obspy import read_events
 from obspy.io.cnv.core import _write_cnv
@@ -41,7 +42,7 @@ def test_write_cnv(self):
             tf.seek(0)
             got = tf.read().decode()
 
-        self.assertEqual(expected, got)
+        self.assertEqual(expected.splitlines(), got.splitlines())
 
         # write manually
         with NamedTemporaryFile() as tf:
@@ -49,7 +50,34 @@ def test_write_cnv(self):
             tf.seek(0)
             got = tf.read().decode()
 
-        self.assertEqual(expected, got)
+        self.assertEqual(expected.splitlines(), got.splitlines())
+
+        # write via plugin and with phase_mapping
+        with NamedTemporaryFile() as tf:
+            cat.write(tf, format="CNV", phase_mapping={"P": "P", "S": "S"})
+            tf.seek(0)
+            got = tf.read().decode()
+
+        self.assertEqual(expected.splitlines(), got.splitlines())
+
+        # write via plugin and with phase_mapping with only P
+        # read expected OBS file output
+        filename = os.path.join(self.datapath, "obspyck_20141020150701_P.cnv")
+        with open(filename, "rb") as fh:
+            expected = fh.read().decode()
+
+        with NamedTemporaryFile() as tf:
+            with warnings.catch_warnings(record=True) as w:
+                # Cause all warnings to always be triggered.
+                warnings.simplefilter("always")
+                cat.write(tf, format="CNV", phase_mapping={"P": "P"})
+                tf.seek(0)
+                got = tf.read().decode()
+                # There should be 4 S warnings for the 4 S phases:
+                self.assertEqual(len(w), 4)
+                assert "with unmapped phase hint: S" in str(w[-1].message)
+
+        self.assertEqual(expected.splitlines(), got.splitlines())
 
 
 def suite():