From 1322ff6e5acfc9128c41d0aabdcdaeb4285b3d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Eide?= Date: Thu, 4 Jun 2020 14:37:10 +0200 Subject: [PATCH] Use deduced_required value for config.push --- configsuite/config.py | 2 ++ tests/test_deprecation_warning.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/configsuite/config.py b/configsuite/config.py index eb5a1a4e..834c68ac 100644 --- a/configsuite/config.py +++ b/configsuite/config.py @@ -89,6 +89,7 @@ def __init__( self._valid = True self._errors = () self._snapshot = None + self._deduce_required = deduce_required self._cached_merged_config = self._build_merged_config() if self._readable: @@ -158,6 +159,7 @@ def push(self, raw_config): layers=self._layers, extract_validation_context=self._extract_validation_context, extract_transformation_context=self._extract_transformation_context, + deduce_required=self._deduce_required, ) @property diff --git a/tests/test_deprecation_warning.py b/tests/test_deprecation_warning.py index 1ccbf9e1..3d3a8d8c 100644 --- a/tests/test_deprecation_warning.py +++ b/tests/test_deprecation_warning.py @@ -79,3 +79,21 @@ def test_no_error_when_deducing_from_default(self): suite = configsuite.ConfigSuite({}, schema, deduce_required=True) self.assertTrue(suite.valid) self.assertEqual(0, len(wc)) + + def test_no_error_when_deducing_with_push(self): + schema = { + MK.Type: types.NamedDict, + MK.Content: { + "not_required": {MK.Type: types.Integer, MK.AllowNone: True}, + "a_required_string": {MK.Type: types.String}, + }, + } + config = {"a_required_string": "a_string"} + + with warnings.catch_warnings(record=True) as wc: + basic_config = configsuite.ConfigSuite(config, schema, deduce_required=True) + self.assertTrue(basic_config.valid) + + basic_config = basic_config.push({"not_required": 10}) + self.assertTrue(basic_config.valid) + self.assertEqual(0, len(wc))