summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/pyanaconda_test/simpleconfig_test.py48
1 files changed, 41 insertions, 7 deletions
diff --git a/tests/pyanaconda_test/simpleconfig_test.py b/tests/pyanaconda_test/simpleconfig_test.py
index ab59f5d83..265ed8879 100644
--- a/tests/pyanaconda_test/simpleconfig_test.py
+++ b/tests/pyanaconda_test/simpleconfig_test.py
@@ -7,14 +7,10 @@ import sys
class SimpleconfigTest(mock.TestCase):
def setUp(self):
self.setupModules(["_isys", "block", "ConfigParser"])
- self.fs = mock.DiskIO()
import pyanaconda.simpleconfig
- pyanaconda.simpleconfig.open = self.fs.open
- pyanaconda.simpleconfig.os = mock.Mock() # Mock os module
- pyanaconda.simpleconfig.os.path = os.path # except os.path part
# Stuff for IfcfgFile class tests
- self.DIR = '/etc/sysconfig/network-scripts/'
+ self.DIR = '/tmp/'
self.IFACE = 'eth0'
self.PATH = "%sifcfg-%s" % (self.DIR, self.IFACE)
self.CONTENT = '# Broadcom Corporation NetXtreme BCM5761 Gigabit Ethernet\n'
@@ -52,6 +48,18 @@ class SimpleconfigTest(mock.TestCase):
ret = pyanaconda.simpleconfig.uppercase_ASCII_string('')
self.assertEqual(ret, '')
+ def unquote_test(self):
+ from pyanaconda.simpleconfig import unquote
+ self.assertEqual(unquote("plain string"), "plain string")
+ self.assertEqual(unquote('"double quote"'), "double quote")
+ self.assertEqual(unquote("'single quote'"), "single quote")
+
+ def quote_test(self):
+ from pyanaconda.simpleconfig import quote
+ self.assertEqual(quote("nospaces"), "nospaces")
+ self.assertEqual(quote("plain string"), '"plain string"')
+ self.assertEqual(quote("alwaysquote", always=True), '"alwaysquote"')
+
def set_and_get_test(self):
"""Setting and getting values"""
import pyanaconda.simpleconfig
@@ -77,15 +85,41 @@ class SimpleconfigTest(mock.TestCase):
scf = pyanaconda.simpleconfig.SimpleConfigFile()
scf.set(('key1', 'value1'))
scf.write('/tmp/file')
- self.assertEqual(self.fs['/tmp/file'], 'KEY1="value1"\n')
+ self.assertEqual(open('/tmp/file').read(), 'KEY1=value1\n')
def read_test(self):
import pyanaconda.simpleconfig
scf = pyanaconda.simpleconfig.SimpleConfigFile()
- self.fs.open('/tmp/file', 'w').write('KEY1="value1"\n')
+ open('/tmp/file', 'w').write('KEY1="value1"\n')
scf.read('/tmp/file')
self.assertEqual(scf.get('key1'), 'value1')
+ def read_write_test(self):
+ from pyanaconda.simpleconfig import SimpleConfigFile
+ scf = SimpleConfigFile()
+ scf.read(self.PATH)
+ scf.write("/tmp/file")
+ self.assertEqual(open("/tmp/file").read(), self.CONTENT)
+
+ def write_new_keys_test(self):
+ from pyanaconda.simpleconfig import SimpleConfigFile
+ scf = SimpleConfigFile()
+ scf.read(self.PATH)
+ scf.set(("key1", "value1"))
+ scf.write("/tmp/file")
+ self.assertEqual(open("/tmp/file").read(),
+ self.CONTENT+"KEY1=value1\n")
+
+ def remove_key_test(self):
+ from pyanaconda.simpleconfig import SimpleConfigFile
+ scf = SimpleConfigFile()
+ scf.read(self.PATH)
+ scf.unset("BOOT")
+ scf.write("/tmp/file")
+ scf.reset()
+ scf.read("/tmp/file")
+ self.assertEqual(scf.get("BOOT"), "")
+
def ifcfgfile_path_property_test(self):
import pyanaconda.simpleconfig
scf = pyanaconda.simpleconfig.IfcfgFile(self.DIR, self.IFACE)