Esempio n. 1
0
def test_primitive_be_display():
    assert space.w_display() is space.w_nil
    mock_display = W_PointersObject(space, space.w_Point, 4)
    w_wordbmp = W_WordsObject(space, space.w_Bitmap, 10)
    mock_display.store(space, 0, w_wordbmp)  # bitmap
    mock_display.store(space, 1, space.wrap_int(32))  # width
    mock_display.store(space, 2, space.wrap_int(10))  # height
    mock_display.store(space, 3, space.wrap_int(1))  # depth
    prim(BE_DISPLAY, [mock_display])
    assert space.w_display() is mock_display
    w_bitmap = mock_display.fetch(space, 0)
    assert w_bitmap is not w_wordbmp
    assert isinstance(w_bitmap, W_DisplayBitmap)
    sdldisplay = w_bitmap.display()
    assert isinstance(sdldisplay, display.SDLDisplay)

    mock_display2 = W_PointersObject(space, space.w_Point, 4)
    mock_display2.store(space, 0, W_WordsObject(space, space.w_Bitmap,
                                                10))  # bitmap
    mock_display2.store(space, 1, space.wrap_int(32))  # width
    mock_display2.store(space, 2, space.wrap_int(10))  # height
    mock_display2.store(space, 3, space.wrap_int(1))  # depth
    prim(BE_DISPLAY, [mock_display2])
    assert space.w_display() is mock_display2
    w_bitmap2 = mock_display.fetch(space, 0)
    assert isinstance(w_bitmap2, W_DisplayBitmap)
    assert w_bitmap.display() is w_bitmap2.display()
    assert sdldisplay.width == 32
    assert sdldisplay.height == 10

    prim(BE_DISPLAY, [mock_display])
    assert space.w_display() is mock_display
    assert mock_display.fetch(space, 0) is w_bitmap
Esempio n. 2
0
def test_primitive_be_display():
    assert space.w_display() is space.w_nil
    mock_display = W_PointersObject(space, space.w_Point, 4)
    w_wordbmp = W_WordsObject(space, space.w_Bitmap, 10)
    mock_display.store(space, 0, w_wordbmp)  # bitmap
    mock_display.store(space, 1, space.wrap_int(32))  # width
    mock_display.store(space, 2, space.wrap_int(10))  # height
    mock_display.store(space, 3, space.wrap_int(1))  # depth
    prim(BE_DISPLAY, [mock_display])
    assert space.w_display() is mock_display
    w_bitmap = mock_display.fetch(space, 0)
    assert w_bitmap is not w_wordbmp
    assert isinstance(w_bitmap, W_DisplayBitmap)
    sdldisplay = w_bitmap.display()
    assert isinstance(sdldisplay, display.SDLDisplay)

    mock_display2 = W_PointersObject(space, space.w_Point, 4)
    mock_display2.store(space, 0, W_WordsObject(space, space.w_Bitmap, 10))  # bitmap
    mock_display2.store(space, 1, space.wrap_int(32))  # width
    mock_display2.store(space, 2, space.wrap_int(10))  # height
    mock_display2.store(space, 3, space.wrap_int(1))  # depth
    prim(BE_DISPLAY, [mock_display2])
    assert space.w_display() is mock_display2
    w_bitmap2 = mock_display.fetch(space, 0)
    assert isinstance(w_bitmap2, W_DisplayBitmap)
    assert w_bitmap.display() is w_bitmap2.display()
    assert sdldisplay.width == 32
    assert sdldisplay.height == 10

    prim(BE_DISPLAY, [mock_display])
    assert space.w_display() is mock_display
    assert mock_display.fetch(space, 0) is w_bitmap
Esempio n. 3
0
    def fetch(self, space, n0):
        class_name = self.class_name(space)
        if W_DBObject.state.get_column_type(class_name, n0) is NIL:
            # print "Can't find column. Falling back to default fetch."
            return W_PointersObject.fetch(self, space, n0)

        if self.ivar_cache[n0] is not None:
            return self.ivar_cache[n0]

        cursor = dbm.connection().execute(space, select_sql(class_name, n0),
                                          [self.w_id])

        w_result = cursor.next(space).fetch(space, 0)
        if w_result:
            if W_DBObject.state.get_column_type(class_name, n0) is BLOB:
                db_id = space.unwrap_int(w_result)
                w_result = W_DBObject.state.db_objects[db_id]

            self.ivar_cache[n0] = w_result
            return w_result
        else:
            raise PrimitiveFailedError
Esempio n. 4
0
    def fetch(self, space, n0):
        class_name = self.class_name(space)
        if W_DBObject.state.get_column_type(class_name, n0) is NIL:
            # print "Can't find column. Falling back to default fetch."
            return W_PointersObject.fetch(self, space, n0)

        if self.ivar_cache[n0] is not None:
            return self.ivar_cache[n0]

        cursor = dbm.connection().execute(
            space, select_sql(class_name, n0), [self.w_id])

        w_result = cursor.next(space).fetch(space, 0)
        if w_result:
            if W_DBObject.state.get_column_type(class_name, n0) is BLOB:
                db_id = space.unwrap_int(w_result)
                w_result = W_DBObject.state.db_objects[db_id]

            self.ivar_cache[n0] = w_result
            return w_result
        else:
            raise PrimitiveFailedError