MCPcopy
hub / github.com/python-attrs/attrs / test_metadata_immutability

Method test_metadata_immutability

tests/test_make.py:1915–1937  ·  tests/test_make.py::TestMetadata.test_metadata_immutability

The metadata dict should be best-effort immutable.

(self, C, string)

Source from the content-addressed store, hash-verified

1913
1914 @given(simple_classes(), text())
1915 def test_metadata_immutability(self, C, string):
1916 class="st">"""
1917 The metadata dict should be best-effort immutable.
1918 class="st">"""
1919 for a in fields(C):
1920 with pytest.raises(TypeError):
1921 a.metadata[string] = string
1922 with pytest.raises(AttributeError):
1923 a.metadata.update({string: string})
1924 with pytest.raises(AttributeError):
1925 a.metadata.clear()
1926 with pytest.raises(AttributeError):
1927 a.metadata.setdefault(string, string)
1928
1929 for k in a.metadata:
1930 class="cm"># For some reason, MappingProxyType throws an IndexError for
1931 class="cm"># deletes on a large integer key.
1932 with pytest.raises((TypeError, IndexError)):
1933 del a.metadata[k]
1934 with pytest.raises(AttributeError):
1935 a.metadata.pop(k)
1936 with pytest.raises(AttributeError):
1937 a.metadata.popitem()
1938
1939 @given(lists(simple_attrs_without_metadata, min_size=2, max_size=5))
1940 def test_empty_metadata_singleton(self, list_of_attrs):

Callers

nothing calls this directly

Calls 1

fieldsFunction · 0.90

Tested by

no test coverage detected