Exemple #1
0
 def test_add_field_config_type(self, mock_ct_field_cls):
     mock_ct_field = mock_ct_field_cls.return_value = MagicMock()
     mock_ct_field.__setkey__ = MagicMock()
     schema = Schema()
     schema._add_field('x', ConfigType)
     assert schema._fields == {'x': mock_ct_field}
     mock_ct_field.__setkey__.assert_called_once_with(schema, 'x')
Exemple #2
0
 def test_add_field_other(self):
     schema = Schema()
     with pytest.raises(TypeError):
         schema._add_field('hello', 'world')
Exemple #3
0
 def test_add_field_field(self):
     field = Field()
     field.__setkey__ = MagicMock()
     schema = Schema()
     schema._add_field('hello', field)
     field.__setkey__.assert_called_once_with(schema, 'hello')
Exemple #4
0
 def test_add_field_schema(self):
     schema = Schema()
     child = Schema()
     child.__setkey__ = MagicMock()
     schema._add_field('hello', child)
     child.__setkey__.assert_called_once_with(schema, 'hello')
Exemple #5
0
 def test_to_tree_ignore_instance_method(self):
     schema = Schema()
     schema._add_field('x', InstanceMethodField(lambda cfg: 1))
     config = schema()
     config._data['x'] = 1
     assert config.to_tree() == {}