summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-04-13 21:42:04 +0300
committerLars Wirzenius <liw@liw.fi>2017-04-13 21:42:04 +0300
commitd8e93703719978e521c99b34cc92a2fd6209e13a (patch)
tree25c088853d54fb492df0d3bbeaccc082f3897e0e
parentc3371ea883acd3a5ceb11b8d0daa47633fe28a20 (diff)
downloadserver-yarns-d8e93703719978e521c99b34cc92a2fd6209e13a.tar.gz
Remove now-dead code
-rw-r--r--yarnhelper.py37
-rw-r--r--yarnhelper_tests.py56
2 files changed, 0 insertions, 93 deletions
diff --git a/yarnhelper.py b/yarnhelper.py
index 4ed2c03..5948664 100644
--- a/yarnhelper.py
+++ b/yarnhelper.py
@@ -34,44 +34,7 @@ class YarnHelper(object):
def __init__(self):
self._env = dict(os.environ)
- self._next_match = 1
self._filename = os.path.join(datadir, variables_filename)
- self._variables = None # None means not loaded, otherwise dict
-
- def set_environment(self, env):
- self._env = dict(env)
-
- def get_next_match(self):
- name = 'MATCH_{}'.format(self._next_match)
- if name not in self._env:
- raise Error('no next match')
- self._next_match += 1
- return self._env[name]
-
- def get_variable(self, name, default=None):
- if self._variables is None:
- self._variables = self._load_variables()
- assert self._variables is not None
- return self._variables.get(name, default)
-
- def _load_variables(self):
- if os.path.exists(self._filename):
- with open(self._filename, 'r') as f:
- data = f.read()
- if data:
- f.seek(0)
- return yaml.safe_load(f)
- return {}
-
- def set_variable(self, name, value):
- if self._variables is None:
- self._variables = {}
- self._variables[name] = value
- self._save_variables(self._variables)
-
- def _save_variables(self, variables):
- with open(self._filename, 'w') as f:
- yaml.safe_dump(variables, f)
def construct_aliased_http_request(
self, address, method, url, data=None, headers=None):
diff --git a/yarnhelper_tests.py b/yarnhelper_tests.py
index 858bcdc..5e0f39a 100644
--- a/yarnhelper_tests.py
+++ b/yarnhelper_tests.py
@@ -22,62 +22,6 @@ import unittest
import yarnhelper
-class GetNextMatchTests(unittest.TestCase):
-
- def test_raises_error_if_no_next_match(self):
- h = yarnhelper.YarnHelper()
- h.set_environment({})
- with self.assertRaises(yarnhelper.Error):
- h.get_next_match()
-
- def test_returns_first_match_if_there(self):
- h = yarnhelper.YarnHelper()
- h.set_environment({
- 'MATCH_1': 'first',
- })
- self.assertEqual(h.get_next_match(), 'first')
-
- def test_returns_second_match_if_there(self):
- h = yarnhelper.YarnHelper()
- h.set_environment({
- 'MATCH_1': 'first',
- 'MATCH_2': 'second',
- })
- self.assertEqual(h.get_next_match(), 'first')
- self.assertEqual(h.get_next_match(), 'second')
-
- def test_raises_error_if_no_more_matches(self):
- h = yarnhelper.YarnHelper()
- h.set_environment({
- 'MATCH_1': 'first',
- })
- self.assertEqual(h.get_next_match(), 'first')
- with self.assertRaises(yarnhelper.Error):
- h.get_next_match()
-
-
-class PersistentVariableTests(unittest.TestCase):
-
- def setUp(self):
- # We need this so that tearDown works
- pass
-
- def tearDown(self):
- if os.path.exists(yarnhelper.variables_filename):
- os.remove(yarnhelper.variables_filename)
-
- def test_returns_default_if_no_such_variable(self):
- h = yarnhelper.YarnHelper()
- self.assertEqual(h.get_variable('foo', default=42), 42)
-
- def test_sets_variable_persistently(self):
- h = yarnhelper.YarnHelper()
- h.set_variable('FOO', 'bar')
-
- h2 = yarnhelper.YarnHelper()
- self.assertEqual(h2.get_variable('FOO'), 'bar')
-
-
class HttpTests(unittest.TestCase):
def test_constructs_aliased_request(self):