def test_generator_support(self): """This will naturally go away if i factor out .copy""" t1 = token() t3 = t1.copy(children=(token() for i in range(3))) assert len(t3.children) == 3 assert type(t3.children) is tuple t4 = t1.copy(properties=((i, i) for i in range(3))) assert len(t4.properties) == 3 from collections import Mapping assert isinstance(t4.properties, Mapping)
def test_repr(self): """token classes should have a simple representation""" assert str(token) == "('token',)" assert repr(token) == repr(token()) # a copy of token token2 = token(a=1) assert repr(token2) == "('token', {'a': 1})", repr(token2) class token3(token): """a subclass of `token'""" pass assert repr(token3) == "('token3',)"
def test_no_object_attributes(self): t = token(token, a=1) with assert_raises_exactly(TypeError, 'token objects are read-only'): t.properties = {'b': 2} with assert_raises_exactly(TypeError, 'token objects are read-only'): del t.children
def test_no_object_attributes(self): t = token(token, a=1) with assert_raises_exactly(TypeError, 'token objects are read-only'): t.properties = {'b':2} with assert_raises_exactly(TypeError, 'token objects are read-only'): del t.children
def test_object_attrs_immutable(self): t = token(token, a=1) with assert_raises_exactly( TypeError, "'FrozenDict' object does not support item assignment", ): t.properties['b'] = 2 with assert_raises_exactly( AttributeError, "'tuple' object has no attribute 'append'", ): t.children.append('wat')
def test_copy(self): """secondary interface for copying tokens""" t1 = token() t2 = t1.copy() assert t1 == t2, (t1, t2)