1894
1894
# FIXME: parametrize against all valid (store, transport) combinations
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:
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)
1911
1911
self.assertEquals(True, store.loaded)
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)
1917
1917
self.assertEquals(True, store.loaded)
1919
1919
self.failIfExists('foo.conf')
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)
1929
1929
def test_save_empty_succeeds(self):
1930
store = self.get_store('', 'foo.conf')
1930
store = self.get_store('foo.conf', '')
1932
1932
self.failIfExists('foo.conf')
1934
1934
self.failUnlessExists('foo.conf')
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')
1939
1939
self.failIfExists('foo.conf')
1942
1942
# FIXME: Far too ConfigObj specific
1943
1943
self.assertFileEqual('foo = bar\n', 'foo.conf')
1945
def test_get_no_sections_for_empty(self):
1946
store = self.get_store('foo.conf', '')
1948
self.assertEquals([], list(store.get_sections()))
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])
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])
1962
def test_get_embedded_sections(self):
1963
store = self.get_store('foo.conf', '''
1967
foo_in_DEFAULT=foo_DEFAULT
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'}),
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'}}),
1946
1989
class TestConfigGetOptions(tests.TestCaseWithTransport, TestOptionsMixin):