Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(482)

Side by Side Diff: tests/rietveld_test.py

Issue 6877038: Improve patch handling and tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/patch_test.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Unit tests for rietveld.py.""" 6 """Unit tests for rietveld.py."""
7 7
8 import logging 8 import logging
9 import os 9 import os
10 import sys 10 import sys
11 import unittest 11 import unittest
12 12
13 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 13 ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
14 sys.path.insert(0, os.path.join(ROOT_DIR, '..')) 14 sys.path.insert(0, os.path.join(ROOT_DIR, '..'))
15 15
16 import patch 16 import patch
17 import rietveld 17 import rietveld
18 18
19 # Access to a protected member XX of a client class 19 # Access to a protected member XX of a client class
20 # pylint: disable=W0212 20 # pylint: disable=W0212
21 21
22 22
23 class RietveldTest(unittest.TestCase): 23 class RietveldTest(unittest.TestCase):
24 def setUp(self):
25 super(RietveldTest, self).setUp()
26 self._rietveld_send = rietveld.Rietveld._send
27 rietveld.Rietveld._send = None
28
29 def tearDown(self):
30 super(RietveldTest, self).setUp()
31 rietveld.Rietveld._send = self._rietveld_send
32
33 def test_get_patch_empty(self): 24 def test_get_patch_empty(self):
34 rietveld.Rietveld._send = lambda x, y, payload: '{}'
35 r = rietveld.Rietveld('url', 'email', 'password') 25 r = rietveld.Rietveld('url', 'email', 'password')
26 r._send = lambda *args, **kwargs: '{}'
36 patches = r.get_patch(123, 456) 27 patches = r.get_patch(123, 456)
37 self.assertTrue(isinstance(patches, patch.PatchSet)) 28 self.assertTrue(isinstance(patches, patch.PatchSet))
38 self.assertEquals([], patches.patches) 29 self.assertEquals([], patches.patches)
39 30
40 def test_get_patch_no_status(self): 31 def test_get_patch_no_status(self):
41 rietveld.Rietveld._send = lambda x, y, payload: ( 32 r = rietveld.Rietveld('url', 'email', 'password')
33 r._send = lambda *args, **kwargs: (
42 '{' 34 '{'
43 ' "files":' 35 ' "files":'
44 ' {' 36 ' {'
45 ' "file_a":' 37 ' "file_a":'
46 ' {' 38 ' {'
47 ' }' 39 ' }'
48 ' }' 40 ' }'
49 '}') 41 '}')
50 r = rietveld.Rietveld('url', 'email', 'password')
51 try: 42 try:
52 r.get_patch(123, 456) 43 r.get_patch(123, 456)
53 self.fail() 44 self.fail()
54 except patch.UnsupportedPatchFormat, e: 45 except patch.UnsupportedPatchFormat, e:
55 self.assertEquals('file_a', e.filename) 46 self.assertEquals('file_a', e.filename)
56 47
57 def test_get_patch_two_files(self): 48 def test_get_patch_two_files(self):
58 output = ( 49 output = (
59 '{' 50 '{'
60 ' "files":' 51 ' "files":'
61 ' {' 52 ' {'
62 ' "file_a":' 53 ' "file_a":'
63 ' {' 54 ' {'
64 ' "status": "A",' 55 ' "status": "A",'
65 ' "is_binary": false,' 56 ' "is_binary": false,'
66 ' "num_chunks": 1,' 57 ' "num_chunks": 1,'
67 ' "id": 789' 58 ' "id": 789'
68 ' }' 59 ' }'
69 ' }' 60 ' }'
70 '}') 61 '}')
71 rietveld.Rietveld._send = lambda x, y, payload: output
72 r = rietveld.Rietveld('url', 'email', 'password') 62 r = rietveld.Rietveld('url', 'email', 'password')
63 r._send = lambda *args, **kwargs: output
73 patches = r.get_patch(123, 456) 64 patches = r.get_patch(123, 456)
74 self.assertTrue(isinstance(patches, patch.PatchSet)) 65 self.assertTrue(isinstance(patches, patch.PatchSet))
75 self.assertEquals(1, len(patches.patches)) 66 self.assertEquals(1, len(patches.patches))
76 obj = patches.patches[0] 67 obj = patches.patches[0]
77 self.assertEquals(patch.FilePatchDiff, obj.__class__) 68 self.assertEquals(patch.FilePatchDiff, obj.__class__)
78 self.assertEquals('file_a', obj.filename) 69 self.assertEquals('file_a', obj.filename)
79 self.assertEquals([], obj.svn_properties) 70 self.assertEquals([], obj.svn_properties)
80 self.assertEquals(False, obj.is_git_diff) 71 self.assertEquals(False, obj.is_git_diff)
81 self.assertEquals(0, obj.patchlevel) 72 self.assertEquals(0, obj.patchlevel)
82 # This is because Rietveld._send() always returns the same buffer. 73 # This is because Rietveld._send() always returns the same buffer.
83 self.assertEquals(output, obj.get()) 74 self.assertEquals(output, obj.get())
84 75
85 76
86 77
87 if __name__ == '__main__': 78 if __name__ == '__main__':
88 logging.basicConfig(level=logging.ERROR) 79 logging.basicConfig(level=logging.ERROR)
89 unittest.main() 80 unittest.main()
OLDNEW
« no previous file with comments | « tests/patch_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698