~jfb-tempo-consulting/unifield-wm/sync-env-py3

« back to all changes in this revision

Viewing changes to unittest27/case.py

  • Committer: jf
  • Date: 2022-02-01 10:24:52 UTC
  • mfrom: (173.1.1 sync-env)
  • Revision ID: jfb@tempo-consulting.fr-20220201102452-rndr3uvmo030kqlf
[MERGE] US-9423: instance registration: do not validate an instance with no group on the sync server

Show diffs side-by-side

added added

removed removed

Lines of Context:
121
121
            return True
122
122
 
123
123
        expected_regexp = self.expected_regexp
124
 
        if isinstance(expected_regexp, str):
 
124
        if isinstance(expected_regexp, basestring):
125
125
            expected_regexp = re.compile(expected_regexp)
126
126
        if not expected_regexp.search(str(exc_value)):
127
127
            raise self.failureException('"%s" does not match "%s"' %
201
201
        self.addTypeEqualityFunc(tuple, 'assertTupleEqual')
202
202
        self.addTypeEqualityFunc(set, 'assertSetEqual')
203
203
        self.addTypeEqualityFunc(frozenset, 'assertSetEqual')
204
 
        self.addTypeEqualityFunc(str, 'assertMultiLineEqual')
 
204
        self.addTypeEqualityFunc(unicode, 'assertMultiLineEqual')
205
205
 
206
206
    def addTypeEqualityFunc(self, typeobj, function):
207
207
        """Add a type specific assertEqual style function to compare a type.
490
490
        if type(first) is type(second):
491
491
            asserter = self._type_equality_funcs.get(type(first))
492
492
            if asserter is not None:
493
 
                if isinstance(asserter, str):
 
493
                if isinstance(asserter, basestring):
494
494
                    asserter = getattr(self, asserter)
495
495
                return asserter
496
496
 
670
670
            elements = (seq_type_name.capitalize(), seq1_repr, seq2_repr)
671
671
            differing = '%ss differ: %s != %s\n' % elements
672
672
 
673
 
            for i in range(min(len1, len2)):
 
673
            for i in xrange(min(len1, len2)):
674
674
                try:
675
675
                    item1 = seq1[i]
676
676
                except (TypeError, IndexError, NotImplementedError):
765
765
        """
766
766
        try:
767
767
            difference1 = set1.difference(set2)
768
 
        except TypeError as e:
 
768
        except TypeError, e:
769
769
            self.fail('invalid type when attempting set difference: %s' % e)
770
 
        except AttributeError as e:
 
770
        except AttributeError, e:
771
771
            self.fail('first argument does not support set difference: %s' % e)
772
772
 
773
773
        try:
774
774
            difference2 = set2.difference(set1)
775
 
        except TypeError as e:
 
775
        except TypeError, e:
776
776
            self.fail('invalid type when attempting set difference: %s' % e)
777
 
        except AttributeError as e:
 
777
        except AttributeError, e:
778
778
            self.fail('second argument does not support set difference: %s' % e)
779
779
 
780
780
        if not (difference1 or difference2):
836
836
        """Checks whether actual is a superset of expected."""
837
837
        missing = []
838
838
        mismatched = []
839
 
        for key, value in expected.items():
 
839
        for key, value in expected.iteritems():
840
840
            if key not in actual:
841
841
                missing.append(key)
842
842
            elif value != actual[key]:
900
900
 
901
901
    def assertMultiLineEqual(self, first, second, msg=None):
902
902
        """Assert that two multi-line strings are equal."""
903
 
        self.assertIsInstance(first, str,
 
903
        self.assertIsInstance(first, basestring,
904
904
                'First argument is not a string')
905
 
        self.assertIsInstance(second, str,
 
905
        self.assertIsInstance(second, basestring,
906
906
                'Second argument is not a string')
907
907
 
908
908
        if first != second:
990
990
 
991
991
    def assertRegexpMatches(self, text, expected_regexp, msg=None):
992
992
        """Fail the test unless the text matches the regular expression."""
993
 
        if isinstance(expected_regexp, str):
 
993
        if isinstance(expected_regexp, basestring):
994
994
            expected_regexp = re.compile(expected_regexp)
995
995
        if not expected_regexp.search(text):
996
996
            msg = msg or "Regexp didn't match"
999
999
 
1000
1000
    def assertNotRegexpMatches(self, text, unexpected_regexp, msg=None):
1001
1001
        """Fail the test if the text matches the regular expression."""
1002
 
        if isinstance(unexpected_regexp, str):
 
1002
        if isinstance(unexpected_regexp, basestring):
1003
1003
            unexpected_regexp = re.compile(unexpected_regexp)
1004
1004
        match = unexpected_regexp.search(text)
1005
1005
        if match: