def test_gobject_unsupported_overrides(self): obj = GObject.Object() with self.assertRaisesRegex(RuntimeError, 'Data access methods are unsupported.*'): obj.get_data() with self.assertRaisesRegex(RuntimeError, 'This method is currently unsupported.*'): obj.force_floating()
def test_instance_argument_base_type_error(self): # ensure TypeError is raised when a base type is passed to something # expecting a derived type obj = Regress.TestSubObj() self.assertEqual(Regress.TestSubObj.instance_method(obj), 0) self.assertRaises(TypeError, Regress.TestSubObj.instance_method, GObject.Object()) self.assertRaises(TypeError, Regress.TestSubObj.instance_method, Regress.TestObj())
def test_object_argument_type_error(self): # ensure TypeError is raised for things which are not GObjects obj = Regress.TestObj() obj.set_bare(GObject.Object()) obj.set_bare(None) self.assertRaises(TypeError, obj.set_bare, object()) self.assertRaises(TypeError, obj.set_bare, 42) self.assertRaises(TypeError, obj.set_bare, 'not an object')
def test_gobject_weak_ref(): called = [] def callback(*args): called.extend(args) # object gets finalized obj = GObject.Object() obj.weak_ref(callback, 1) del obj gc.collect() gc.collect() assert called == [1] del called[:] # wrapper gets finalized first obj = GObject.Object() pyref = weakref.ref(obj, lambda x: callback(-2)) value = GObject.Value(GObject.Object, obj) ref = obj.weak_ref(callback, 2) del obj gc.collect() assert called == [-2] del pyref value.unset() gc.collect() assert called == [-2, 2] del called[:] # weakref gets unregistered first obj = GObject.Object() ref = obj.weak_ref(callback, 3) ref.unref() del obj gc.collect() assert not called # weakref gets GCed obj = GObject.Object() obj.weak_ref(callback, 4) gc.collect() del obj assert called == [4]
def test_instance_argument_error(self): # ensure TypeError is raised for non Regress.TestObj instances. obj = Regress.TestObj() self.assertEqual(Regress.TestObj.instance_method(obj), -1) self.assertRaises(TypeError, Regress.TestObj.instance_method, object()) self.assertRaises(TypeError, Regress.TestObj.instance_method, GObject.Object()) self.assertRaises(TypeError, Regress.TestObj.instance_method, 42) self.assertRaises(TypeError, Regress.TestObj.instance_method, 'not an object')
def test_obj_repr(self): w = Gtk.Window() r = repr(w) self.assertTrue("<Window" in r) self.assertTrue("GtkWindow" in r) self.assertTrue(str(hex(int(id(w)))) in r) g = GObject.Object() r = repr(g) self.assertTrue("GObject" in r) self.assertTrue(str(hex(int(id(g)))) in r)
def test_held_object_ref_count_getter(self): holder = GIMarshallingTests.PropertiesObject() held = GObject.Object() self.assertEqual(holder.__grefcount__, 1) self.assertEqual(held.__grefcount__, 1) self.set_prop(holder, 'some-object', held) self.assertEqual(holder.__grefcount__, 1) initial_ref_count = held.__grefcount__ self.get_prop(holder, 'some-object') gc.collect() self.assertEqual(held.__grefcount__, initial_ref_count)
def test_props_getter_holding_object_ref_count(self): holder = GIMarshallingTests.PropertiesObject() held = GObject.Object() self.assertEqual(holder.__grefcount__, 1) self.assertEqual(held.__grefcount__, 1) holder.set_property('some-object', held) self.assertEqual(holder.__grefcount__, 1) initial_ref_count = held.__grefcount__ holder.props.some_object gc.collect() self.assertEqual(held.__grefcount__, initial_ref_count)
def idle_func(): new_obj = GObject.Object() new_obj.archive = common.get_archive(archive_name, False) stats = new_obj.archive.calc_stats(common.cur_rep_cache) new_obj.fingerprint = binascii.hexlify( new_obj.archive.id).decode('ascii') new_obj.info = { 'hostname': new_obj.archive.metadata[b'hostname'], 'username': new_obj.archive.metadata[b'username'], 'time_start': borg.helpers.format_time( borg.helpers.to_localtime(new_obj.archive.ts)), 'time_end': borg.helpers.format_time( borg.helpers.to_localtime(new_obj.archive.ts_end)), 'command': ' '.join(new_obj.archive.metadata[b'cmdline']), 'n_files': str(stats.nfiles), 'original_size': stats.osize_fmt, 'compressed_size': stats.csize_fmt, 'deduplicated_size': stats.usize_fmt } model[iterator][2] = new_obj if not hasattr(model, 'all_info'): summary = common.cur_rep_cache.chunks.summarize() model.all_info = { 'all_original_size': borg.helpers.format_file_size(summary[0]), 'all_compressed_size': borg.helpers.format_file_size(summary[1]), 'all_deduplicated_size': borg.helpers.format_file_size(summary[3]), 'unique_chunks': str(summary[4]), 'total_chunks': str(summary[5]) } set_info_labels() select_grid.show_all() transitions.unload()
def test_held_object_ref_count_setter(self): holder = GIMarshallingTests.PropertiesObject() held = GObject.Object() self.assertEqual(holder.__grefcount__, 1) self.assertEqual(held.__grefcount__, 1) # Setting property should only increase ref count by 1 self.set_prop(holder, 'some-object', held) self.assertEqual(holder.__grefcount__, 1) self.assertEqual(held.__grefcount__, 2) # Clearing should pull it back down self.set_prop(holder, 'some-object', None) self.assertEqual(held.__grefcount__, 1)
def test_props_setter_holding_object_ref_count(self): holder = GIMarshallingTests.PropertiesObject() held = GObject.Object() self.assertEqual(holder.__grefcount__, 1) self.assertEqual(held.__grefcount__, 1) # Setting property should only increase ref count by 1 holder.props.some_object = held self.assertEqual(holder.__grefcount__, 1) self.assertEqual(held.__grefcount__, 2) # Clearing should pull it back down holder.props.some_object = None self.assertEqual(held.__grefcount__, 1)
def test_classes(self): g = GObject.Object() self.assertTrue(isinstance(g, GObject.Object)) a = Gtk.AccelMap() self.assertTrue(isinstance(a, type(g)))