From cb27bdb4319c0f8bb8bdada01c77e3823b0ebd86 Mon Sep 17 00:00:00 2001 From: Andy Lu Date: Fri, 16 Nov 2018 19:42:57 +0000 Subject: [PATCH 1/2] Add update_config_file() and unittests --- singer/utils.py | 3 +++ tests/test_utils.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/singer/utils.py b/singer/utils.py index 4cd179d..3efdccf 100644 --- a/singer/utils.py +++ b/singer/utils.py @@ -185,6 +185,9 @@ def check_config(config, required_keys): if missing_keys: raise Exception("Config is missing required keys: {}".format(missing_keys)) +def update_config_file(config_path, new_config): + with open(config_path, 'w') as output: + output.write(json.dumps(new_config, indent=2)) def backoff(exceptions, giveup): """Decorates a function to retry up to 5 times using an exponential backoff diff --git a/tests/test_utils.py b/tests/test_utils.py index bb26da6..4d9e1ca 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -33,3 +33,22 @@ def test_exception_fn(self): def foo(): raise RuntimeError("foo") self.assertRaises(RuntimeError, foo) + +class TestUpdateConfig(unittest.TestCase): + def test_file_changed(self): + original_config = {'key_a': 'val_a'} + + with open('config.json', 'w') as file: + file.write(json.dumps(original_config)) + + changed_config = {'key_b': 'val_b'} + + u.update_config_file('config.json', changed_config) + + read_config = u.load_json('config.json') + + self.assertEqual(changed_config.get('key_b'), read_config.get('key_b')) + + def tearDown(self): + import os + os.remove('config.json') From f479a532e6ef85ba0d4abacab31d1169744f9206 Mon Sep 17 00:00:00 2001 From: Andy Lu Date: Fri, 16 Nov 2018 19:48:26 +0000 Subject: [PATCH 2/2] Add missing dependency --- tests/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 4d9e1ca..0783510 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -3,7 +3,7 @@ import pytz import logging import singer.utils as u - +import json class TestFormat(unittest.TestCase): def test_small_years(self):