~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_gpg.py

MergeĀ fromĀ martin

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
    def test_returns_output(self):
48
48
        # This test needs a 'cat' command or similar to work.
49
49
        my_gpg = gpg.GPGStrategy(FakeConfig())
50
 
        my_gpg._command_line = lambda:["cat", "-"]
51
 
        self.assertEqual("some content\nwith newlines\n",
52
 
                         my_gpg.sign("some content\nwith newlines\n"))
 
50
        content = "some content\nwith newlines\n"
 
51
 
 
52
        if sys.platform == 'win32':
 
53
            # Windows doesn't come with cat, and we don't require it
 
54
            # so lets try using python instead.
 
55
            # But stupid windows and line-ending conversions. 
 
56
            # It is too much work to make sys.stdout be in binary mode.
 
57
            # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65443
 
58
            my_gpg._command_line = lambda:[sys.executable, '-c',
 
59
                    'import sys; sys.stdout.write(sys.stdin.read())']
 
60
            new_content = content.replace('\n', '\r\n')
 
61
 
 
62
            self.assertEqual(new_content, my_gpg.sign(content))
 
63
        else:
 
64
            my_gpg._command_line = lambda:['cat', '-']
 
65
            self.assertEqual(content, my_gpg.sign(content))
53
66
 
54
67
 
55
68
class TestDisabled(TestCase):