Fix unit tests for SVN 1.6 and Python 2.6

Review Request #7503 — Created July 8, 2015 and submitted — Latest diff uploaded

Information

RBTools
release-0.7.x
2fb7e92...

Reviewers

This patch fixes some issues with Python 2.6 compatability and using
SVN 1.6.

All tests using TestCase.assertIn(element, container) have been
rewritten to use TestCase.assertTrue(element in Container). All tests
using TestCase.assertRaises as a context manager have been rewritten
to not use a context manager.

The tests that operate on the output of svn diff have been modified
to have a decorator applied to them that will supply the correct hash
depending on the current version of SVN. This is required because SVN
prior to 1.7 will generate a different diff.

The aliases module has been updated to ensure that on pre Python 2.7.3
that the command is passed as a binary string and not a unicode string.
Support in shlex.split for unicode strings was added in Python
2.7.3.

Unit tests passed using all the following combinations:

  • Python 2.6, SVN 1.6
  • Python 2.6, SVN 1.8
  • Python 2.6, SVN 1.6
  • Python 2.6, SVN 1.8

Changes between revision 1 and 2

orig
1
2
rbtools/utils/aliases.py
rbtools/utils/aliases.py
Diff Revision 1 Diff Revision 2
30 lines
def arg_sub(m):
31
        except IndexError:
31
        except IndexError:
32
            return ''
32
            return ''
33

    
   
33

   
34
    did_replacement = False
34
    did_replacement = False
35

    
   
35

   
36
    translated = False
36
    shlex_convert_text_type = (not _SHLEX_SUPPORTS_UNICODE and

    
   
37
                               isinstance(cmd, six.text_type))
37

    
   
38

   
38
    if not _SHLEX_SUPPORTS_UNICODE and isinstance(cmd, six.text_type):
39
    if shlex_convert_text_type:
39
        cmd = cmd.encode('utf-8')
40
        cmd = cmd.encode('utf-8')
40
        translated = True

   
41

    
   
41

   
42
    for part in shlex.split(cmd):
42
    for part in shlex.split(cmd):
43
        if part == '$*':
43
        if part == '$*':
44
            did_replacement = True
44
            did_replacement = True
45

    
   
45

   
46
            for arg in args:
46
            for arg in args:
47
                yield arg
47
                yield arg
48
        else:
48
        else:
49
            part, subs = _arg_re.subn(arg_sub, part)
49
            part, subs = _arg_re.subn(arg_sub, part)
50

    
   
50

   
51
            if subs != 0:
51
            if subs != 0:
52
                did_replacement = True
52
                did_replacement = True
53

    
   
53

   
54
            if translated:
54
            if shlex_convert_text_type:
55
                part = part.decode('utf-8')
55
                part = part.decode('utf-8')
56

    
   
56

   
57
            yield part
57
            yield part
58

    
   
58

   
59
    if not did_replacement:
59
    if not did_replacement:
25 lines