def test_packed_bits(self): pf = PixelFormatPackedBits('<') assert_repr(pf, "djvu.decode.PixelFormatPackedBits('<')") assert_equal(pf.bpp, 1) pf = PixelFormatPackedBits('>') assert_repr(pf, "djvu.decode.PixelFormatPackedBits('>')") assert_equal(pf.bpp, 1)
def t(self, fp): def read(): return Expression.from_stream(fp) x = read() assert_repr(x, self.repr[0]) x = read() assert_repr(x, self.repr[1]) with assert_raises(ExpressionSyntaxError): x = read()
def test1(self): x = Expression(()) assert_repr(x, "Expression([])") y = Expression(x) assert_is(x, y) assert_equal(x.value, ()) assert_equal(x.lvalue, []) assert_equal(len(x), 0) assert_equal(bool(x), False) assert_equal(list(x), [])
def test_rgb_mask(self): pf = PixelFormatRgbMask(0xFF, 0xF00, 0x1F000, 0, 16) assert_repr( pf, "djvu.decode.PixelFormatRgbMask(red_mask = 0x00ff, green_mask = 0x0f00, blue_mask = 0xf000, xor_value = 0x0000, bpp = 16)" ) pf = PixelFormatRgbMask(0xFF000000, 0xFF0000, 0xFF00, 0xFF, 32) assert_repr( pf, "djvu.decode.PixelFormatRgbMask(red_mask = 0xff000000, green_mask = 0x00ff0000, blue_mask = 0x0000ff00, xor_value = 0x000000ff, bpp = 32)" )
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 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 test_copy3(self): x = Expression([1, [2], 3]) y = copy.deepcopy(x) x[1][0] = 0 assert_repr(x, 'Expression([1, [0], 3])') assert_repr(y, 'Expression([1, [2], 3])') x[1] = 0 assert_repr(x, 'Expression([1, 0, 3])') assert_repr(y, 'Expression([1, [2], 3])')
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_rgb(self): pf = PixelFormatRgb() assert_repr(pf, "djvu.decode.PixelFormatRgb(byte_order = 'RGB', bpp = 24)") pf = PixelFormatRgb('RGB') assert_repr(pf, "djvu.decode.PixelFormatRgb(byte_order = 'RGB', bpp = 24)") pf = PixelFormatRgb('BGR') assert_repr(pf, "djvu.decode.PixelFormatRgb(byte_order = 'BGR', bpp = 24)")
def test_rgb(self): pf = PixelFormatRgb() assert_repr( pf, "djvu.decode.PixelFormatRgb(byte_order = 'RGB', bpp = 24)") pf = PixelFormatRgb('RGB') assert_repr( pf, "djvu.decode.PixelFormatRgb(byte_order = 'RGB', bpp = 24)") pf = PixelFormatRgb('BGR') assert_repr( pf, "djvu.decode.PixelFormatRgb(byte_order = 'BGR', bpp = 24)")
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_grey(self): pf = PixelFormatGrey() assert_repr(pf, "djvu.decode.PixelFormatGrey(bpp = 8)")
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 test2(self): x = Expression(u('żółw')) if py3k: assert_repr(x, "Expression('żółw')") else: assert_repr(x, r"Expression('\xc5\xbc\xc3\xb3\xc5\x82w')")
def test1(self): x = Expression(u('eggs')) assert_repr(x, "Expression('eggs')") assert_is(x, Expression(x))
def test_rgb_mask(self): pf = PixelFormatRgbMask(0xFF, 0xF00, 0x1F000, 0, 16) assert_repr(pf, "djvu.decode.PixelFormatRgbMask(red_mask = 0x00ff, green_mask = 0x0f00, blue_mask = 0xf000, xor_value = 0x0000, bpp = 16)") pf = PixelFormatRgbMask(0xFF000000, 0xFF0000, 0xFF00, 0xFF, 32) assert_repr(pf, "djvu.decode.PixelFormatRgbMask(red_mask = 0xff000000, green_mask = 0x00ff0000, blue_mask = 0x0000ff00, xor_value = 0x000000ff, bpp = 32)")
def test_repr(self): assert_repr(TEXT_ZONE_PAGE, '<djvu.const.TextZoneType: page>') assert_repr(TEXT_ZONE_COLUMN, '<djvu.const.TextZoneType: column>') assert_repr(TEXT_ZONE_REGION, '<djvu.const.TextZoneType: region>') assert_repr(TEXT_ZONE_PARAGRAPH, '<djvu.const.TextZoneType: para>') assert_repr(TEXT_ZONE_LINE, '<djvu.const.TextZoneType: line>') assert_repr(TEXT_ZONE_WORD, '<djvu.const.TextZoneType: word>') assert_repr(TEXT_ZONE_CHARACTER, '<djvu.const.TextZoneType: char>')
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)