Skip to content

fix: load_from_config uses json.loads after read - #109

Open
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:codequality/bobber-load-from-config-uses-json-loads-after
Open

fix: load_from_config uses json.loads after read#109
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:codequality/bobber-load-from-config-uses-json-loads-after

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

This PR addresses the following issue in bobber/bobber.py: load_from_config uses json.loads after read.

Changes

  • bobber/bobber.py: load_from_config uses json.loads after read.

Details

--- a/bobber/bobber.py
+++ b/bobber/bobber.py
@@ -1,1 +1,1 @@
-        settings = json.loads(config.read())
+        settings = json.load(config)

Tests

  • tests/test_bobber_load_config.py
--- /dev/null
+++ b/tests/test_bobber_load_config.py
@@ -0,0 +1,13 @@
+import unittest
+from unittest.mock import mock_open, patch
+import bobber.bobber as bobber_module
+
+
+class TestLoadFromConfig(unittest.TestCase):
+    def test_load_from_config_parses_json(self):
+        mock_file = mock_open(read_data='{"foo": "bar", "baz": 1}')
+        with patch('builtins.open', mock_file):
+            ns = bobber_module.load_from_config('dummy.json')
+        self.assertEqual(ns.foo, 'bar')
+        self.assertEqual(ns.baz, 1)

Contributor guidelines

Per this repo's CONTRIBUTING.md:

  • All commits are signed off (Signed-off-by trailer, DCO).

Signed-off-by: Andrew White <andrewh@cdw.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant