File: error_test.py

package info (click to toggle)
pysdl2 0.9.9%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,276 kB
  • sloc: python: 18,592; makefile: 148; sh: 40
file content (42 lines) | stat: -rw-r--r-- 1,420 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import sys
import pytest
import sdl2
from ctypes import create_string_buffer, byref
from sdl2 import SDL_Init, SDL_Quit, error


class TestSDLError(object):
    __tags__ = ["sdl"]

    @classmethod
    def setup_class(cls):
        SDL_Init(0)

    @classmethod
    def teardown_class(cls):
        SDL_Quit()

    def test_SDL_GetSetClearError(self):
        assert error.SDL_GetError() == b""
        error.SDL_SetError(b"A Unit Test Error Message")
        assert error.SDL_GetError() == b"A Unit Test Error Message"
        error.SDL_ClearError()
        assert error.SDL_GetError() == b""
        error.SDL_SetError(b"A Unit Test Error Message")
        assert error.SDL_GetError() == b"A Unit Test Error Message"
        assert error.SDL_GetError() == b"A Unit Test Error Message"
        error.SDL_ClearError()
        error.SDL_SetError(b"123456789")
        assert error.SDL_GetError() == b"123456789"

    @pytest.mark.skipif(sdl2.dll.version < 2014, reason="not available")
    def test_SDL_GetErrorMsg(self):
        error.SDL_SetError(b"123456789")
        assert error.SDL_GetError() == b"123456789"
        buf = create_string_buffer(10)
        assert error.SDL_GetErrorMsg(buf, 10) == b"123456789"
        assert buf.value == b"123456789"
        buf2 = create_string_buffer(5)
        assert error.SDL_GetErrorMsg(buf2, 5) == b"1234"
        assert buf2.value == b"1234"
        error.SDL_ClearError()