Repository: gwpy/gwosc

Issue:
Exact match when query for event time
In the latest version of the client, there is an error thrown when trying to get the GPS time of GW190521

```
from gwosc import datasets
t0 = datasets.event_gps('GW190521')
```

The error message says that the query for this event name gets multiple events (e.g. includes GW190521_074343).  This is not a great behavior, because I really want the GPS time of 'GW190521'.  I think when asking for a GPS time, it would be best to demand an exact match in the name (not a substring).

This seems to be a change from version 0.5.8 to 0.6.0.  

Discussion:
jkanner: @duncanmmacleod  Thank you!  

Patch:
diff --git a/gwosc/api.py b/gwosc/api.py
index 5f00576..7c5d2ec 100644
--- a/gwosc/api.py
+++ b/gwosc/api.py
@@ -241,9 +241,17 @@ def _fetch_allevents_event_json(
             return
         return True
 
+    # match datasets
     matched = list(filter(_match, allevents.items()))
     names = set(x[1]["commonName"] for x in matched)
-    if matched and len(names) == 1:
+
+    # one dataset has an exact name match, so discard everything else
+    if event in names:
+        matched = [x for x in matched if x[1]["commonName"] == event]
+        names = set(x[1]["commonName"] for x in matched)
+
+    # we have a winner!
+    if len(names) == 1:
         key, meta = sorted(matched, key=lambda x: x[1]["version"])[-1]
         return {"events": {key: meta}}
 


Test patch:
diff --git a/gwosc/tests/test_api.py b/gwosc/tests/test_api.py
index fa33ce6..2905c83 100644
--- a/gwosc/tests/test_api.py
+++ b/gwosc/tests/test_api.py
@@ -161,8 +161,14 @@ def test_fetch_event_json_error_not_found():
         api.fetch_event_json("blah")
 
 
+@pytest.mark.remote
+def test_fetch_event_json_exact_match():
+    data, = list(api.fetch_event_json("GW190521")["events"].values())
+    assert data["commonName"] == "GW190521"
+
+
 @pytest.mark.remote
 def test_fetch_event_json_error_multiple_names():
     with pytest.raises(ValueError) as exc:
-        api.fetch_event_json("GW190521")
-    assert str(exc.value).startswith("multiple events matched for 'GW190521'")
+        api.fetch_event_json("GW190828")
+    assert str(exc.value).startswith("multiple events matched for 'GW190828'")