diff options
author | Lars Wirzenius <liw@liw.fi> | 2016-09-25 18:50:26 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2016-09-25 18:50:26 +0300 |
commit | 55429a8a9fb0b0546e20f5f9a6abb719261c3bc1 (patch) | |
tree | 218789b54a2113d6f9ba67c1262c62d825764256 | |
parent | 2a5ceeafa683780e679b07c5e9199c196ee65703 (diff) | |
download | server-yarns-55429a8a9fb0b0546e20f5f9a6abb719261c3bc1.tar.gz |
Implement get_next_match
-rw-r--r-- | yarnhelper.py | 15 | ||||
-rw-r--r-- | yarnhelper_tests.py | 5 |
2 files changed, 18 insertions, 2 deletions
diff --git a/yarnhelper.py b/yarnhelper.py index f313ab4..4501eab 100644 --- a/yarnhelper.py +++ b/yarnhelper.py @@ -16,13 +16,24 @@ # =*= License: GPL-3+ =*= +import os + + class YarnHelper(object): + def __init__(self): + self._env = dict(os.environ) + self._next_match = 1 + def set_environment(self, env): - pass + self._env = dict(env) def get_next_match(self): - raise Error('no next match') + 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] class Error(Exception): diff --git a/yarnhelper_tests.py b/yarnhelper_tests.py index 2e64f93..5c49901 100644 --- a/yarnhelper_tests.py +++ b/yarnhelper_tests.py @@ -28,3 +28,8 @@ class GetNextMatchTests(unittest.TestCase): h.set_environment({}) with self.assertRaises(yarnhelper.Error): h.get_next_match() + + def test_returns_match_if_there(self): + h = yarnhelper.YarnHelper() + h.set_environment({'MATCH_1': 'first'}) + self.assertEqual(h.get_next_match(), 'first') |