11"""Test cases for the SpaceRenderer class in Mesa."""
22
3+ import random
34import re
45from unittest .mock import MagicMock , patch
56
@@ -39,7 +40,9 @@ class CustomModel(mesa.Model):
3940
4041 def __init__ (self , seed = None ): # noqa: D107
4142 super ().__init__ (seed = seed )
42- self .grid = mesa .discrete_space .OrthogonalMooreGrid ([2 , 2 ])
43+ self .grid = mesa .discrete_space .OrthogonalMooreGrid (
44+ [2 , 2 ], random = random .Random (42 )
45+ )
4346 self .layer = PropertyLayer ("test" , [2 , 2 ], default_value = 0 )
4447
4548 self .grid .add_property_layer (self .layer )
@@ -59,16 +62,22 @@ def test_backend_selection():
5962@pytest .mark .parametrize (
6063 "grid,expected_drawer" ,
6164 [
62- (OrthogonalMooreGrid ([2 , 2 ]), OrthogonalSpaceDrawer ),
65+ (
66+ OrthogonalMooreGrid ([2 , 2 ], random = random .Random (42 )),
67+ OrthogonalSpaceDrawer ,
68+ ),
6369 (SingleGrid (width = 2 , height = 2 , torus = False ), OrthogonalSpaceDrawer ),
6470 (MultiGrid (width = 2 , height = 2 , torus = False ), OrthogonalSpaceDrawer ),
65- (HexGrid ([2 , 2 ]), HexSpaceDrawer ),
71+ (HexGrid ([2 , 2 ], random = random . Random ( 42 ) ), HexSpaceDrawer ),
6672 (HexSingleGrid (width = 2 , height = 2 , torus = False ), HexSpaceDrawer ),
6773 (HexMultiGrid (width = 2 , height = 2 , torus = False ), HexSpaceDrawer ),
68- (Network (G = MagicMock ()), NetworkSpaceDrawer ),
74+ (Network (G = MagicMock (), random = random . Random ( 42 ) ), NetworkSpaceDrawer ),
6975 (NetworkGrid (g = MagicMock ()), NetworkSpaceDrawer ),
7076 (ContinuousSpace (x_max = 2 , y_max = 2 , torus = False ), ContinuousSpaceDrawer ),
71- (VoronoiGrid ([[0 , 0 ], [1 , 1 ]]), VoronoiSpaceDrawer ),
77+ (
78+ VoronoiGrid ([[0 , 0 ], [1 , 1 ]], random = random .Random (42 )),
79+ VoronoiSpaceDrawer ,
80+ ),
7281 ],
7382)
7483def test_space_drawer_selection (grid , expected_drawer ):
@@ -91,14 +100,16 @@ def test_map_coordinates():
91100 # same for orthogonal grids
92101 assert np .array_equal (mapped ["loc" ], arr )
93102
94- with patch .object (model , "grid" , new = HexGrid ([2 , 2 ])):
103+ with patch .object (model , "grid" , new = HexGrid ([2 , 2 ], random = random . Random ( 42 ) )):
95104 sr = SpaceRenderer (model )
96105 mapped = sr ._map_coordinates (args )
97106
98107 assert not np .array_equal (mapped ["loc" ], arr )
99108 assert mapped ["loc" ].shape == arr .shape
100109
101- with patch .object (model , "grid" , new = Network (G = MagicMock ())):
110+ with patch .object (
111+ model , "grid" , new = Network (G = MagicMock (), random = random .Random (42 ))
112+ ):
102113 sr = SpaceRenderer (model )
103114 # Patch the space_drawer.pos to provide a mapping for the test
104115 sr .space_drawer .pos = {0 : (0 , 0 ), 1 : (1 , 1 ), 2 : (2 , 2 ), 3 : (3 , 3 )}
0 commit comments