DevStack supporting tools in python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_ini_remove.py 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # Copyright 2017 IBM
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  4. # not use this file except in compliance with the License. You may obtain
  5. # a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations
  13. # under the License.
  14. # Implementation of ini add / remove for devstack. We don't use the
  15. # python ConfigFile parser because that ends up rewriting the entire
  16. # file and doesn't ensure comments remain.
  17. import fixtures
  18. import testtools
  19. from devstack import dsconf
  20. BASIC = """[default]
  21. a = b
  22. c = d
  23. [second]
  24. e = f
  25. g = h
  26. [new]
  27. s = t
  28. """
  29. RESULT1 = """[default]
  30. c = d
  31. [second]
  32. e = f
  33. g = h
  34. [new]
  35. s = t
  36. """
  37. RESULT2 = """[default]
  38. a = b
  39. c = d
  40. [second]
  41. e = f
  42. [new]
  43. s = t
  44. """
  45. RESULT3 = """[default]
  46. a = b
  47. c = d
  48. [second]
  49. e = f
  50. g = h
  51. [new]
  52. """
  53. class TestIniRemove(testtools.TestCase):
  54. def setUp(self):
  55. super(TestIniRemove, self).setUp()
  56. self._path = self.useFixture(fixtures.TempDir()).path
  57. self._path += "/test.ini"
  58. with open(self._path, "w") as f:
  59. f.write(BASIC)
  60. def test_remove_ini_default(self):
  61. conf = dsconf.IniFile(self._path)
  62. conf.remove("default", "a")
  63. with open(self._path) as f:
  64. content = f.read()
  65. self.assertEqual(content, RESULT1)
  66. def test_remove_ini_second(self):
  67. conf = dsconf.IniFile(self._path)
  68. conf.remove("second", "g")
  69. with open(self._path) as f:
  70. content = f.read()
  71. self.assertEqual(content, RESULT2)
  72. def test_remove_ini_new(self):
  73. conf = dsconf.IniFile(self._path)
  74. conf.remove("new", "s")
  75. with open(self._path) as f:
  76. content = f.read()
  77. self.assertEqual(content, RESULT3)
  78. def test_remove_ini_none(self):
  79. conf = dsconf.IniFile(self._path)
  80. conf.remove("default", "s")
  81. with open(self._path) as f:
  82. content = f.read()
  83. self.assertEqual(content, BASIC)