コード例 #1
0
 def test_get_item_position_not_exists(self):
     schema = Schema()
     schema.lst = ListField(IntField())
     config = schema()
     proxy = ListProxy(config, schema.lst)
     proxy.extend([1, 2, 3])
     assert proxy._get_item_position(10) == '3'
コード例 #2
0
ファイル: test_list.py プロジェクト: Burrch3s/cincoconfig
 def test_to_basic_schema(self):
     schema = Schema()
     schema.x = IntField(default=1)
     schema.y = IntField(default=2)
     field = ListProxy(MockConfig(), schema)
     field.append(schema())
     assert field.to_basic() == [{'x': 1, 'y': 2}]
コード例 #3
0
 def test_validate_not_field(self):
     schema = Schema()
     schema.lst = ListField(int)
     config = schema()
     proxy = ListProxy(config, schema.lst)
     with pytest.raises(TypeError):
         proxy._validate(10)
コード例 #4
0
    def test_extend_list(self):
        wrap = ListProxy(MockConfig(), ListField(IntField()), [1, 2, '3'])
        with patch.object(wrap, '_validate') as mock_validate:
            mock_validate.side_effect = [4, 5]
            wrap.extend([4, '5'])
            mock_validate.mock_calls = [call(4), call('5')]

        assert wrap == [1, 2, 3, 4, 5]
コード例 #5
0
 def test_validate_list_proxy(self):
     field = ListField(IntField())
     orig = ListProxy(MockConfig(), field, [1, 2, 3])
     check = field._validate(MockConfig(),
                             ListProxy(MockConfig(), field, orig))
     assert isinstance(check, ListProxy)
     assert check == orig
     assert check is not orig
コード例 #6
0
    def test_extend_proxy(self):
        cfg = MockConfig()
        field = IntField()
        wrap = ListProxy(cfg, ListField(field), [1, 2, '3'])
        with patch.object(wrap, '_validate') as mock_validate:
            wrap.extend(ListProxy(cfg, ListField(field), [4, 5]))
            mock_validate.assert_not_called()

        assert wrap == [1, 2, 3, 4, 5]
コード例 #7
0
    def test_validate_schema_invalid(self):
        schema = Schema()
        schema.x = IntField(default=1)
        schema.y = IntField(default=2)
        cfg = MockConfig()
        proxy = ListProxy(cfg, schema)

        with pytest.raises(ValueError):
            proxy._validate(100)
コード例 #8
0
 def test_validate_item_valid(self):
     schema = Schema()
     field = IntField()
     list_field = schema.x = ListField(field)
     config = schema()
     proxy = ListProxy(config, list_field)
     with patch.object(field, 'validate') as mock_validate:
         retval = mock_validate.return_value = object()
         assert proxy._validate(2) is retval
         mock_validate.assert_called_once_with(config, 2)
コード例 #9
0
 def test_validate_item_validation_error(self):
     schema = Schema()
     field = IntField()
     list_field = schema.x = ListField(field)
     config = schema()
     proxy = ListProxy(config, list_field)
     orig_exc = ValidationError(config, list_field, ValueError('asdf'))
     with patch.object(field, 'validate') as mock_validate:
         mock_validate.side_effect = orig_exc
         with pytest.raises(ValueError):
             proxy._validate(2)
コード例 #10
0
    def test_validate_schema_config(self):
        schema = Schema()
        schema.x = IntField(default=1)
        schema.y = IntField(default=2)
        cfg = MockConfig()
        proxy = ListProxy(cfg, ListField(schema))

        val = schema()
        val.x = 10
        check = proxy._validate(val)
        assert isinstance(check, Config)
        assert check is val
        assert check._parent is cfg
        assert check._schema is schema
コード例 #11
0
    def test_listfield_no_field(self):
        schema = Schema()
        list_field = schema.lst = ListField()
        config = schema()

        with pytest.raises(TypeError):
            ListProxy(config, list_field)
コード例 #12
0
 def test_eq_not_list(self):
     wrap = ListProxy(MockConfig(), ListField(IntField()), [1, 2, '3'])
     assert wrap != 'hello'
コード例 #13
0
 def test_append(self):
     wrap = ListProxy(MockConfig(), ListField(IntField()), [1, 2, '3'])
     wrap.append('4')
     assert wrap == [1, 2, 3, 4]
コード例 #14
0
ファイル: test_list.py プロジェクト: Burrch3s/cincoconfig
 def test_index(self):
     wrap = ListProxy(MockConfig(), IntField(), [1, 2, '3'])
     assert wrap.index(3) == 2
コード例 #15
0
 def test_default_list_wrap(self):
     cfg = MockConfig()
     field = ListField(IntField(), default=lambda: [1, 2, 3], key='asdf')
     field.__setdefault__(cfg)
     cfg._set_default_value.assert_called_once_with(
         'asdf', ListProxy(cfg, field, [1, 2, 3]))
コード例 #16
0
 def test_to_basic(self):
     field = ListField(IntField(), required=True)
     wrap = ListProxy(MockConfig(), ListField(IntField()), [1, 2, '3'])
     assert field.to_basic(MockConfig(), wrap) == [1, 2, 3]
コード例 #17
0
 def test_eq_proxy(self):
     wrap = ListProxy(MockConfig(), ListField(IntField()), [1, 2, '3'])
     wrap2 = ListProxy(MockConfig(), ListField(IntField()), [1, 2, '3'])
     assert wrap == wrap2
コード例 #18
0
 def test_eq_list(self):
     wrap = ListProxy(MockConfig(), ListField(IntField()), [1, 2, '3'])
     assert wrap == [1, 2, 3]
コード例 #19
0
ファイル: test_list.py プロジェクト: Burrch3s/cincoconfig
 def test_count(self):
     wrap = ListProxy(MockConfig(), IntField(), [1, 2, '3'])
     assert wrap.count(2) == 1
コード例 #20
0
 def test_iadd(self):
     wrap = ListProxy(MockConfig(), ListField(IntField()), [1, 2, '3'])
     wrap += [4, 5]
     assert wrap == [1, 2, 3, 4, 5]
コード例 #21
0
 def test_add_list(self):
     wrap = ListProxy(MockConfig(), ListField(IntField()), [1, 2, '3'])
     wrap2 = wrap + [4, 5]
     assert wrap2 == [1, 2, 3, 4, 5]
コード例 #22
0
ファイル: test_list.py プロジェクト: Burrch3s/cincoconfig
 def test_pop_none(self):
     wrap = ListProxy(MockConfig(), IntField(), [1, 2, '3'])
     val = wrap.pop()
     assert val == 3
     assert wrap._items == [1, 2]
コード例 #23
0
 def test_add_wrapper(self):
     wrap = ListProxy(MockConfig(), ListField(IntField()), [1, 2, '3'])
     wrap2 = ListProxy(MockConfig(), ListField(IntField()), [4, '5'])
     wrap3 = wrap + wrap2
     assert wrap3 == [1, 2, 3, 4, 5]
コード例 #24
0
ファイル: test_list.py プロジェクト: Burrch3s/cincoconfig
 def test_clear(self):
     wrap = ListProxy(MockConfig(), IntField(), [1, 2, '3'])
     wrap.clear()
     assert wrap._items == []
コード例 #25
0
 def test_setitem(self):
     wrap = ListProxy(MockConfig(), ListField(IntField()), [1, 2, '3'])
     wrap[1] = '5'
     assert wrap == [1, 5, 3]
コード例 #26
0
ファイル: test_list.py プロジェクト: Burrch3s/cincoconfig
 def test_copy(self):
     wrap = ListProxy(MockConfig(), IntField(), [1, 2, '3'])
     wrap2 = wrap.copy()
     assert wrap._items == wrap2._items
     assert wrap.field is wrap2.field
     assert wrap.cfg is wrap2.cfg