summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian C. Lane <bcl@redhat.com>2012-08-08 09:22:40 -0700
committerBrian C. Lane <bcl@redhat.com>2012-08-09 08:22:27 -0700
commit7d9df4be41df3a044d9179d7e13df86dafe82324 (patch)
treea58c978a0f34c45b8cc28390b469fce56a5b260b
parent58728f08187dcca003036d0d58cff62d5e3f44ee (diff)
downloadanaconda-7d9df4be41df3a044d9179d7e13df86dafe82324.tar.gz
anaconda-7d9df4be41df3a044d9179d7e13df86dafe82324.tar.xz
anaconda-7d9df4be41df3a044d9179d7e13df86dafe82324.zip
tests: Add tests for new SimpleConfigFile features
-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)