[3.9] bpo-25130: Add calls of gc.collect() in tests to support PyPy (GH-28005). (GH-28028)

(cherry picked from commit 2a8127cafe)
This commit is contained in:
Serhiy Storchaka 2021-08-29 15:08:32 +03:00 committed by GitHub
parent dab74d68e3
commit 330aabbbbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 143 additions and 15 deletions

View file

@ -2,7 +2,7 @@ import sys
import unittest
import tkinter
from tkinter import ttk
from test.support import requires, run_unittest
from test.support import requires, run_unittest, gc_collect
from tkinter.test.support import AbstractTkTest, AbstractDefaultRootTest
requires('gui')
@ -18,6 +18,7 @@ class LabeledScaleTest(AbstractTkTest, unittest.TestCase):
x = ttk.LabeledScale(self.root)
var = x._variable._name
x.destroy()
gc_collect() # For PyPy or other GCs.
self.assertRaises(tkinter.TclError, x.tk.globalgetvar, var)
# manually created variable
@ -30,6 +31,7 @@ class LabeledScaleTest(AbstractTkTest, unittest.TestCase):
else:
self.assertEqual(float(x.tk.globalgetvar(name)), myvar.get())
del myvar
gc_collect() # For PyPy or other GCs.
self.assertRaises(tkinter.TclError, x.tk.globalgetvar, name)
# checking that the tracing callback is properly removed
@ -171,6 +173,7 @@ class LabeledScaleTest(AbstractTkTest, unittest.TestCase):
def test_resize(self):
x = ttk.LabeledScale(self.root)
x.pack(expand=True, fill='both')
gc_collect() # For PyPy or other GCs.
x.update()
width, height = x.master.winfo_width(), x.master.winfo_height()
@ -206,6 +209,7 @@ class OptionMenuTest(AbstractTkTest, unittest.TestCase):
optmenu.destroy()
self.assertEqual(optmenu.tk.globalgetvar(name), var.get())
del var
gc_collect() # For PyPy or other GCs.
self.assertRaises(tkinter.TclError, optmenu.tk.globalgetvar, name)
@ -251,6 +255,7 @@ class OptionMenuTest(AbstractTkTest, unittest.TestCase):
# check that variable is updated correctly
optmenu.pack()
gc_collect() # For PyPy or other GCs.
optmenu['menu'].invoke(0)
self.assertEqual(optmenu._variable.get(), items[0])