def test_simpleattr_create(client): a = attr.ValueAttr({('instrument', ): 'eit'}) assert va.walker.create(a, client.api)[0].instrument == 'eit'
def test_dummyattr(): one = attr.DummyAttr() other = attr.ValueAttr({'a': 'b'}) assert (one | other) is other assert (one & other) is other
def test_simpleattr_apply(): a = attr.ValueAttr({('test', ): 1}) dct = {} va.walker.apply(a, None, dct) assert dct['test'] == 1
def test_complexattr_create(client): a = attr.ValueAttr({('time', 'start'): 'test'}) assert va.walker.create(a, client.api)[0].time.start == 'test'
def test_complexattr_apply(): tst = {('test', 'foo'): 'a', ('test', 'bar'): 'b'} a = attr.ValueAttr(tst) dct = {'test': {}} va.walker.apply(a, None, dct) assert dct['test'] == {'foo': 'a', 'bar': 'b'}
@_walker.add_creator(_attr.AttrOr) def _create(wlk, root, api): """ Implementation detail. """ blocks = [] for attr in root.attrs: blocks.extend(wlk.create(attr, api)) return blocks # Converters take a type unknown to the walker and convert it into one # known to it. All of those convert types into ValueAttrs, which are # handled above by just assigning according to the keys and values of the # attrs member. _walker.add_converter(Extent)( lambda x: _attr.ValueAttr({('extent', k): v for k, v in vars(x).items()})) _walker.add_converter(_attrs.Time)(lambda x: _attr.ValueAttr({ ('time', 'start'): x.start.strftime(_TIMEFORMAT), ('time', 'end'): x.end.strftime(_TIMEFORMAT), ('time', 'near'): (x.near.strftime(_TIMEFORMAT) if x.near is not None else None), })) _walker.add_converter(_attr.SimpleAttr)( lambda x: _attr.ValueAttr({(x.__class__.__name__.lower(), ): x.value})) _walker.add_converter(_attrs.Wavelength)( lambda x: _attr.ValueAttr({
def test_dummyattr_eq(): one = attr.DummyAttr() two = attr.DummyAttr() other = attr.ValueAttr({'a': 'b'}) assert one == two assert one != other