14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Tests for finding and reading the bzr properties file[s]."""
17
"""Tests for finding and reading the bzr attributes file[s]."""
22
22
from bzrlib import (
27
27
from bzrlib.util.configobj import configobj
30
class TestPropertiesPath(tests.TestCase):
30
class TestAttributesPath(tests.TestCase):
33
super(TestPropertiesPath, self).setUp()
33
super(TestAttributesPath, self).setUp()
34
34
os.environ['HOME'] = '/home/bogus'
35
35
if sys.platform == 'win32':
36
36
os.environ['BZR_HOME'] = \
41
41
self.bzr_home = '/home/bogus/.bazaar'
43
def test_properties_filename(self):
44
self.assertEqual(properties.properties_filename(),
45
self.bzr_home + '/fileproperties')
48
class TestPropertiesProvider(tests.TestCase):
43
def test_attributes_filename(self):
44
self.assertEqual(attributes.attributes_filename(),
45
self.bzr_home + '/attributes')
48
class TestAttributesProvider(tests.TestCase):
50
50
def make_provider(self, lines):
51
"""Make a _PropertiesProvider from a list of strings"""
51
"""Make a _AttributesProvider from a list of strings"""
52
52
# This works even though the API doesn't document it yet
53
return properties._PropertiesProvider(lines)
53
return attributes._FileBasedAttributesProvider(lines)
55
def test_get_properties_file_missing(self):
55
def test_get_attributes_file_missing(self):
56
56
pp = self.make_provider(None)
57
self.assertEquals({}, pp.get_properties('a.txt'))
58
self.assertEquals({'foo': None}, pp.get_properties('a.txt', ['foo']))
57
self.assertEquals({}, pp.get_attributes('a.txt'))
58
self.assertEquals({'foo': None}, pp.get_attributes('a.txt', ['foo']))
60
def test_get_properties_file_empty(self):
60
def test_get_attributes_file_empty(self):
61
61
pp = self.make_provider([])
62
self.assertEquals({}, pp.get_properties('a.txt'))
63
self.assertEquals({'foo': None}, pp.get_properties('a.txt', ['foo']))
62
self.assertEquals({}, pp.get_attributes('a.txt'))
63
self.assertEquals({'foo': None}, pp.get_attributes('a.txt', ['foo']))
65
def test_get_properties_from_extension_match(self):
65
def test_get_attributes_from_extension_match(self):
66
66
pp = self.make_provider(["[*.txt]", "foo=bar", "a=True"])
67
self.assertEquals({}, pp.get_properties('a.py'))
68
self.assertEquals({'foo':'bar', 'a': 'True'},
69
pp.get_properties('a.txt'))
70
self.assertEquals({'foo':'bar', 'a': 'True'},
71
pp.get_properties('dir/a.txt'))
67
self.assertEquals({}, pp.get_attributes('a.py'))
68
self.assertEquals({'foo':'bar', 'a': 'True'},
69
pp.get_attributes('a.txt'))
70
self.assertEquals({'foo':'bar', 'a': 'True'},
71
pp.get_attributes('dir/a.txt'))
72
72
self.assertEquals({'foo':'bar'},
73
pp.get_properties('a.txt', ['foo']))
73
pp.get_attributes('a.txt', ['foo']))
75
def test_get_properties_pathname_match(self):
75
def test_get_attributes_pathname_match(self):
76
76
pp = self.make_provider(["[./a.txt]", "foo=baz"])
77
self.assertEquals({'foo':'baz'}, pp.get_properties('a.txt'))
78
self.assertEquals({}, pp.get_properties('dir/a.txt'))
77
self.assertEquals({'foo':'baz'}, pp.get_attributes('a.txt'))
78
self.assertEquals({}, pp.get_attributes('dir/a.txt'))
80
def test_get_properties_match_first(self):
80
def test_get_attributes_match_first(self):
81
81
pp = self.make_provider([
82
82
"[./a.txt]", "foo=baz",
83
83
"[*.txt]", "foo=bar", "a=True"])
84
self.assertEquals({'foo':'baz'}, pp.get_properties('a.txt'))
84
self.assertEquals({'foo':'baz'}, pp.get_attributes('a.txt'))
85
85
self.assertEquals({'foo':'bar', 'a': 'True'},
86
pp.get_properties('dir/a.txt'))
86
pp.get_attributes('dir/a.txt'))