[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [arm/master] Removing _load_settings()



commit 4a79df1cdd55340ce4faba03a65e289079689772
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Dec 21 17:46:52 2013 -0800

    Removing _load_settings()
    
    The _load_settings() helper was purely for our tests. Our starter loads the
    settings, and as such tests that relied on those settings wouldn't work. On
    reflection it's better to simply have the test starter do the same rather than
    have this in a helper function.
---
 arm/starter.py                |   31 ++++++-------------------------
 run_tests.py                  |    5 +++++
 test/starter/authenticate.py  |    3 ---
 test/starter/load_settings.py |   31 -------------------------------
 4 files changed, 11 insertions(+), 59 deletions(-)

diff --git a/arm/starter.py b/arm/starter.py
index 779421a..6913275 100644
--- a/arm/starter.py
+++ b/arm/starter.py
@@ -53,30 +53,6 @@ CONFIG = stem.util.conf.config_dict("arm", {
 })
 
 
-def _load_settings(config = 'arm'):
-  """
-  Loads arm's internal settings from its 'settings.cfg'. This comes bundled
-  with arm and should be considered to be an error if it can't be loaded. If
-  the settings have already been loaded then this is a no-op.
-
-  :param str config: configuration config to load the parameters into
-
-  :returns: **stem.util.conf.Config** for the given handle
-
-  :raises: **ValueError** if the settings can't be loaded
-  """
-
-  config = stem.util.conf.get_config(config)
-
-  if not config.get('settings_loaded', False):
-    try:
-      config.load(SETTINGS_PATH)
-    except IOError as exc:
-      raise ValueError("Unable to load arm's internal configuration (%s): %s" % (SETTINGS_PATH, exc))
-
-  return config
-
-
 def _get_controller(args):
   """
   Provides a Controller for the endpoint specified in the given arguments.
@@ -210,7 +186,12 @@ def main():
   config.set('attribute.start_time', str(int(time.time())))
 
   try:
-    _load_settings()
+    config.load(SETTINGS_PATH)
+  except IOError as exc:
+    print "Unable to load arm's internal configuration (%s): %s" % (SETTINGS_PATH, exc)
+    sys.exit(1)
+
+  try:
     args = arm.arguments.parse(sys.argv[1:])
   except getopt.GetoptError as exc:
     print "%s (for usage provide --help)" % exc
diff --git a/run_tests.py b/run_tests.py
index 1b7d544..52b8fd7 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -10,6 +10,8 @@ the test coverage we can achieve, but exercising what we can.
 import os
 import unittest
 
+import stem.util.conf
+
 
 def clean_orphaned_pyc():
   for root, _, files in os.walk(os.path.dirname(__file__)):
@@ -26,6 +28,9 @@ def clean_orphaned_pyc():
 
 
 def main():
+  settings_path = os.path.join(os.path.dirname(__file__), 'arm', 'settings.cfg')
+  stem.util.conf.get_config('arm').load(settings_path)
+
   clean_orphaned_pyc()
 
   tests = unittest.defaultTestLoader.discover('test', pattern='*.py')
diff --git a/test/starter/authenticate.py b/test/starter/authenticate.py
index 17c846e..b2f7592 100644
--- a/test/starter/authenticate.py
+++ b/test/starter/authenticate.py
@@ -3,7 +3,6 @@ import unittest
 from mock import Mock, patch
 
 from arm.starter import (
-  _load_settings,
   _get_controller,
   _authenticate,
 )
@@ -12,8 +11,6 @@ import stem
 import stem.connection
 import stem.socket
 
-_load_settings()
-
 
 class TestAuthenticate(unittest.TestCase):
   @patch('arm.util.torTools.get_chroot')
diff --git a/test/starter/load_settings.py b/test/starter/load_settings.py
deleted file mode 100644
index c0a2dfa..0000000
--- a/test/starter/load_settings.py
+++ /dev/null
@@ -1,31 +0,0 @@
-import io
-import unittest
-
-from mock import patch
-
-from arm.starter import _load_settings
-
-
-class TestArgumentParsing(unittest.TestCase):
-  def test_we_can_load_the_settings(self):
-    config = _load_settings(self.id())
-    self.assertEqual(config.get('settings_loaded'), 'true')
-
-  @patch('stem.util.conf.open', create = True)
-  def test_when_file_doesnt_exist(self, open_mock):
-    open_mock.side_effect = IOError("No such file or directory")
-
-    try:
-      _load_settings(self.id())
-      self.fail("We didn't raise an exception for a missing settings.cfg")
-    except ValueError as exc:
-      self.assertTrue("Unable to load arm's internal configuration" in str(exc))
-
-  @patch('stem.util.conf.open', create = True)
-  def test_that_repeated_calls_are_ignored(self, open_mock):
-    open_mock.return_value = io.BytesIO("settings_loaded true")
-
-    _load_settings(self.id())
-    _load_settings(self.id())
-    _load_settings(self.id())
-    self.assertEqual(1, open_mock.call_count)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits