예제 #1
0
 def test_unknown(self, C):
     """
     Wanting to change an unknown attribute raises a ValueError.
     """
     # No generated class will have a four letter attribute.
     with pytest.raises(AttrsAttributeNotFoundError) as e:
         assoc(C(), aaaa=2)
     assert (
         "aaaa is not an attrs attribute on {cls!r}.".format(cls=C),
     ) == e.value.args
예제 #2
0
    def test_unknown(self, C):
        """
        Wanting to change an unknown attribute raises a ValueError.
        """

        @attributes
        class C(object):
            x = attr()
            y = 42

        with pytest.raises(ValueError) as e:
            assoc(C(1), y=2)
        assert ("y is not an attrs attribute on {cl!r}.".format(cl=C),) == e.value.args
예제 #3
0
    def test_unknown(self):
        """
        Wanting to change an unknown attribute raises a ValueError.
        """
        @attributes
        class C(object):
            x = attr()
            y = 42

        with pytest.raises(ValueError) as e:
            assoc(C(1), y=2)
        assert ("y is not an attrs attribute on {cl!r}.".format(
            cl=C), ) == e.value.args
예제 #4
0
파일: test_funcs.py 프로젝트: Tinche/attrs
    def test_no_changes(self, C):
        """
        No changes means a verbatim copy.
        """
        i1 = C(1, 2)
        i2 = assoc(i1)

        assert i1 is not i2
        assert i1 == i2
예제 #5
0
    def test_no_changes(self, C):
        """
        No changes means a verbatim copy.
        """
        i1 = C()
        i2 = assoc(i1)

        assert i1 is not i2
        assert i1 == i2
예제 #6
0
    def test_frozen(self):
        """
        Works on frozen classes.
        """
        @attributes(frozen=True)
        class C(object):
            x = attr()
            y = attr()

        assert C(3, 2) == assoc(C(1, 2), x=3)
예제 #7
0
 def test_change(self, C, val):
     """
     Changes work.
     """
     # Take the first attribute, and change it.
     assume(fields(C))  # Skip classes with no attributes.
     original = C()
     attribute = fields(C)[0]
     changed = assoc(original, **{attribute.name: val})
     assert getattr(changed, attribute.name) == val
예제 #8
0
파일: test_funcs.py 프로젝트: Tinche/attrs
    def test_empty(self):
        """
        Empty classes without changes get copied.
        """
        @attributes
        class C(object):
            pass

        i1 = C()
        i2 = assoc(i1)

        assert i1 is not i2
        assert i1 == i2
예제 #9
0
    def test_empty(self, slots, frozen):
        """
        Empty classes without changes get copied.
        """
        @attributes(slots=slots, frozen=frozen)
        class C(object):
            pass

        i1 = C()
        i2 = assoc(i1)

        assert i1 is not i2
        assert i1 == i2
예제 #10
0
    def test_empty(self):
        """
        Empty classes without changes get copied.
        """
        @attributes
        class C(object):
            pass

        i1 = C()
        i2 = assoc(i1)

        assert i1 is not i2
        assert i1 == i2
예제 #11
0
 def test_change(self, C, data):
     """
     Changes work.
     """
     # Take the first attribute, and change it.
     assume(fields(C))  # Skip classes with no attributes.
     field_names = [a.name for a in fields(C)]
     original = C()
     chosen_names = data.draw(st.sets(st.sampled_from(field_names)))
     change_dict = {name: data.draw(st.integers())
                    for name in chosen_names}
     changed = assoc(original, **change_dict)
     for k, v in change_dict.items():
         assert getattr(changed, k) == v
예제 #12
0
파일: test_funcs.py 프로젝트: Tinche/attrs
 def test_change(self, C):
     """
     Changes work.
     """
     i = assoc(C(1, 2), x=42)
     assert C(42, 2) == i
예제 #13
0
 def test_change(self, C):
     """
     Changes work.
     """
     i = assoc(C(1, 2), x=42)
     assert C(42, 2) == i