diff options
author | Friedemann Kleint <[email protected]> | 2024-12-19 08:49:25 +0100 |
---|---|---|
committer | Friedemann Kleint <[email protected]> | 2024-12-20 10:14:45 +0100 |
commit | 6eb75a26498f8984345fcdd5434b6758819f0d7f (patch) | |
tree | db4b6b7b706bb3443c946014cec48315f3e9ec7c /sources/pyside6/tests/QtGui | |
parent | 6a3161e3fea6b84106b3dfcd84b541e643c9e531 (diff) |
qpixmap_test.py: Fix warning about leaking file handle
Port to pathlib, fixing:
sources/pyside6/tests/QtGui/qpixmap_test.py:42: ResourceWarning:
unclosed file <_io.BufferedReader name='/data0/frkleint/pyside-setup6i/sources/pyside6/tests/QtGui/sample.png'>
data = open(os.path.join(os.path.dirname(__file__), 'sample.png'), 'rb').read()
ResourceWarning: Enable tracemalloc to get the object allocation traceback
Pick-to: 6.8
Change-Id: I8417719eb150aae9e04b5ff706e3934b398e7381
Reviewed-by: Shyamnath Premnadh <[email protected]>
Diffstat (limited to 'sources/pyside6/tests/QtGui')
-rw-r--r-- | sources/pyside6/tests/QtGui/qpixmap_test.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/sources/pyside6/tests/QtGui/qpixmap_test.py b/sources/pyside6/tests/QtGui/qpixmap_test.py index 0dcd71064..12be6d28c 100644 --- a/sources/pyside6/tests/QtGui/qpixmap_test.py +++ b/sources/pyside6/tests/QtGui/qpixmap_test.py @@ -17,6 +17,11 @@ from PySide6.QtCore import QFile, QIODevice, QObject, QSize, Qt class QPixmapTest(UsesQApplication): + + def setUp(self): + super().setUp() + self._sample_file = Path(__file__).resolve().parent / 'sample.png' + def testQVariantConstructor(self): obj = QObject() pixmap = QPixmap() @@ -31,7 +36,7 @@ class QPixmapTest(UsesQApplication): pixmap = QPixmap("Testing!") # noqa: F841 def testQPixmapLoadFromDataWithQFile(self): - f = QFile(os.path.join(os.path.dirname(__file__), 'sample.png')) + f = QFile(self._sample_file) self.assertTrue(f.open(QIODevice.ReadOnly)) data = f.read(f.size()) f.close() @@ -39,7 +44,8 @@ class QPixmapTest(UsesQApplication): self.assertTrue(pixmap.loadFromData(data)) def testQPixmapLoadFromDataWithPython(self): - data = open(os.path.join(os.path.dirname(__file__), 'sample.png'), 'rb').read() + with self._sample_file.open('rb') as f: + data = f.read() pixmap = QPixmap() self.assertTrue(pixmap.loadFromData(data)) |