From 1d51ab954726cb478325cba0046fedd7d931b8b3 Mon Sep 17 00:00:00 2001 From: Andy Lu Date: Tue, 13 Nov 2018 19:52:06 +0000 Subject: [PATCH 1/2] Add key property to function call, clean up whitespace --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7c064f7..7073a57 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,10 @@ library: import singer singer.write_schema('my_table', - {'properties':{'id': {'type': 'string', 'key': True}}}) + {'properties':{'id': {'type': 'string', 'key': True}}}, + ['id']) singer.write_records('my_table', - [{'id': 'b'}, {'id':'d'}]) + [{'id': 'b'}, {'id':'d'}]) singer.write_state({'my_table': 'd'}) ``` From f3715e2f8c1caa3c5e0d62762d2a24c33b6f1f2d Mon Sep 17 00:00:00 2001 From: Andy Lu Date: Fri, 16 Nov 2018 19:33:46 +0000 Subject: [PATCH 2/2] Add update_config_file() and unittest --- singer/utils.py | 3 +++ tests/test_utils.py | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) 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..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): @@ -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')