Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit test: image.load_basic() #1777

Closed
MyreMylar opened this issue May 18, 2020 · 5 comments · Fixed by #2307
Closed

Add unit test: image.load_basic() #1777

MyreMylar opened this issue May 18, 2020 · 5 comments · Fixed by #2307
Assignees
Labels
easy An easy challenge to solve good first issue image pygame.image needs-tests Unit tests need writing python code This involves python code

Comments

@MyreMylar
Copy link
Contributor

@MyreMylar MyreMylar added image pygame.image good first issue needs-tests Unit tests need writing python code This involves python code easy An easy challenge to solve labels May 18, 2020
@williams-c
Copy link
Contributor

I'll work on this one if that's alright

@dtomci
Copy link

dtomci commented Oct 1, 2020

Hello, can I try to do this ?

@MyreMylar MyreMylar assigned dtomci and unassigned williams-c Oct 2, 2020
@MyreMylar
Copy link
Contributor Author

Sure, it's been a few months. There is some discussion of the function in another issue recently that might be of interest:

#1732

@bwright8
Copy link
Contributor

bwright8 commented Nov 4, 2020

May I work on this and ask a couple questions? It is ok to recycle code from other tests? How many filetypes should be tested?

@MyreMylar
Copy link
Contributor Author

I believe load_basic() only loads .bmp files, however there are a couple of loading paths (loading from a file on disc directly, loading from bmp data in a file .like object in memory). Recycling code from other tests is OK, in fact there has been one nearly done attempt at this test already in a PR that you should look at here:

#2225

So you know where we got to and what was missing from that go around.

Worth looking at the underlying C code as well:

pygame/src_c/image.c

Lines 83 to 128 in 4306f7a

static PyObject *
image_load_basic(PyObject *self, PyObject *arg)
{
PyObject *obj;
PyObject *final;
PyObject *oencoded;
const char *name = NULL;
SDL_Surface *surf;
if (!PyArg_ParseTuple(arg, "O|s", &obj, &name)) {
return NULL;
}
oencoded = pg_EncodeString(obj, "UTF-8", NULL, pgExc_SDLError);
if (oencoded == NULL) {
return NULL;
}
if (oencoded != Py_None) {
Py_BEGIN_ALLOW_THREADS;
surf = SDL_LoadBMP(Bytes_AS_STRING(oencoded));
Py_END_ALLOW_THREADS;
Py_DECREF(oencoded);
}
else {
SDL_RWops *rw;
Py_DECREF(oencoded);
rw = pgRWops_FromFileObject(obj);
if (rw == NULL) {
return NULL;
}
Py_BEGIN_ALLOW_THREADS;
surf = SDL_LoadBMP_RW(rw, 1);
Py_END_ALLOW_THREADS;
}
if (surf == NULL) {
return RAISE(pgExc_SDLError, SDL_GetError());
}
final = (PyObject *)pgSurface_New(surf);
if (final == NULL) {
SDL_FreeSurface(surf);
}
return final;
}

@MightyJosip MightyJosip linked a pull request Nov 7, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy An easy challenge to solve good first issue image pygame.image needs-tests Unit tests need writing python code This involves python code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants