Beispiel #1
0
def test_error():
    list = e.intern('list')

    error = e.intern('error')
    msg = e.str('An error message')
    with pytest.raises(e.Signal) as ex:
        error(msg)
    sym, data = ex.value.args
    assert e.eq(sym, e.intern('error'))
    assert e.equal(data, list(msg))

    throw = e.intern('throw')
    tag = e.intern('tag')
    value = e.int(1)
    with pytest.raises(e.Throw) as ex:
        throw(tag, value)
    sym, data = ex.value.args
    assert e.eq(sym, e.intern('tag'))
    assert e.equal_sign(data, value)

    def err():
        error = e.intern('error')
        list = e.intern('list')
        raise e.Signal(error, list(e.str('message')))

    func = e.function(err, 0, 0)
    with pytest.raises(e.Signal) as ex:
        func()
    sym, data = ex.value.args
    assert e.eq(sym, e.intern('error'))
    assert e.equal(data, list(e.str('message')))
Beispiel #2
0
def test_place():
    obj = PlaceOrSymbol()

    assert er.eq(obj.place, er.intern('nil'))
    assert er.eq(er.EmacsObject(obj), er.intern('nil'))

    new_place = er.list([er.int(1), er.int(2), er.int(3)])
    obj._bind(new_place)

    assert er.eq(obj.place, new_place)
    assert er.eq(er.EmacsObject(obj), new_place)
Beispiel #3
0
def test_cons():
    cons = e.intern('cons')
    assert e.functionp(cons)
    a = e.intern('a')
    b = e.intern('b')
    c = e.intern('c')
    nil = e.intern('nil')

    assert repr(cons(kwd='value')) == '(:kwd . "value")'

    cell = cons(a, b)
    lst = cons(a, cons(b, cons(c, nil)))

    assert e.equal(cell, cons(a, b))
    assert not e.eq(cell, cons(a, b))
    assert repr(cell) == '(a . b)'
    assert str(cell) == '(a . b)'
    with pytest.raises(TypeError):
        int(cell)
    with pytest.raises(TypeError):
        float(cell)
    assert cell.type() == 'cons'
    assert cell.is_a('cons')
    assert not e.integerp(cell)
    assert not e.floatp(cell)
    assert not e.stringp(cell)
    assert not e.symbolp(cell)
    assert e.consp(cell)
    assert not e.vectorp(cell)
    assert e.listp(cell)
    assert not e.functionp(cell)
    assert cell

    assert e.equal(lst, cons(a, cons(b, cons(c, nil))))
    assert not e.eq(lst, cons(a, cons(b, cons(c, nil))))
    assert repr(lst) == '(a b c)'
    assert str(lst) == '(a b c)'
    with pytest.raises(TypeError):
        int(lst)
    with pytest.raises(TypeError):
        float(lst)
    assert lst.type() == 'cons'
    assert lst.is_a('cons')
    assert not e.integerp(lst)
    assert not e.floatp(lst)
    assert not e.stringp(lst)
    assert not e.symbolp(lst)
    assert e.consp(lst)
    assert not e.vectorp(lst)
    assert e.listp(lst)
    assert not e.functionp(lst)
    assert lst
Beispiel #4
0
def test_list():
    list = e.intern('list')
    assert e.functionp(list)
    a = e.intern('a')
    b = e.intern('b')
    c = e.intern('c')

    lst = list(a, b, c)

    assert e.equal(lst, list(a, b, c))
    assert not e.eq(lst, list(a, b, c))
    assert repr(lst) == '(a b c)'
    assert str(lst) == '(a b c)'
    with pytest.raises(TypeError):
        int(lst)
    with pytest.raises(TypeError):
        float(lst)
    assert lst.type() == 'cons'
    assert lst.is_a('cons')
    assert not e.integerp(lst)
    assert not e.floatp(lst)
    assert not e.stringp(lst)
    assert not e.symbolp(lst)
    assert e.consp(lst)
    assert not e.vectorp(lst)
    assert e.listp(lst)
    assert not e.functionp(lst)
    assert lst
Beispiel #5
0
def test_vector():
    vector = e.intern('vector')
    assert e.functionp(vector)
    a = e.intern('a')
    b = e.intern('b')
    c = e.intern('c')

    vec = vector(a, b, c)

    assert e.equal(vec, vector(a, b, c))
    assert not e.eq(vec, vector(a, b, c))
    assert repr(vec) == '[a b c]'
    assert str(vec) == '[a b c]'
    with pytest.raises(TypeError):
        int(vec)
    with pytest.raises(TypeError):
        float(vec)
    assert vec.type() == 'vector'
    assert vec.is_a('vector')
    assert not e.integerp(vec)
    assert not e.floatp(vec)
    assert not e.stringp(vec)
    assert not e.symbolp(vec)
    assert not e.consp(vec)
    assert e.vectorp(vec)
    assert not e.listp(vec)
    assert not e.functionp(vec)
    assert vec
Beispiel #6
0
def test_intern():
    alpha = e.intern('alpha')
    assert e.eq(alpha, e.intern('alpha'))
    assert repr(alpha) == 'alpha'
    assert str(alpha) == 'alpha'
    with pytest.raises(TypeError):
        int(alpha)
    with pytest.raises(TypeError):
        float(alpha)
    assert alpha.type() == 'symbol'
    assert alpha.is_a('symbol')
    assert not e.integerp(alpha)
    assert not e.floatp(alpha)
    assert not e.stringp(alpha)
    assert e.symbolp(alpha)
    assert not e.consp(alpha)
    assert not e.vectorp(alpha)
    assert not e.listp(alpha)
    assert not e.functionp(alpha)
    assert alpha

    with pytest.raises(TypeError):
        e.intern(2)
    with pytest.raises(TypeError):
        e.intern([])
Beispiel #7
0
def test_binding():
    get = lambda s: e.intern('symbol-value')(e.intern(s))

    from emacs.emacs import version
    assert e.eq(version[binding], get('emacs-version'))

    import emacs
    with pytest.raises(NameError):
        emacs.doesnt.exist[fbinding]
Beispiel #8
0
 def _cell(self, key, cell=None):
     key = _colonify(key)
     if cell is None:
         cell = self.place
     prev = None
     while cell and not eq(key, _car(cell)):
         prev, cell = cell, _cdr(cell)
     if not cell:
         raise KeyError("Key '{}' not in mplist".format(key))
     return prev, cell
Beispiel #9
0
def test_int():
    one = e.int('1')
    assert e.eq(one, e.int(1))
    assert repr(one) == '1'
    assert str(one) == '1'
    assert int(one) == 1
    assert float(one) == 1.0
    assert one.type() == 'integer'
    assert one.is_a('integer')
    assert e.integerp(one)
    assert not e.floatp(one)
    assert not e.stringp(one)
    assert not e.symbolp(one)
    assert not e.consp(one)
    assert not e.vectorp(one)
    assert not e.listp(one)
    assert not e.functionp(one)
    assert one

    zero = e.int(0)
    assert e.eq(zero, e.int(0))
    assert repr(zero) == '0'
    assert str(zero) == '0'
    assert int(zero) == 0
    assert float(zero) == 0.0
    assert zero.type() == 'integer'
    assert zero.is_a('integer')
    assert e.integerp(zero)
    assert not e.floatp(zero)
    assert not e.stringp(zero)
    assert not e.symbolp(zero)
    assert not e.consp(zero)
    assert not e.vectorp(zero)
    assert not e.listp(zero)
    assert not e.functionp(zero)
    assert zero

    assert str(e.int(0.1)) == '0'
    with pytest.raises(ValueError):
        e.int('alpha')
Beispiel #10
0
def test_initializer():
    l = List(ascii_lowercase)
    assert list(l) == list(ascii_lowercase)

    l = List(ascii_lowercase, prefer_symbol=True)
    assert list(l) == py_list(ascii_lowercase)

    l = List(ascii_lowercase, bind='test')
    assert er.eq(l.place, _('symbol-value')(_('test')))
    assert list(l) == list(ascii_lowercase)

    l = List((a for a in ascii_lowercase))
    assert list(l) == list(ascii_lowercase)
Beispiel #11
0
def test_function():
    def a():
        return e.int(1)

    func = e.function(a, 0, 0)
    assert e.functionp(func)
    ret = func()
    assert e.eq(ret, e.int(1))

    def b():
        return e.str('alpha')

    func = e.function(b)
    assert e.functionp(func)
    ret = func()
    assert e.string_equal(ret, e.str('alpha'))
Beispiel #12
0
    def _cell(self, key, cell=None):
        """Given a key, return the two key cells *prev* and *cell*, where
        *cell* is the first key cell corresponding to the *key*, and prev is
        the preceding key cell. *prev* may be *None*.

        :param key: The key to search for.
        :param cell: If given, search starts at this key cell.
        """
        if self.colonify:
            key = _colonify(key)
        if cell is None:
            cell = self.place
        prev = None
        while cell:
            if eq(_car(cell), key):
                return prev, cell
            prev, cell = cell, _cddr(cell)
        raise KeyError("Key '{}' not in plist".format(key))
Beispiel #13
0
def test_nil():
    nil = e.intern('nil')
    assert e.eq(nil, e.intern('nil'))
    assert repr(nil) == 'nil'
    assert str(nil) == 'nil'
    with pytest.raises(TypeError):
        int(nil)
    with pytest.raises(TypeError):
        float(nil)
    assert nil.type() == 'symbol'
    assert nil.is_a('symbol')
    assert not e.integerp(nil)
    assert not e.floatp(nil)
    assert not e.stringp(nil)
    assert e.symbolp(nil)
    assert not e.consp(nil)
    assert not e.vectorp(nil)
    assert e.listp(nil)
    assert not e.functionp(nil)
    assert not nil
Beispiel #14
0
def test_symbol():
    mylist = er.list([er.int(1), er.int(2), er.int(3)])

    sym = er.intern('alpha')
    setq = er.intern('set')
    setq(sym, mylist)

    obj = PlaceOrSymbol(sym)
    assert er.eq(obj.place, mylist)
    assert er.eq(er.EmacsObject(obj), mylist)

    mylist = er.list([er.int(1), er.int(2), er.int(3), er.int(4)])
    obj._bind(mylist)

    assert er.eq(obj._symbol, er.intern('alpha'))
    assert er.eq(obj.place, mylist)
    assert er.eq(er.EmacsObject(obj), mylist)
    assert er.eq(er.intern('symbol-value')(er.intern('alpha')), mylist)