comparison tests/test_push_autoprops.py @ 911:772280aed751

Honor SVN auto-props (solves issue #186) The auto-props are read from the users subversion configuration file (~/.subversion/config on posix). System-wide configuration files are not taken into account. The implementation completely bypasses the subversion bindings, because the current bindings provide little support for this functionality.
author Ronny Voelker <ronny.voelker@googlemail.com>
date Sun, 01 Jan 2012 15:59:15 +0100
parents
children d741f536f23a
comparison
equal deleted inserted replaced
910:312f36a425f0 911:772280aed751
1 import subprocess
2 import sys
3 import unittest
4 import os
5
6 import test_util
7
8 from hgsubversion import svnwrap
9
10 class PushAutoPropsTests(test_util.TestBase):
11 def setUp(self):
12 test_util.TestBase.setUp(self)
13 repo, self.repo_path = self.load_and_fetch('emptyrepo.svndump')
14
15 def test_push_honors_svn_autoprops(self):
16 self.setup_svn_config(
17 "[miscellany]\n"
18 "enable-auto-props = yes\n"
19 "[auto-props]\n"
20 "*.py = test:prop=success\n")
21 changes = [('test.py', 'test.py', 'echo hallo')]
22 self.commitchanges(changes)
23 self.pushrevisions(True)
24 prop_val = test_util.svnpropget(
25 self.repo_path, "trunk/test.py", 'test:prop')
26 self.assertEqual('success', prop_val)
27
28
29 class AutoPropsConfigTest(test_util.TestBase):
30 def test_use_autoprops_for_matching_file_when_enabled(self):
31 self.setup_svn_config(
32 "[miscellany]\n"
33 "enable-auto-props = yes\n"
34 "[auto-props]\n"
35 "*.py = test:prop=success\n")
36 props = self.new_autoprops_config().properties('xxx/test.py')
37 self.assertEqual({ 'test:prop': 'success'}, props)
38
39 def new_autoprops_config(self):
40 return svnwrap.AutoPropsConfig(self.config_dir)
41
42 def test_ignore_nonexisting_config(self):
43 config_file = os.path.join(self.config_dir, 'config')
44 os.remove(config_file)
45 self.assertTrue(not os.path.exists(config_file))
46 props = self.new_autoprops_config().properties('xxx/test.py')
47 self.assertEqual({}, props)
48
49 def test_ignore_autoprops_when_file_doesnt_match(self):
50 self.setup_svn_config(
51 "[miscellany]\n"
52 "enable-auto-props = yes\n"
53 "[auto-props]\n"
54 "*.py = test:prop=success\n")
55 props = self.new_autoprops_config().properties('xxx/test.sh')
56 self.assertEqual({}, props)
57
58 def test_ignore_autoprops_when_disabled(self):
59 self.setup_svn_config(
60 "[miscellany]\n"
61 "#enable-auto-props = yes\n"
62 "[auto-props]\n"
63 "*.py = test:prop=success\n")
64 props = self.new_autoprops_config().properties('xxx/test.py')
65 self.assertEqual({}, props)
66
67 def test_combine_properties_of_multiple_matches(self):
68 self.setup_svn_config(
69 "[miscellany]\n"
70 "enable-auto-props = yes\n"
71 "[auto-props]\n"
72 "*.py = test:prop=success\n"
73 "test.* = test:prop2=success\n")
74 props = self.new_autoprops_config().properties('xxx/test.py')
75 self.assertEqual({
76 'test:prop': 'success', 'test:prop2': 'success'}, props)
77
78
79 class ParseAutoPropsTests(test_util.TestBase):
80 def test_property_value_is_optional(self):
81 props = svnwrap.parse_autoprops("svn:executable")
82 self.assertEqual({'svn:executable': ''}, props)
83 props = svnwrap.parse_autoprops("svn:executable=")
84 self.assertEqual({'svn:executable': ''}, props)
85
86 def test_property_value_may_be_quoted(self):
87 props = svnwrap.parse_autoprops("svn:eol-style=\" native \"")
88 self.assertEqual({'svn:eol-style': ' native '}, props)
89 props = svnwrap.parse_autoprops("svn:eol-style=' native '")
90 self.assertEqual({'svn:eol-style': ' native '}, props)
91
92 def test_surrounding_whitespaces_are_ignored(self):
93 props = svnwrap.parse_autoprops(" svn:eol-style = native ")
94 self.assertEqual({'svn:eol-style': 'native'}, props)
95
96 def test_multiple_properties_are_separated_by_semicolon(self):
97 props = svnwrap.parse_autoprops(
98 "svn:eol-style=native;svn:executable=true\n")
99 self.assertEqual({
100 'svn:eol-style': 'native',
101 'svn:executable': 'true'},
102 props)
103
104
105 def suite():
106 return unittest.findTestCases(sys.modules[__name__])
107