diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-04-14 15:40:28 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-04-14 15:44:16 +0300 |
commit | e84c04d32dba8a7c7ebd799bc00696a6a6589640 (patch) | |
tree | 23ccc1b286336c2d17e91d57487f21f54cccf81f | |
parent | 30ff2822d2da0365858211a1becafa77252d2671 (diff) | |
download | vmdb2-e84c04d32dba8a7c7ebd799bc00696a6a6589640.tar.gz |
User yarnutils's persistent variables, drop YarnHelper's
-rw-r--r-- | yarns/900-implements.yarn | 16 | ||||
-rw-r--r-- | yarns/lib.py | 2 | ||||
-rw-r--r-- | yarns/yarnhelper.py | 31 | ||||
-rw-r--r-- | yarns/yarnhelper_tests.py | 25 |
4 files changed, 10 insertions, 64 deletions
diff --git a/yarns/900-implements.yarn b/yarns/900-implements.yarn index e3e4a86..f8bc328 100644 --- a/yarns/900-implements.yarn +++ b/yarns/900-implements.yarn @@ -12,22 +12,22 @@ This chapter contains the implementations for all scenario steps. args = get_next_match() vmdb2 = os.path.join(srcdir, 'vmdb2') exit, out, err = cliapp.runcmd_unchecked([vmdb2] + args.split()) - helper.set_variable('exit', exit) - helper.set_variable('stdout', out) - helper.set_variable('stderr', err) + vars['exit'] = exit + vars['stdout'] = out + vars['stderr'] = err IMPLEMENTS THEN exit code is (\d+) wanted = int(get_next_match()) - exit = helper.get_variable('exit') + exit = vars['exit'] print 'exit code', exit - print 'stdout:', helper.get_variable('stdout') - print 'stderr:', helper.get_variable('stderr') + print 'stdout:', vars['stdout'] + print 'stderr:', vars['stderr'] assertEqual(exit, wanted) IMPLEMENTS THEN stdout contains "(.+)" followed by "(.+)" first = get_next_match() second = get_next_match() - stdout = helper.get_variable('stdout') + stdout = vars['stdout'] first_i = stdout.find(first) assertGreaterThan(first_i, 0) rest = stdout[first_i + len(first):] @@ -36,6 +36,6 @@ This chapter contains the implementations for all scenario steps. IMPLEMENTS THEN stdout does NOT contain "(\S+)" what = get_next_match() - stdout = helper.get_variable('stdout') + stdout = vars['stdout'] i = stdout.find(what) assertEqual(i, -1) diff --git a/yarns/lib.py b/yarns/lib.py index 2ea6eed..f463ab0 100644 --- a/yarns/lib.py +++ b/yarns/lib.py @@ -9,4 +9,6 @@ import yarnhelper srcdir = os.environ['SRCDIR'] datadir = os.environ['DATADIR'] +vars = Variables(datadir) + helper = yarnhelper.YarnHelper() diff --git a/yarns/yarnhelper.py b/yarns/yarnhelper.py index c3418cf..765f697 100644 --- a/yarns/yarnhelper.py +++ b/yarns/yarnhelper.py @@ -31,32 +31,6 @@ variables_filename = os.environ.get('VARIABLES', 'vars.yaml') class YarnHelper(object): - def __init__(self): - self._variables = None # None means not loaded, otherwise dict - - def get_variable(self, name): - if self._variables is None: - self._variables = self._load_variables() - if name not in self._variables: - raise Error('no variable {}'.format(name)) - return self._variables[name] - - def _load_variables(self): - if os.path.exists(variables_filename): - with open(variables_filename, 'r') as f: - 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(variables_filename, 'w') as f: - yaml.safe_dump(variables, f) - def construct_aliased_http_request( self, address, method, url, data=None, headers=None): @@ -100,8 +74,3 @@ class YarnHelper(object): m.expunge() m.close() m.logout() - - -class Error(Exception): - - pass diff --git a/yarns/yarnhelper_tests.py b/yarns/yarnhelper_tests.py index 5fe2cbe..40dc89e 100644 --- a/yarns/yarnhelper_tests.py +++ b/yarns/yarnhelper_tests.py @@ -22,31 +22,6 @@ import unittest import yarnhelper -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_raises_error_if_no_such_variable(self): - h = yarnhelper.YarnHelper() - with self.assertRaises(yarnhelper.Error): - h.get_variable('FOO') - print - print 'variables:', h._variables - - 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): |