[tor-commits] [stem/master] Integ testing for multi-line configs

atagar at torproject.org atagar at torproject.org
Wed Jan 25 15:46:29 UTC 2012


commit 2ae0452fb59ef5781e0803919b02cc0f3fa5212a
Author: Damian Johnson <atagar at torproject.org>
Date:   Tue Jan 24 09:47:51 2012 -0800

    Integ testing for multi-line configs
---
 stem/util/conf.py       |    5 +++++
 test/integ/util/conf.py |   43 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/stem/util/conf.py b/stem/util/conf.py
index 67bd253..63843e5 100644
--- a/stem/util/conf.py
+++ b/stem/util/conf.py
@@ -217,6 +217,11 @@ class Config():
     self._path = path
     self._contents_lock.release()
   
+  # TODO: pending improvements...
+  # - missing pydocs
+  # - integ testing
+  # - does not yet handle multi-line entries
+  # - should have an optional path argument
   def save(self):
     self._contents_lock.acquire()
     
diff --git a/test/integ/util/conf.py b/test/integ/util/conf.py
index 0b4cbc8..6ac37c3 100644
--- a/test/integ/util/conf.py
+++ b/test/integ/util/conf.py
@@ -21,12 +21,36 @@ startup.run export PATH=$PATH:~/bin
 startup.run alias l=ls
 """ % CONF_HEADER
 
+MULTILINE_CONF = """%s
+multiline.entry.simple
+|la de da
+|and a ho hum
+
+multiline.entry.leading_whitespace
+ |la de da
+     |and a ho hum
+
+multiline.entry.empty
+
+multiline.entry.squashed_top
+|la de da
+|and a ho hum
+multiline.entry.squashed_bottom
+|la de da
+|and a ho hum
+"""
+
 class TestConf(unittest.TestCase):
   """
   Tests the stem.util.conf contents.
   """
   
   def tearDown(self):
+    # clears the config contents
+    test_config = stem.util.conf.get_config("integ_testing")
+    test_config.clear()
+    test_config.clear_listeners()
+    
     # cleans up test configurations we made
     if os.path.exists(CONF_PATH):
       os.remove(CONF_PATH)
@@ -46,7 +70,7 @@ class TestConf(unittest.TestCase):
                   "destination.port": 22,
                   "startup.run": []}
     
-    user_config = stem.util.conf.get_config("integ-ssh_login")
+    user_config = stem.util.conf.get_config("integ_testing")
     user_config.load(CONF_PATH)
     user_config.update(ssh_config)
     
@@ -55,6 +79,21 @@ class TestConf(unittest.TestCase):
     self.assertEquals("1.2.3.4", ssh_config["destination.ip"])
     self.assertEquals(22, ssh_config["destination.port"])
     self.assertEquals(["export PATH=$PATH:~/bin", "alias l=ls"], ssh_config["startup.run"])
+  
+  def test_load_multiline(self):
+    """
+    Tests the load method with multi-line configuration files.
+    """
+    
+    test_conf_file = open(CONF_PATH, "w")
+    test_conf_file.write(MULTILINE_CONF)
+    test_conf_file.close()
+    
+    test_config = stem.util.conf.get_config("integ_testing")
+    test_config.load(CONF_PATH)
+    
+    for entry in ("simple", "leading_whitespace", "squashed_top", "squashed_bottom"):
+      self.assertEquals("la de da\nand a ho hum", test_config.get("multiline.entry.%s" % entry))
     
-    user_config.clear()
+    self.assertEquals("", test_config.get("multiline.entry.empty"))
 





More information about the tor-commits mailing list