import gi
gi.require_version("GES", "1.0")
gi.require_version("Gst", "1.0")

from gi.repository import Gst  # noqa
from gi.repository import GES  # noqa
Gst.init(None)
GES.init()


class TestConnection:
    def __init__(self):
        self.asset = GES.Asset.request(GES.EffectClip, "agingtv")
        self.nb_calls = 0

    def callbackCb(self, unused_me, unused1):
        self.nb_calls += 1

test = TestConnection()
test.asset.connect("proxied", test.callbackCb)

test.asset.emit("proxied", None)

print(test.nb_calls)
assert(test.nb_calls == 1)

test.nb_calls = 0
test.asset.connect("proxied", test.callbackCb)
test.asset.emit("proxied", None)

print(test.nb_calls)
assert(test.nb_calls == 2)

test.nb_calls = 0

# That should work but fails
assert(test.asset.disconnect_by_func(test.callbackCb) == 2)

test.asset.emit("proxied", None)
print(test.nb_calls)

# If you remove previous assert, you will see that the callback got called once.
assert(test.nb_calls == 0)
