コード例 #1
0
ファイル: test_validators.py プロジェクト: yutiansut/atom
    (Dict(int, int), [{
        1: 2
    }], [{
        1: 2
    }], [{
        '': 2
    }, {
        2: ''
    }]),
    (Instance((int, float)), [1, 2.0, None], [1, 2.0, None], ['']),
    (ForwardInstance(lambda: (int, float)), [1, 2.0], [1, 2.0], ['']),
    (Typed(float), [1.0, None], [1.0, None], [1]),
    (ForwardTyped(lambda: float), [1.0], [1.0], [1]),
    (Subclass(CAtom), [Atom], [Atom], [int, 1]),
    (Subclass((CAtom, float)), [Atom], [Atom], [int, 1]),
    (ForwardSubclass(lambda: CAtom), [Atom], [Atom], [int]),
] + ([(Range(sys.maxsize, sys.maxsize + 2), [sys.maxsize, sys.maxsize + 2],
       [sys.maxsize, sys.maxsize + 2],
       [sys.maxsize - 1, sys.maxsize + 3])] if sys.version_info >
     (3, ) else []))
def test_validation_modes(member, set_values, values, raising_values):
    """Test the validation modes.

    """
    class MemberTest(Atom):

        m = member

    tester = MemberTest()
    for sv, v in zip(set_values, values):
        tester.m = sv
コード例 #2
0
ファイル: test_member.py プロジェクト: frmdstryr/atom
    cl2 = typed.clone()
    assert cl2.index == typed.index
    validators = [typed.item] if hasattr(typed,
                                         "item") else typed.validate_mode[1]
    c_validators = [cl2.item] if hasattr(typed,
                                         "item") else cl2.validate_mode[1]
    for v, cv in zip(validators, c_validators):
        assert cv is not v
        assert isinstance(cv, type(v))


# XXX should the kwargs be copied rather than simply re-assigned
@pytest.mark.parametrize(
    "member, cloned_attributes",
    [
        (ForwardSubclass(lambda: object), ["resolve"]),
        (ForwardTyped(lambda: object,
                      (1, ), {"a": 1}), ["resolve", "args", "kwargs"]),
        (
            ForwardInstance(lambda: object, (1, ), {"a": 1}),
            ["resolve", "args", "kwargs"],
        ),
    ],
)
def test_cloning_forward(member, cloned_attributes):
    """Test that subclasses of Member are properly cloned."""
    member.set_index(5)
    clone = member.clone()
    assert clone.index == member.index
    for attr in cloned_attributes:
        assert getattr(clone, attr) is getattr(member, attr)
コード例 #3
0
ファイル: test_member.py プロジェクト: yutiansut/atom
    typed.set_index(5)
    cl2 = typed.clone()
    assert cl2.index == typed.index
    validators = ([typed.item]
                  if hasattr(typed, 'item') else typed.validate_mode[1])
    c_validators = ([cl2.item]
                    if hasattr(typed, 'item') else cl2.validate_mode[1])
    for v, cv in zip(validators, c_validators):
        assert cv is not v
        assert isinstance(cv, type(v))


# XXX should the kwargs be copied rather than simply re-assigned
@pytest.mark.parametrize(
    "member, cloned_attributes",
    [(ForwardSubclass(lambda: object), ['resolve']),
     (ForwardTyped(lambda: object,
                   (1, ), {'a': 1}), ['resolve', 'args', 'kwargs']),
     (ForwardInstance(lambda: object,
                      (1, ), {'a': 1}), ['resolve', 'args', 'kwargs'])])
def test_cloning_forward(member, cloned_attributes):
    """Test that subclasses of Member are properly cloned.

    """
    member.set_index(5)
    clone = member.clone()
    assert clone.index == member.index
    for attr in cloned_attributes:
        assert getattr(clone, attr) is getattr(member, attr)
コード例 #4
0
ファイル: test_default_values.py プロジェクト: frmdstryr/atom
    assert A.v.default_value_mode[0] == DefaultValue.NoOp
    assert A().v is None


@pytest.mark.parametrize(
    "member, expected",
    [
        (Value(1), 1),
        (Range(0), 0),
        (Range(high=0), 0),
        (Range(0, value=1), 1),
        (FloatRange(0.0), 0.0),
        (FloatRange(high=0.0), 0.0),
        (FloatRange(0.0, value=1.0), 1.0),
        (Subclass(float), float),
        (ForwardSubclass(lambda: float), float),
    ],
)
def test_static_handler(member, expected):
    """Test a static handler."""
    class StaticTest(Atom):
        v = member

    mode = (DefaultValue.MemberMethod_Object if isinstance(
        member, ForwardSubclass) else DefaultValue.Static)
    assert StaticTest.v.default_value_mode[0] == mode
    assert StaticTest().v == expected
    assert StaticTest.v.default_value_mode[0] == DefaultValue.Static


@pytest.mark.parametrize(