Skip to content

Commit c1dba7a

Browse files
committed
Clean up mock object.
1 parent 9a2f602 commit c1dba7a

File tree

4 files changed

+20
-24
lines changed

4 files changed

+20
-24
lines changed

tcod/event.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,16 @@ def _pixel_to_tile(x: float, y: float) -> Tuple[float, float]:
8989
Point = NamedTuple("Point", [("x", int), ("y", int)])
9090

9191
# manually define names for SDL macros
92-
BUTTON_LEFT = lib.SDL_BUTTON_LEFT
93-
BUTTON_MIDDLE = lib.SDL_BUTTON_MIDDLE
94-
BUTTON_RIGHT = lib.SDL_BUTTON_RIGHT
95-
BUTTON_X1 = lib.SDL_BUTTON_X1
96-
BUTTON_X2 = lib.SDL_BUTTON_X2
97-
BUTTON_LMASK = lib.SDL_BUTTON_LMASK
98-
BUTTON_MMASK = lib.SDL_BUTTON_MMASK
99-
BUTTON_RMASK = lib.SDL_BUTTON_RMASK
100-
BUTTON_X1MASK = lib.SDL_BUTTON_X1MASK
101-
BUTTON_X2MASK = lib.SDL_BUTTON_X2MASK
92+
BUTTON_LEFT = 1
93+
BUTTON_MIDDLE = 2
94+
BUTTON_RIGHT = 3
95+
BUTTON_X1 = 4
96+
BUTTON_X2 = 5
97+
BUTTON_LMASK = 0x1
98+
BUTTON_MMASK = 0x2
99+
BUTTON_RMASK = 0x4
100+
BUTTON_X1MASK = 0x8
101+
BUTTON_X2MASK = 0x10
102102

103103
# reverse tables are used to get the tcod.event name from the value.
104104
_REVERSE_BUTTON_TABLE = {

tcod/libtcodpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4404,7 +4404,7 @@ def sys_clipboard_get() -> str:
44044404
@atexit.register
44054405
def _atexit_verify() -> None:
44064406
"""Warns if the libtcod root console is implicitly deleted."""
4407-
if lib.TCOD_ctx.root:
4407+
if lib and lib.TCOD_ctx.root:
44084408
warnings.warn(
44094409
"The libtcod root console was implicitly deleted.\n"
44104410
"Make sure the 'with' statement is used with the root console to"

tcod/loader.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,18 @@ def get_sdl_version() -> str:
6666
class _Mock(object):
6767
"""Mock object needed for ReadTheDocs."""
6868

69-
CData = () # This gets passed to an isinstance call.
70-
7169
@staticmethod
7270
def def_extern() -> Any:
7371
"""Pass def_extern call silently."""
7472
return lambda func: func
7573

76-
def __getattr__(self, attr: Any) -> Any:
77-
"""This object pretends to have everything."""
78-
return self
79-
80-
def __call__(self, *args: Any, **kargs: Any) -> Any:
81-
"""Suppress any other calls"""
82-
return self
74+
def __getattr__(self, attr: str) -> None:
75+
"""Return None on any attribute."""
76+
return None
8377

84-
def __str__(self) -> Any:
85-
"""Just have ? in case anything leaks as a parameter default."""
86-
return "?"
78+
def __bool__(self) -> bool:
79+
"""Allow checking for this mock object at import time."""
80+
return False
8781

8882

8983
lib = None # type: Any

tcod/path.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def _get_pathcost_func(
6262
name: str,
6363
) -> Callable[[int, int, int, int, Any], float]:
6464
"""Return a properly cast PathCostArray callback."""
65+
if not ffi:
66+
return lambda x1, y1, x2, y2, _: 0
6567
return ffi.cast( # type: ignore
6668
"TCOD_path_func_t", ffi.addressof(lib, name)
6769
)
@@ -162,7 +164,7 @@ def get_tcod_path_ffi(self) -> Tuple[Any, Any, Tuple[int, int]]:
162164
"struct PathCostArray*",
163165
(ffi.cast("char*", self.ctypes.data), self.strides),
164166
)
165-
return callback, userdata, self.shape
167+
return callback, userdata, (self.shape[0], self.shape[1])
166168

167169

168170
class _PathFinder(object):

0 commit comments

Comments
 (0)