~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Vincent Ladeuil
  • Date: 2011-04-04 15:31:16 UTC
  • mto: (5743.5.1 config-concrete-stores)
  • mto: This revision was merged to the branch mainline in revision 5832.
  • Revision ID: v.ladeuil+lp@free.fr-20110404153116-86oshhkw9nboow6z
Implement store.get_sections() as an iterator and provides the configobj implementation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1893
1893
 
1894
1894
    # FIXME: parametrize against all valid (store, transport) combinations
1895
1895
 
1896
 
    def get_store(self, content=None, name=None):
 
1896
    def get_store(self, name=None, content=None):
1897
1897
        if name is None:
1898
1898
            name = 'foo.conf'
1899
1899
        if content is None:
1905
1905
 
1906
1906
    def test_delayed_load(self):
1907
1907
        self.build_tree_contents([('foo.conf', '')])
1908
 
        store = self.get_store(None, 'foo.conf')
 
1908
        store = self.get_store('foo.conf')
1909
1909
        self.assertEquals(False, store.loaded)
1910
1910
        store.load()
1911
1911
        self.assertEquals(True, store.loaded)
1912
1912
 
1913
1913
    def test_from_string_delayed_load(self):
1914
 
        store = self.get_store('')
 
1914
        store = self.get_store('foo.conf', '')
1915
1915
        self.assertEquals(False, store.loaded)
1916
1916
        store.load()
1917
1917
        self.assertEquals(True, store.loaded)
1919
1919
        self.failIfExists('foo.conf')
1920
1920
 
1921
1921
    def test_invalid_content(self):
1922
 
        store = self.get_store('this is invalid !', 'foo.conf')
 
1922
        store = self.get_store('foo.conf', 'this is invalid !')
1923
1923
        self.assertEquals(False, store.loaded)
1924
1924
        exc = self.assertRaises(errors.ParseConfigError, store.load)
1925
1925
        self.assertEndsWith(exc.filename, 'foo.conf')
1927
1927
        self.assertEquals(False, store.loaded)
1928
1928
 
1929
1929
    def test_save_empty_succeeds(self):
1930
 
        store = self.get_store('', 'foo.conf')
 
1930
        store = self.get_store('foo.conf', '')
1931
1931
        store.load()
1932
1932
        self.failIfExists('foo.conf')
1933
1933
        store.save()
1934
1934
        self.failUnlessExists('foo.conf')
1935
1935
 
1936
1936
    def test_save_with_content_succeeds(self):
1937
 
        store = self.get_store('foo=bar\n', 'foo.conf')
 
1937
        store = self.get_store('foo.conf', 'foo=bar\n')
1938
1938
        store.load()
1939
1939
        self.failIfExists('foo.conf')
1940
1940
        store.save()
1942
1942
        # FIXME: Far too ConfigObj specific
1943
1943
        self.assertFileEqual('foo = bar\n', 'foo.conf')
1944
1944
 
 
1945
    def test_get_no_sections_for_empty(self):
 
1946
        store = self.get_store('foo.conf', '')
 
1947
        store.load()
 
1948
        self.assertEquals([], list(store.get_sections()))
 
1949
 
 
1950
    def test_get_default_section(self):
 
1951
        store = self.get_store('foo.conf', 'foo=bar')
 
1952
        sections = list(store.get_sections())
 
1953
        self.assertLength(1, sections)
 
1954
        self.assertEquals((None, {'foo': 'bar'}), sections[0])
 
1955
 
 
1956
    def test_get_named_section(self):
 
1957
        store = self.get_store('foo.conf', '[baz]\nfoo=bar')
 
1958
        sections = list(store.get_sections())
 
1959
        self.assertLength(1, sections)
 
1960
        self.assertEquals(('baz', {'foo': 'bar'}), sections[0])
 
1961
 
 
1962
    def test_get_embedded_sections(self):
 
1963
        store = self.get_store('foo.conf', '''
 
1964
foo=bar
 
1965
l=1,2
 
1966
[DEFAULT]
 
1967
foo_in_DEFAULT=foo_DEFAULT
 
1968
[bar]
 
1969
foo_in_bar=barbar
 
1970
[baz]
 
1971
foo_in_baz=barbaz
 
1972
[[qux]]
 
1973
foo_in_qux=quux
 
1974
''')
 
1975
        sections = list(store.get_sections())
 
1976
        self.assertLength(4, sections)
 
1977
        # The default section has no name.
 
1978
        # List values are provided as lists
 
1979
        self.assertEquals((None, {'foo': 'bar', 'l': ['1', '2']}), sections[0])
 
1980
        self.assertEquals(('DEFAULT', {'foo_in_DEFAULT': 'foo_DEFAULT'}),
 
1981
                          sections[1])
 
1982
        self.assertEquals(('bar', {'foo_in_bar': 'barbar'}), sections[2])
 
1983
        # sub sections are provided as embedded dicts.
 
1984
        self.assertEquals(('baz', {'foo_in_baz': 'barbaz',
 
1985
                                   'qux': {'foo_in_qux': 'quux'}}),
 
1986
                          sections[3])
 
1987
 
1945
1988
 
1946
1989
class TestConfigGetOptions(tests.TestCaseWithTransport, TestOptionsMixin):
1947
1990