def test_invalid_flat_leaf(self): expected_message = ff._NOT_A_DICT_OR_ITEM.format("int") with self.assertRaisesWithLiteralMatch(TypeError, expected_message): ff._extract_defaults({ "string_field": ff.String("default", "String field"), "naughty_field": 100, })
def test_invalid_container(self): expected_message = ff._NOT_A_DICT_OR_ITEM.format("list") with self.assertRaisesWithLiteralMatch(TypeError, expected_message): ff._extract_defaults({ "integer_field": ff.Integer(10, "Integer field"), "string_field": ff.String("default", "String field"), "nested": [ff.Float(3.1, "Float field")], })
def test_valid_flat(self): result = ff._extract_defaults({ "integer_field": ff.Integer(10, "Integer field"), "string_field": ff.String("default", "String field"), }) expected = {"integer_field": 10, "string_field": "default"} self.assertEqual(result, expected)
def test_valid_nested(self): result = ff._extract_defaults( { "integer_field": ff.Integer(10, "Integer field"), "string_field": ff.String("default", "String field"), "nested": { "float_field": ff.Float(3.1, "Float field"), }, } ) expected = { "integer_field": 10, "string_field": "default", "nested": {"float_field": 3.1}, } self.assertEqual(result, expected)