294 lines
13 KiB
Diff
294 lines
13 KiB
Diff
From ebc0eed6f9838253ae6fcaa51695136611c98298 Mon Sep 17 00:00:00 2001
|
|
From: Christoph Reiter <reiter.christoph@gmail.com>
|
|
Date: Fri, 6 Nov 2020 16:02:43 +0100
|
|
Subject: [PATCH] tests: Remove usage of some deprecated unittest methods
|
|
|
|
---
|
|
tests/__init__.py | 4 ----
|
|
tests/test_gi.py | 36 ++++++++++++++++++------------------
|
|
tests/test_gio.py | 4 ++--
|
|
tests/test_overrides_gdk.py | 4 ++--
|
|
tests/test_overrides_glib.py | 32 ++++++++++++++++----------------
|
|
tests/test_overrides_gtk.py | 18 +++++++++---------
|
|
6 files changed, 47 insertions(+), 51 deletions(-)
|
|
|
|
diff --git a/tests/__init__.py b/tests/__init__.py
|
|
index 3497667..e6dd333 100644
|
|
--- a/tests/__init__.py
|
|
+++ b/tests/__init__.py
|
|
@@ -1,6 +1,5 @@
|
|
import os
|
|
import sys
|
|
-import unittest
|
|
import signal
|
|
import subprocess
|
|
import atexit
|
|
@@ -8,9 +7,6 @@ import warnings
|
|
|
|
|
|
def init_test_environ():
|
|
- # this was renamed in Python 3, provide backwards compatible name
|
|
- unittest.TestCase.assertRegexpMatches = unittest.TestCase.assertRegex
|
|
- unittest.TestCase.assertRaisesRegexp = unittest.TestCase.assertRaisesRegex
|
|
|
|
def dbus_launch_session():
|
|
if os.name == "nt" or sys.platform == "darwin":
|
|
diff --git a/tests/test_gi.py b/tests/test_gi.py
|
|
index 2cabe02..5e7d0e3 100644
|
|
--- a/tests/test_gi.py
|
|
+++ b/tests/test_gi.py
|
|
@@ -2248,22 +2248,22 @@ class TestStructure(unittest.TestCase):
|
|
self.assertRaises(TypeError, GIMarshallingTests.Union.method)
|
|
|
|
def test_repr(self):
|
|
- self.assertRegexpMatches(
|
|
+ self.assertRegex(
|
|
repr(GIMarshallingTests.PointerStruct()),
|
|
r"<GIMarshallingTests.PointerStruct object at 0x[^\s]+ "
|
|
r"\(void at 0x[^\s]+\)>")
|
|
|
|
- self.assertRegexpMatches(
|
|
+ self.assertRegex(
|
|
repr(GIMarshallingTests.SimpleStruct()),
|
|
r"<GIMarshallingTests.SimpleStruct object at 0x[^\s]+ "
|
|
r"\(void at 0x[^\s]+\)>")
|
|
|
|
- self.assertRegexpMatches(
|
|
+ self.assertRegex(
|
|
repr(GIMarshallingTests.Union()),
|
|
r"<GIMarshallingTests.Union object at 0x[^\s]+ "
|
|
r"\(GIMarshallingTestsUnion at 0x[^\s]+\)>")
|
|
|
|
- self.assertRegexpMatches(
|
|
+ self.assertRegex(
|
|
repr(GIMarshallingTests.BoxedStruct()),
|
|
r"<GIMarshallingTests.BoxedStruct object at 0x[^\s]+ "
|
|
r"\(GIMarshallingTestsBoxedStruct at 0x[^\s]+\)>")
|
|
@@ -2399,13 +2399,13 @@ class TestGObject(unittest.TestCase):
|
|
self.assertEqual(new_object.__grefcount__, 1)
|
|
|
|
def test_repr(self):
|
|
- self.assertRegexpMatches(
|
|
+ self.assertRegex(
|
|
repr(GIMarshallingTests.Object(int=42)),
|
|
r"<GIMarshallingTests.Object object at 0x[^\s]+ "
|
|
r"\(GIMarshallingTestsObject at 0x[^\s]+\)>")
|
|
|
|
def test_nongir_repr(self):
|
|
- self.assertRegexpMatches(
|
|
+ self.assertRegex(
|
|
repr(Gio.File.new_for_path("")),
|
|
r"<__gi__.GLocalFile object at 0x[^\s]+ "
|
|
r"\(GLocalFile at 0x[^\s]+\)>")
|
|
@@ -3208,7 +3208,7 @@ class TestDeprecation(unittest.TestCase):
|
|
self.assertEqual(len(warn), 3)
|
|
self.assertTrue(
|
|
issubclass(warn[0].category, PyGIDeprecationWarning))
|
|
- self.assertRegexpMatches(
|
|
+ self.assertRegex(
|
|
str(warn[0].message),
|
|
".*GLib.IO_STATUS_ERROR.*GLib.IOStatus.ERROR.*")
|
|
|
|
@@ -3244,8 +3244,8 @@ class TestDeprecation(unittest.TestCase):
|
|
fn(self, 1, 2, 3)
|
|
self.assertEqual(len(warn), 1)
|
|
self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning))
|
|
- self.assertRegexpMatches(str(warn[0].message),
|
|
- '.*keyword.*a, b, c.*')
|
|
+ self.assertRegex(str(warn[0].message),
|
|
+ '.*keyword.*a, b, c.*')
|
|
|
|
def test_deprecated_init_no_keywords_out_of_order(self):
|
|
def init(self, **kwargs):
|
|
@@ -3257,8 +3257,8 @@ class TestDeprecation(unittest.TestCase):
|
|
fn(self, 2, 1, 3)
|
|
self.assertEqual(len(warn), 1)
|
|
self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning))
|
|
- self.assertRegexpMatches(str(warn[0].message),
|
|
- '.*keyword.*b, a, c.*')
|
|
+ self.assertRegex(str(warn[0].message),
|
|
+ '.*keyword.*b, a, c.*')
|
|
|
|
def test_deprecated_init_ignored_keyword(self):
|
|
def init(self, **kwargs):
|
|
@@ -3272,8 +3272,8 @@ class TestDeprecation(unittest.TestCase):
|
|
fn(self, 1, 2, 3)
|
|
self.assertEqual(len(warn), 1)
|
|
self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning))
|
|
- self.assertRegexpMatches(str(warn[0].message),
|
|
- '.*keyword.*a, b, c.*')
|
|
+ self.assertRegex(str(warn[0].message),
|
|
+ '.*keyword.*a, b, c.*')
|
|
|
|
def test_deprecated_init_with_aliases(self):
|
|
def init(self, **kwargs):
|
|
@@ -3288,8 +3288,8 @@ class TestDeprecation(unittest.TestCase):
|
|
fn(self, a=1, bb=2, cc=3)
|
|
self.assertEqual(len(warn), 1)
|
|
self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning))
|
|
- self.assertRegexpMatches(str(warn[0].message),
|
|
- '.*keyword.*"bb, cc".*deprecated.*"b, c" respectively')
|
|
+ self.assertRegex(str(warn[0].message),
|
|
+ '.*keyword.*"bb, cc".*deprecated.*"b, c" respectively')
|
|
|
|
def test_deprecated_init_with_defaults(self):
|
|
def init(self, **kwargs):
|
|
@@ -3303,6 +3303,6 @@ class TestDeprecation(unittest.TestCase):
|
|
fn(self, a=1)
|
|
self.assertEqual(len(warn), 1)
|
|
self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning))
|
|
- self.assertRegexpMatches(str(warn[0].message),
|
|
- '.*relying on deprecated non-standard defaults.*'
|
|
- 'explicitly use: b=2, c=3')
|
|
+ self.assertRegex(str(warn[0].message),
|
|
+ '.*relying on deprecated non-standard defaults.*'
|
|
+ 'explicitly use: b=2, c=3')
|
|
diff --git a/tests/test_gio.py b/tests/test_gio.py
|
|
index 3b812c4..07ee506 100644
|
|
--- a/tests/test_gio.py
|
|
+++ b/tests/test_gio.py
|
|
@@ -50,8 +50,8 @@ class TestGio(unittest.TestCase):
|
|
Gio.VolumeMonitor()
|
|
self.assertEqual(len(warn), 1)
|
|
self.assertTrue(issubclass(warn[0].category, PyGIWarning))
|
|
- self.assertRegexpMatches(str(warn[0].message),
|
|
- '.*Gio\\.VolumeMonitor\\.get\\(\\).*')
|
|
+ self.assertRegex(str(warn[0].message),
|
|
+ '.*Gio\\.VolumeMonitor\\.get\\(\\).*')
|
|
|
|
|
|
class TestGSettings(unittest.TestCase):
|
|
diff --git a/tests/test_overrides_gdk.py b/tests/test_overrides_gdk.py
|
|
index 1788ef6..d959571 100644
|
|
--- a/tests/test_overrides_gdk.py
|
|
+++ b/tests/test_overrides_gdk.py
|
|
@@ -227,8 +227,8 @@ class TestGdk(unittest.TestCase):
|
|
|
|
self.assertEqual(len(warn), 1)
|
|
self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning))
|
|
- self.assertRegexpMatches(str(warn[0].message),
|
|
- '.*new_from_pixbuf.*')
|
|
+ self.assertRegex(str(warn[0].message),
|
|
+ '.*new_from_pixbuf.*')
|
|
|
|
self.assertRaises(ValueError, Gdk.Cursor, 1, 2, 3)
|
|
|
|
diff --git a/tests/test_overrides_glib.py b/tests/test_overrides_glib.py
|
|
index d8f1a6c..08c41ae 100644
|
|
--- a/tests/test_overrides_glib.py
|
|
+++ b/tests/test_overrides_glib.py
|
|
@@ -691,30 +691,30 @@ class TestGVariant(unittest.TestCase):
|
|
|
|
def test_parse_error_exceptions(self):
|
|
source_str = 'abc'
|
|
- self.assertRaisesRegexp(TypeError, 'Must be GLib.Error, not int',
|
|
- GLib.Variant.parse_error_print_context,
|
|
- 42, source_str)
|
|
+ self.assertRaisesRegex(TypeError, 'Must be GLib.Error, not int',
|
|
+ GLib.Variant.parse_error_print_context,
|
|
+ 42, source_str)
|
|
|
|
gerror = GLib.Error(message=42) # not a string
|
|
- self.assertRaisesRegexp(TypeError, ".*Must be string, not int.*",
|
|
- GLib.Variant.parse_error_print_context,
|
|
- gerror, source_str)
|
|
+ self.assertRaisesRegex(TypeError, ".*Must be string, not int.*",
|
|
+ GLib.Variant.parse_error_print_context,
|
|
+ gerror, source_str)
|
|
|
|
gerror = GLib.Error(domain=42) # not a string
|
|
- self.assertRaisesRegexp(TypeError, ".*Must be string, not int.*",
|
|
- GLib.Variant.parse_error_print_context,
|
|
- gerror, source_str)
|
|
+ self.assertRaisesRegex(TypeError, ".*Must be string, not int.*",
|
|
+ GLib.Variant.parse_error_print_context,
|
|
+ gerror, source_str)
|
|
|
|
gerror = GLib.Error(code='not an int')
|
|
- self.assertRaisesRegexp(TypeError, ".*Must be number, not str.*",
|
|
- GLib.Variant.parse_error_print_context,
|
|
- gerror, source_str)
|
|
+ self.assertRaisesRegex(TypeError, ".*Must be number, not str.*",
|
|
+ GLib.Variant.parse_error_print_context,
|
|
+ gerror, source_str)
|
|
|
|
gerror = GLib.Error(code=GLib.MAXUINT)
|
|
- self.assertRaisesRegexp(OverflowError,
|
|
- ".*not in range.*",
|
|
- GLib.Variant.parse_error_print_context,
|
|
- gerror, source_str)
|
|
+ self.assertRaisesRegex(OverflowError,
|
|
+ ".*not in range.*",
|
|
+ GLib.Variant.parse_error_print_context,
|
|
+ gerror, source_str)
|
|
|
|
|
|
class TestConstants(unittest.TestCase):
|
|
diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py
|
|
index 30ad1d8..091a6a2 100644
|
|
--- a/tests/test_overrides_gtk.py
|
|
+++ b/tests/test_overrides_gtk.py
|
|
@@ -403,8 +403,8 @@ class TestGtk(unittest.TestCase):
|
|
self.assertTrue(dialog.get_modal())
|
|
self.assertEqual(len(warn), 1)
|
|
self.assertTrue(issubclass(warn[0].category, PyGTKDeprecationWarning))
|
|
- self.assertRegexpMatches(str(warn[0].message),
|
|
- '.*flags.*modal.*')
|
|
+ self.assertRegex(str(warn[0].message),
|
|
+ '.*flags.*modal.*')
|
|
|
|
with warnings.catch_warnings(record=True) as warn:
|
|
warnings.simplefilter('always')
|
|
@@ -412,8 +412,8 @@ class TestGtk(unittest.TestCase):
|
|
self.assertTrue(dialog.get_destroy_with_parent())
|
|
self.assertEqual(len(warn), 1)
|
|
self.assertTrue(issubclass(warn[0].category, PyGTKDeprecationWarning))
|
|
- self.assertRegexpMatches(str(warn[0].message),
|
|
- '.*flags.*destroy_with_parent.*')
|
|
+ self.assertRegex(str(warn[0].message),
|
|
+ '.*flags.*destroy_with_parent.*')
|
|
|
|
def test_dialog_deprecation_stacklevels(self):
|
|
# Test warning levels are setup to give the correct filename for
|
|
@@ -425,7 +425,7 @@ class TestGtk(unittest.TestCase):
|
|
warnings.simplefilter('always')
|
|
Gtk.Dialog(flags=Gtk.DialogFlags.MODAL)
|
|
self.assertEqual(len(warn), 1)
|
|
- self.assertRegexpMatches(warn[0].filename, '.*test_overrides_gtk.*')
|
|
+ self.assertRegex(warn[0].filename, '.*test_overrides_gtk.*')
|
|
|
|
# Validate overridden base with overridden sub-class.
|
|
self.assertEqual(Gtk.MessageDialog, gi.overrides.Gtk.MessageDialog)
|
|
@@ -433,7 +433,7 @@ class TestGtk(unittest.TestCase):
|
|
warnings.simplefilter('always')
|
|
Gtk.MessageDialog(flags=Gtk.DialogFlags.MODAL)
|
|
self.assertEqual(len(warn), 1)
|
|
- self.assertRegexpMatches(warn[0].filename, '.*test_overrides_gtk.*')
|
|
+ self.assertRegex(warn[0].filename, '.*test_overrides_gtk.*')
|
|
|
|
# Validate overridden base with non-overridden sub-class.
|
|
self.assertEqual(Gtk.AboutDialog, gi.repository.Gtk.AboutDialog)
|
|
@@ -441,7 +441,7 @@ class TestGtk(unittest.TestCase):
|
|
warnings.simplefilter('always')
|
|
Gtk.AboutDialog(flags=Gtk.DialogFlags.MODAL)
|
|
self.assertEqual(len(warn), 1)
|
|
- self.assertRegexpMatches(warn[0].filename, '.*test_overrides_gtk.*')
|
|
+ self.assertRegex(warn[0].filename, '.*test_overrides_gtk.*')
|
|
|
|
def test_dialog_add_buttons(self):
|
|
# The overloaded "buttons" keyword gives a warning when attempting
|
|
@@ -452,8 +452,8 @@ class TestGtk(unittest.TestCase):
|
|
buttons=('test-button1', 1))
|
|
self.assertEqual(len(warn), 1)
|
|
self.assertTrue(issubclass(warn[0].category, PyGTKDeprecationWarning))
|
|
- self.assertRegexpMatches(str(warn[0].message),
|
|
- '.*ButtonsType.*add_buttons.*')
|
|
+ self.assertRegex(str(warn[0].message),
|
|
+ '.*ButtonsType.*add_buttons.*')
|
|
|
|
dialog.add_buttons('test-button2', 2, 'gtk-close', Gtk.ResponseType.CLOSE)
|
|
button = dialog.get_widget_for_response(1)
|
|
--
|
|
1.8.3.1
|
|
|