comparison tests/test_fetch_command_regexes.py @ 859:1d07e86f5797

stupid: handle changes in svn 1.7 diff format Metadata changes are now represented like: Property changes on: a ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* instead of: Property changes on: a ___________________________________________________________________ Added: svn:executable + * Also, I got tired of massaging the diff with regexps, so I extracted the parsing logic in parsediff(). This is no small refactoring but it makes things cleaner and the test suite pass on 1.6 and 1.7 so...
author Patrick Mezard <patrick@mezard.eu>
date Thu, 19 Apr 2012 14:59:50 +0200
parents 46e69be8e2c8
children d741f536f23a
comparison
equal deleted inserted replaced
858:bb6a013abaed 859:1d07e86f5797
46 46
47 """ 47 """
48 48
49 class RegexTests(unittest.TestCase): 49 class RegexTests(unittest.TestCase):
50 def test_empty_file_re(self): 50 def test_empty_file_re(self):
51 matches = stupid.empty_file_patch_wont_make_re.findall(two_empties) 51 changed = stupid.parsediff(two_empties)
52 assert sorted(matches) == ['__init__.py', 'bar/__init__.py'] 52 self.assertEqual(3, len(changed))
53 self.assertEqual('__init__.py', changed[0].name)
54 self.assert_(changed[0].isempty())
55 self.assertEqual('bar/__init__.py', changed[1].name)
56 self.assert_(changed[1].isempty())
57 self.assertEqual('bar/test_muhaha.py', changed[2].name)
58 self.assert_(not changed[2].isempty())
53 59
54 def test_any_matches_just_one(self): 60 def test_any_matches_just_one(self):
55 pat = '''Index: trunk/django/contrib/admin/urls/__init__.py 61 pat = '''Index: trunk/django/contrib/admin/urls/__init__.py
56 =================================================================== 62 ===================================================================
57 ''' 63 '''
58 matches = stupid.any_file_re.findall(pat) 64 changed = stupid.parsediff(pat)
59 assert len(matches) == 1 65 self.assertEqual(['trunk/django/contrib/admin/urls/__init__.py'],
66 [f.name for f in changed])
60 67
61 def test_special_re(self): 68 def test_special_re(self):
62 matches = stupid.property_special_set_re.findall(special_delta) 69 changed = stupid.parsediff(special_delta)
63 assert len(matches) == 1 70 self.assertEqual(1, len(changed))
71 self.assert_(changed[0].symlink)
64 72
65 def test_any_file_re(self): 73 def test_any_file_re(self):
66 matches = stupid.any_file_re.findall(two_empties) 74 changed = stupid.parsediff(two_empties)
67 assert sorted(matches) == ['__init__.py', 'bar/__init__.py', 75 self.assertEqual(['__init__.py', 'bar/__init__.py', 'bar/test_muhaha.py'],
68 'bar/test_muhaha.py'] 76 [f.name for f in changed])
69 77
70 def test_binary_file_re(self): 78 def test_binary_file_re(self):
71 matches = stupid.binary_file_re.findall(binary_delta) 79 changed = stupid.parsediff(binary_delta)
72 assert matches == ['trunk/functional_tests/doc_tests/test_doctest_fixtures/doctest_fixtures_fixtures.pyc'] 80 binaries = [f.name for f in changed if f.binary]
81 self.assertEqual(['trunk/functional_tests/doc_tests/test_doctest_fixtures/doctest_fixtures_fixtures.pyc'],
82 binaries)
83
84 def test_diff16(self):
85 data = """Index: d3/d
86 ===================================================================
87 --- d3/d (revision 0)
88 +++ d3/d (revision 6)
89 @@ -0,0 +1 @@
90 +d
91
92 Property changes on: d3
93 ___________________________________________________________________
94 Added: svn:externals
95 + ^/trunk/common/ext ext3
96
97
98
99 Property changes on: .
100 ___________________________________________________________________
101 Added: svn:mergeinfo
102 Merged /branches/branch:r4-5
103 """
104 changed = stupid.parsediff(data)
105 self.assertEqual(['d3/d', 'd3', '.'], [f.name for f in changed])
106 data = """Property changes on: empty1
107 ___________________________________________________________________
108 Deleted: svn:executable
109 - *
110
111
112 Property changes on: empty2
113 ___________________________________________________________________
114 Added: svn:executable
115 + *
116
117
118 Property changes on: binary1
119 ___________________________________________________________________
120 Deleted: svn:executable
121 - *
122
123
124 Property changes on: text1
125 ___________________________________________________________________
126 Deleted: svn:executable
127 - *
128
129
130 Property changes on: binary2
131 ___________________________________________________________________
132 Added: svn:executable
133 + *
134
135
136 Property changes on: text2
137 ___________________________________________________________________
138 Added: svn:executable
139 + *
140 """
141 changed = stupid.parsediff(data)
142 self.assertEqual(['empty1', 'empty2', 'binary1', 'text1', 'binary2', 'text2'],
143 [f.name for f in changed])
73 144
74 def suite(): 145 def suite():
75 return unittest.TestLoader().loadTestsFromTestCase(RegexTests) 146 return unittest.TestLoader().loadTestsFromTestCase(RegexTests)