File: python2.7-testsuite.patch

package info (click to toggle)
python-gflags 1.5.1-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 976 kB
  • sloc: python: 3,374; makefile: 15; sh: 5
file content (111 lines) | stat: -rw-r--r-- 3,677 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
From 10ea9a8a55dc55df0afe3ba80ad1e740103bb697 Mon Sep 17 00:00:00 2001
From: Soren Hansen <soren@ubuntu.com>
Date: Thu, 8 Oct 2015 12:09:58 -0700
Subject: Make test suite pass with Python2.7

 Python 2.7's unittest module introduced some new methods
 that gflags_unittest already had defined. This calls for
 some special handling to avoid having them step on each
 other's toes.
Forwarded: http://code.google.com/p/python-gflags/issues/detail?id=7
Last-Update: 2011-06-14
Patch-Name: python2.7-testsuite.patch
---
 gflags_unittest.py | 40 ++++++++++++++++++++++------------------
 test_module_baz.py | 18 ++++++++++++++++++
 2 files changed, 40 insertions(+), 18 deletions(-)
 create mode 100644 test_module_baz.py

diff --git a/gflags_unittest.py b/gflags_unittest.py
index 250958f..1ec27f0 100755
--- a/gflags_unittest.py
+++ b/gflags_unittest.py
@@ -102,22 +102,34 @@ def MultiLineEqual(expected_help, help):
 
   return False
 
+class _UnitTestClass(unittest.TestCase):
+  def assertListEqual(self, list1, list2, msg=None):
+    """Asserts that, when sorted, list1 and list2 are identical."""
+    if hasattr(super(_UnitTestClass, self), 'assertListEqual'):
+      super(_UnitTestClass, self).assertListEqual(Sorted(list1), Sorted(list2))
+    else:
+      self.assertEqual(Sorted(list1), Sorted(list2))
 
-class FlagsUnitTest(unittest.TestCase):
+  def assertMultiLineEqual(self, expected, actual):
+    """Could do fancy diffing, but for now, just do a normal compare."""
+    self.assert_(MultiLineEqual(expected, actual))
+
+  def assertRaisesWithRegexpMatch(self, exception, regexp, fn, *args, **kwargs):
+    try:
+      fn(*args, **kwargs)
+    except exception, why:
+      self.assert_(re.search(regexp, str(why)),
+                   '"%s" does not match "%s"' % (regexp, why))
+      return
+    self.fail(exception.__name__ + ' not raised')
+
+class FlagsUnitTest(_UnitTestClass):
   "Flags Unit Test"
 
   def setUp(self):
     # make sure we are using the old, stupid way of parsing flags.
     FLAGS.UseGnuGetOpt(False)
 
-  def assertListEqual(self, list1, list2):
-    """Asserts that, when sorted, list1 and list2 are identical."""
-    self.assertEqual(Sorted(list1), Sorted(list2))
-
-  def assertMultiLineEqual(self, expected, actual):
-    self.assert_(MultiLineEqual(expected, actual))
-
-
   def test_flags(self):
 
     ##############################################
@@ -1411,19 +1423,11 @@ class NonGlobalFlagsTest(unittest.TestCase):
     self.assertFalse('x5' in flag_values.RegisteredFlags())
 
 
-class KeyFlagsTest(unittest.TestCase):
+class KeyFlagsTest(_UnitTestClass):
 
   def setUp(self):
     self.flag_values = flags.FlagValues()
 
-  def assertListEqual(self, list1, list2):
-    """Asserts that, when sorted, list1 and list2 are identical."""
-    self.assertEqual(Sorted(list1), Sorted(list2))
-
-  def assertMultiLineEqual(self, s1, s2):
-    """Could do fancy diffing, but for now, just do a normal compare."""
-    self.assertEqual(s1, s2)
-
   def _GetNamesOfDefinedFlags(self, module, flag_values):
     """Returns the list of names of flags defined by a module.
 
diff --git a/test_module_baz.py b/test_module_baz.py
new file mode 100644
index 0000000..7abd416
--- /dev/null
+++ b/test_module_baz.py
@@ -0,0 +1,18 @@
+#!/usr/bin/python2.4
+#
+# Copyright 2010 Google Inc. All Rights Reserved.
+
+"""Auxiliary module for testing flags.py.
+
+The purpose of this module is to test the behavior of flags that are defined
+before main() executes.
+"""
+
+
+__author__ = 'mikecurtis@google.com (Michael Bennett Curtis)'
+
+import gflags as flags
+
+FLAGS = flags.FLAGS
+
+flags.DEFINE_boolean('tmod_baz_x', True, 'Boolean flag.')