def test_objects_values_path(patch, magic): patch.object(Objects, 'path') item = magic(type='NAME') tree = magic(child=lambda x: item) result = Objects().values(tree) Objects.path.assert_called_with(tree) assert result == Objects.path()
def test_objects_names_path(patch, magic, tree): """ Ensures that paths like x[y] are compiled correctly """ patch.object(Objects, 'path') subtree = Tree('path', ['token']) tree.children = [magic(), Tree('fragment', [subtree])] result = Objects().names(tree) Objects.path.assert_called_with(subtree) assert result[1] == Objects.path()
def test_objects_objects_key_path(patch, tree): """ Ensures that objects like {x: 0} are compiled """ patch.many(Objects, ['base_expression', 'path']) subtree = Tree('key_value', [ Tree('path', ['string.name']), Tree('path', ['value.path']), ]) tree.children = [subtree] result = Objects().map(tree) assert result['items'] == [[Objects.path(), Objects.base_expression()]]
def test_objects_objects_key_path(patch, tree): """ Ensures that objects like {x: 0} are compiled """ patch.many(Objects, ["base_expression", "path"]) subtree = Tree( "key_value", [ Tree("path", ["string.name"]), Tree("path", ["value.path"]), ], ) tree.children = [subtree] result = Objects().map(tree) assert result["items"] == [[Objects.path(), Objects.base_expression()]]