I have 2 pygame surfaces (technically subsurfaces) and I need to test for their equality.
Here’s my code:
actor.display(mockSurface, Rect((0, 0, 640, 640)))
assert actor.image == actor.spriteSheet.subsurface(Rect((0, 30, 30, 30)))
And here’s the code behind actor.display:
def display(self, screen, camera_location):
self.image = self.spriteSheet.subsurface(Rect((0, 30, 30, 30)))
screen.blit(self.image, (0, 0))
Now here’s the error I get from that assertion line:
> assert teste.image == teste.spriteSheet.subsurface(Rect((0, 30, 30, 30)))
E assert <Surface(30x30x32 SW)> == <Surface(30x30x32 SW)>
E + where <Surface(30x30x32 SW)> = <actor.Actor instance at 0x2f78ef0>.image
E + and <Surface(30x30x32 SW)> = <Surface(120x90x32 SW)>.subsurface(<rect(0, 30, 30, 30)>)
E + where <Surface(120x90x32 SW)> = <actor.Actor instance at 0x2f78ef0>.spriteSheet
E + and <rect(0, 30, 30, 30)> = Rect((0, 30, 30, 30))
These should be equal (am I wrong), but by some sneaky snake trick the assertion fails.
Use Surface.get_offset() and Surface.get_parent() to determine whether both subsurfaces point to the same area of their parent surface.
Both s1 and s2 refer to different objects thus are not equal.