<commit_before># Copyright 2013 <NAME>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.

import unittest

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk


class SignalTest(unittest.TestCase):

    def test_connect(self):
        w = Gtk.Window()
        id_ = w.connect("map", lambda *x: None)
        self.assertTrue(isinstance(id_, (long, int)))
        w.disconnect(id_)

    def test_connect_after(self):
        w = Gtk.Window()
        id_ = w.connect_after("map", lambda *x: None)
        self.assertTrue(isinstance(id_, (long, int)))
        w.disconnect(id_)

    def test_handler_block(self):
        w = Gtk.Window()
        id_ = w.connect_after("map", lambda *x: None)
        w.handler_block(id_)
        w.handler_unblock(id_)
        w.disconnect(id_)

    def test_connect_invalid(self):
        w = Gtk.Window()
        self.assertRaises(TypeError, w.connect, "map", None)
        self.assertRaises(TypeError, w.connect, "foobar", lambda *x: None)
        self.assertRaises(TypeError, w.connect_after, "foobar", lambda: None)

    def test_connect_user_data(self):
        w = Gtk.Window()
        id_ = w.connect("map", lambda *x: None, 1, 2, 3, 4)
        w.disconnect(id_)

    def test_subclass_connect(self):
        class A(Gtk.Window):
            def __init__(self):
                Gtk.Window.__init__(self)
        class B(A):
            def __init__(self):
                A.__init__(self)

        x = B()
        id_ = x.connect("map", lambda *x: None)
        x.disconnect(id_)

    def test_name_under(self):
         w = Gtk.Window()
         for name in ["scroll-event", "scroll_event"]:
             id_ = w.connect("scroll_event", lambda *x: None)
             self.failUnless(id_ is not None)


class SignalReturnTest(unittest.TestCase):

    def test_bool(self):
        window = Gtk.OffscreenWindow()
        area = Gtk.DrawingArea()
        window.add(area)
        called = [0]
        def foo(area, context):
            called[0] += 1
            return True
        area.connect("draw", foo)
        area.connect("draw", foo)
        window.show_all()
        while Gtk.events_pending():
            Gtk.main_iteration()
        window.destroy()
        self.assertEqual(called[0], 1)<commit_msg>this one can hang, limit iterations<commit_after># Copyright 2013 <NAME>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.

import unittest

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk


class SignalTest(unittest.TestCase):

    def test_connect(self):
        w = Gtk.Window()
        id_ = w.connect("map", lambda *x: None)
        self.assertTrue(isinstance(id_, (long, int)))
        w.disconnect(id_)

    def test_connect_after(self):
        w = Gtk.Window()
        id_ = w.connect_after("map", lambda *x: None)
        self.assertTrue(isinstance(id_, (long, int)))
        w.disconnect(id_)

    def test_handler_block(self):
        w = Gtk.Window()
        id_ = w.connect_after("map", lambda *x: None)
        w.handler_block(id_)
        w.handler_unblock(id_)
        w.disconnect(id_)

    def test_connect_invalid(self):
        w = Gtk.Window()
        self.assertRaises(TypeError, w.connect, "map", None)
        self.assertRaises(TypeError, w.connect, "foobar", lambda *x: None)
        self.assertRaises(TypeError, w.connect_after, "foobar", lambda: None)

    def test_connect_user_data(self):
        w = Gtk.Window()
        id_ = w.connect("map", lambda *x: None, 1, 2, 3, 4)
        w.disconnect(id_)

    def test_subclass_connect(self):
        class A(Gtk.Window):
            def __init__(self):
                Gtk.Window.__init__(self)
        class B(A):
            def __init__(self):
                A.__init__(self)

        x = B()
        id_ = x.connect("map", lambda *x: None)
        x.disconnect(id_)

    def test_name_under(self):
         w = Gtk.Window()
         for name in ["scroll-event", "scroll_event"]:
             id_ = w.connect("scroll_event", lambda *x: None)
             self.failUnless(id_ is not None)


class SignalReturnTest(unittest.TestCase):

    def test_bool(self):
        window = Gtk.OffscreenWindow()
        area = Gtk.DrawingArea()
        window.add(area)
        called = [0]
        def foo(area, context):
            called[0] += 1
            return True
        area.connect("draw", foo)
        area.connect("draw", foo)
        window.show_all()
        for x in xrange(100):
            Gtk.main_iteration_do(False)
        window.destroy()
        self.assertEqual(called[0], 1)
{'fraction_non_alphanumeric': 0.12048192771084337, 'fraction_numerical': 0.007429718875502008, 'mean_word_length': 2.3542087542087544, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1859919', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1545, 'n_words': 398}