Skip to content

sgnl.gracedb

FakeGracedbClient

Bases: object

A drop-in stand-in for ligo.gracedb.rest.GraceDb used when the service URL is a file:// path (offline runs and tests).

The methods accept **kwargs so they tolerate v2/Kafka-only arguments (kafka, http_fallback, offline, labels, ...) without the caller needing to special-case the fake client.

Source code in sgnl/gracedb.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class FakeGracedbClient(object):
    """A drop-in stand-in for ``ligo.gracedb.rest.GraceDb`` used when the
    service URL is a ``file://`` path (offline runs and tests).

    The methods accept ``**kwargs`` so they tolerate v2/Kafka-only arguments
    (``kafka``, ``http_fallback``, ``offline``, ``labels``, ...) without the
    caller needing to special-case the fake client.
    """

    def __init__(self, service_url):
        # Assumes that service url is a directory to write files to
        self.path = urlparse(service_url).path

    def createEvent(
        self, group, pipeline, filename, filecontents, search=None, **kwargs
    ):
        with open(os.path.join(self.path, filename), "w") as f:
            f.write(filecontents)
        return FakeGracedbResp()

    def writeLog(self, *args, **kwargs):
        return FakeGracedbResp()

    def writeLabel(self, *args, **kwargs):
        return FakeGracedbResp()