okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
01f8c3255
main
1"""The run config's experimental "pool_cores" (the CPU expert workers' logical processors; --pool-cores in the engine).""" 2import contextlib 3import io 4import unittest 5 6from serve .server import engine_args ,pool_cores_args 7 8 9class PoolCoresConfig (unittest .TestCase ): 10def test_off_by_default (self ): 11self .assertEqual (pool_cores_args ({}, []), []) 12self .assertEqual (pool_cores_args ({"pool_cores" :None }, []), []) 13self .assertEqual (pool_cores_args ({"pool_cores" :"" }, []), []) 14self .assertEqual (pool_cores_args ({"pool_cores" : []}, []), []) 15self .assertEqual (pool_cores_args ({"pool_cores" :False }, []), []) 16self .assertEqual (engine_args ({"args" : ["--pack" ,"p" ]}), ["--pack" ,"p" ])# nothing is added to an ordinary config 17 18def test_text_and_list_forms (self ): 19self .assertEqual (pool_cores_args ({"pool_cores" :"2,4,6,8" }, []), ["--pool-cores" ,"2,4,6,8" ]) 20self .assertEqual (pool_cores_args ({"pool_cores" :" 2-14:2 " }, []), ["--pool-cores" ,"2-14:2" ]) 21self .assertEqual (pool_cores_args ({"pool_cores" : [2 ,4 ,6 ]}, []), ["--pool-cores" ,"2,4,6" ]) 22self .assertEqual (pool_cores_args ({"pool_cores" :"0,2-6,10" }, []), ["--pool-cores" ,"0,2-6,10" ]) 23 24def test_the_args_own_value_wins (self ): 25self .assertEqual (pool_cores_args ({"pool_cores" :"2,4" }, ["--pool-cores" ,"6,8" ]), []) 26 27def test_a_list_that_cannot_be_read_is_said_and_ignored (self ): 28for bad in ("two,four" ,"1,,2" ,"6-2x" ,- 1 ,True ,5 , [1 ,"a" ], [- 1 ], {"a" :1 }): 29buf = io .StringIO () 30with contextlib .redirect_stdout (buf ): 31r = pool_cores_args ({"pool_cores" :bad }, []) 32self .assertEqual (r , [],bad ) 33self .assertIn ("pool_cores" ,buf .getvalue (),bad ) 34 35def test_reaches_the_engine_arguments (self ): 36args = engine_args ({"args" : ["--pack" ,"p" ],"pool_cores" :"2,4,6" }) 37self .assertEqual (args [- 2 :], ["--pool-cores" ,"2,4,6" ]) 38 39 40if __name__ == "__main__" : 41unittest .main ()