def t(self, name, sname): if sname is None: sname = name if py3k: [uname, bname] = [sname, sname.encode('UTF-8')] else: [uname, bname] = [sname.decode('UTF-8'), sname] sym = Symbol(name) x = Expression(sym) assert_is(x, Expression(x)) # __repr__(x) assert_repr(x, 'Expression({sym!r})'.format(sym=sym)) # value: v = x.value assert_equal(type(v), Symbol) assert_equal(v, sym) # lvalue: v = x.lvalue assert_equal(type(v), Symbol) assert_equal(v, sym) # __str__(): assert_equal(str(x), sname) assert_repr(x, repr(Expression.from_string(sname))) # __unicode__(): assert_equal(unicode(x), uname) assert_repr(x, repr(Expression.from_string(uname))) # __eq__(), __ne__(): assert_equal(x, Expression(sym)) assert_not_equal(x, Expression(name)) assert_not_equal(x, sym) # __hash__(): assert_equal(hash(x), hash(bname.strip(b'|'))) # pickle: assert_pickle_equal(x) return x
def test2(self): x = Expression([[1, 2], 3, [4, 5, Symbol('baz')], ['quux']]) assert_repr( x, "Expression([[1, 2], 3, [4, 5, Symbol('baz')], ['quux']])") y = Expression(x) assert_repr(y, repr(x)) assert_false(x is y) assert_equal(x.value, ((1, 2), 3, (4, 5, Symbol('baz')), ('quux', ))) assert_equal(x.lvalue, [[1, 2], 3, [4, 5, Symbol('baz')], ['quux']]) assert_equal(str(x), '((1 2) 3 (4 5 baz) ("quux"))') assert_repr(x, repr(Expression.from_string(str(x)))) assert_equal(len(x), 4) assert_equal(bool(x), True) assert_equal(tuple(x), (Expression( (1, 2)), Expression(3), Expression( (4, 5, Symbol('baz'))), Expression(('quux', )))) with assert_raises_str(TypeError, 'key must be an integer or a slice'): x[object()] assert_equal(x[1], Expression(3)) assert_equal(x[-1][0], Expression('quux')) with assert_raises_str(IndexError, 'list index of out range'): x[6] with assert_raises_str(IndexError, 'list index of out range'): x[-6] assert_equal(x[:].value, x.value) assert_equal(x[:].lvalue, x.lvalue) assert_repr(x[1:], "Expression([3, [4, 5, Symbol('baz')], ['quux']])") assert_repr(x[-2:], "Expression([[4, 5, Symbol('baz')], ['quux']])") x[-2:] = 4, 5, 6 assert_repr(x, 'Expression([[1, 2], 3, 4, 5, 6])') x[0] = 2 assert_repr(x, 'Expression([2, 3, 4, 5, 6])') x[:] = (1, 3, 5) assert_repr(x, 'Expression([1, 3, 5])') x[3:] = 7, assert_repr(x, 'Expression([1, 3, 5, 7])') with assert_raises_str(NotImplementedError, 'only [n:] slices are supported'): x[object():] with assert_raises_str(NotImplementedError, 'only [n:] slices are supported'): x[:2] with assert_raises_str(NotImplementedError, 'only [n:] slices are supported'): x[object():] = [] with assert_raises_str(NotImplementedError, 'only [n:] slices are supported'): x[:2] = [] with assert_raises_str(TypeError, 'can only assign a list expression'): x[:] = 0 assert_equal(x, Expression((1, 3, 5, 7))) assert_not_equal(x, Expression((2, 4, 6))) assert_not_equal(x, (1, 3, 5, 7)) with assert_raises_str(TypeError, "unhashable type: 'ListExpression'"): hash(x)
def test_no_verbatim(self): self.require_feature('Exiv2') self.pdf2djvu().assert_() xmp = self.extract_xmp() xmp = etree.fromstring(xmp) dcformat = xml_find_text(xmp, 'dc:format') assert_equal(dcformat, 'image/vnd.djvu') instance_id = xml_find_text(xmp, 'xmpMM:InstanceID') document_id = xml_find_text(xmp, 'xmpMM:DocumentID') assert_not_equal(instance_id, document_id) assert_uuid_urn(instance_id) assert_uuid_urn(document_id)
def test_string_expressions(): x = Expression('eggs') assert_repr(x, "Expression('eggs')") assert_is(x, Expression(x)) assert_equal(x.value, 'eggs') assert_equal(x.lvalue, 'eggs') assert_equal(str(x), '"eggs"') assert_repr(x, repr(Expression.from_string(str(x)))) assert_equal(x, Expression('eggs')) assert_not_equal(x, Expression(Symbol('eggs'))) assert_not_equal(x, 'eggs') assert_equal(hash(x), hash('eggs')) assert_pickle_equal(x)
def test_comparison1(self): assert_not_equal(TEXT_ZONE_PAGE, '') assert_not_equal(TEXT_ZONE_PAGE, 42) with assert_raises_str( TypeError, 'cannot compare text zone type with other object'): TEXT_ZONE_PAGE < 42 with assert_raises_str( TypeError, 'cannot compare text zone type with other object'): TEXT_ZONE_PAGE <= 42 with assert_raises_str( TypeError, 'cannot compare text zone type with other object'): TEXT_ZONE_PAGE > 42 with assert_raises_str( TypeError, 'cannot compare text zone type with other object'): TEXT_ZONE_PAGE >= 42
def t(self, n, x=None): if x is None: x = Expression(n) assert_is(x, Expression(x)) # __repr__(): assert_repr(x, 'Expression({n})'.format(n=int(n))) # value: v = x.value assert_equal(type(v), int) assert_equal(v, n) # lvalue: v = x.lvalue assert_equal(type(v), int) assert_equal(v, n) # __int__(): i = int(x) assert_equal(type(i), int) assert_equal(i, n) # __long__(): i = long(x) assert_equal(type(i), long) assert_equal(i, n) # __float__(): i = float(x) assert_equal(type(i), float) assert_equal(i, n) # __str__(): s = str(x) assert_equal(s, str(n)) # __unicode__(): s = unicode(x) assert_equal(s, str(n)) # __eq__(), __ne__(): assert_equal(x, Expression(n)) assert_not_equal(x, n) assert_not_equal(x, Expression(n + 37)) # __hash__(): assert_equal(hash(x), n) # __bool__() / __nonzero__(): obj = object() if n: assert_is(x and obj, obj) assert_is(x or obj, x) else: assert_is(x and obj, x) assert_is(x or obj, obj) # pickle: assert_pickle_equal(x)
def test2(self): x = Expression([[1, 2], 3, [4, 5, Symbol('baz')], ['quux']]) assert_repr(x, "Expression([[1, 2], 3, [4, 5, Symbol('baz')], ['quux']])") y = Expression(x) assert_repr(y, repr(x)) assert_false(x is y) assert_equal(x.value, ((1, 2), 3, (4, 5, Symbol('baz')), ('quux',))) assert_equal(x.lvalue, [[1, 2], 3, [4, 5, Symbol('baz')], ['quux']]) assert_equal(str(x), '((1 2) 3 (4 5 baz) ("quux"))') assert_repr(x, repr(Expression.from_string(str(x)))) assert_equal(len(x), 4) assert_equal(bool(x), True) assert_equal(tuple(x), (Expression((1, 2)), Expression(3), Expression((4, 5, Symbol('baz'))), Expression(('quux',)))) with assert_raises_str(TypeError, 'key must be an integer or a slice'): x[object()] assert_equal(x[1], Expression(3)) assert_equal(x[-1][0], Expression('quux')) with assert_raises_str(IndexError, 'list index of out range'): x[6] with assert_raises_str(IndexError, 'list index of out range'): x[-6] assert_equal(x[:].value, x.value) assert_equal(x[:].lvalue, x.lvalue) assert_repr(x[1:], "Expression([3, [4, 5, Symbol('baz')], ['quux']])") assert_repr(x[-2:], "Expression([[4, 5, Symbol('baz')], ['quux']])") x[-2:] = 4, 5, 6 assert_repr(x, 'Expression([[1, 2], 3, 4, 5, 6])') x[0] = 2 assert_repr(x, 'Expression([2, 3, 4, 5, 6])') x[:] = (1, 3, 5) assert_repr(x, 'Expression([1, 3, 5])') x[3:] = 7, assert_repr(x, 'Expression([1, 3, 5, 7])') with assert_raises_str(NotImplementedError, 'only [n:] slices are supported'): x[object():] with assert_raises_str(NotImplementedError, 'only [n:] slices are supported'): x[:2] with assert_raises_str(NotImplementedError, 'only [n:] slices are supported'): x[object():] = [] with assert_raises_str(NotImplementedError, 'only [n:] slices are supported'): x[:2] = [] with assert_raises_str(TypeError, 'can only assign a list expression'): x[:] = 0 assert_equal(x, Expression((1, 3, 5, 7))) assert_not_equal(x, Expression((2, 4, 6))) assert_not_equal(x, (1, 3, 5, 7)) with assert_raises_str(TypeError, "unhashable type: 'ListExpression'"): hash(x)
def t(self, name, sname=None): if sname is None: sname = name if py3k: [uname, bname] = [sname, sname.encode('UTF-8')] else: [uname, bname] = [sname.decode('UTF-8'), sname] symbol = Symbol(name) assert_equal(type(symbol), Symbol) assert_equal(symbol, Symbol(name)) assert_is(symbol, Symbol(name)) assert_equal(str(symbol), sname) assert_equal(unicode(symbol), uname) assert_not_equal(symbol, bname) assert_not_equal(symbol, uname) assert_equal(hash(symbol), hash(bname)) assert_pickle_equal(symbol) return symbol
def t(self, name, sname): if sname is None: sname = name if py3k: [uname, bname] = [sname, sname.encode('UTF-8')] else: [uname, bname] = [sname.decode('UTF-8'), sname] sym = Symbol(name) x = Expression(sym) assert_is(x, Expression(x)) # __repr__(x) assert_repr(x, 'Expression({sym!r})'.format(sym=sym)) # value: v = x.value assert_equal(type(v), Symbol) assert_equal(v, sym) # lvalue: v = x.lvalue assert_equal(type(v), Symbol) assert_equal(v, sym) # __str__(): assert_equal(str(x), sname) assert_repr(x, repr(Expression.from_string(sname))) # __unicode__(): assert_equal(unicode(x), uname) assert_repr(x, repr(Expression.from_string(uname))) # __eq__(), __ne__(): assert_equal(x, Expression(sym)) assert_not_equal(x, Expression(name)) assert_not_equal(x, sym) # __hash__(): assert_equal( hash(x), hash(bname.strip(b'|')) ) # pickle: assert_pickle_equal(x) return x
def test_indirect(self): r = self.pdf2djvu_indirect('--pages=1,1') r.assert_(stderr=re.compile('^Duplicate page:', re.M), rc=None) assert_not_equal(r.rc, 0)