3838 test_send_from_coroutine /1 ,
3939 test_send_multiple_from_coroutine /1 ,
4040 test_send_is_nonblocking /1 ,
41- test_send_interleaved_with_async /1
41+ test_send_interleaved_with_async /1 ,
42+ % % whereis tests
43+ test_whereis_registered_process /1 ,
44+ test_whereis_nonexistent /1 ,
45+ test_whereis_with_atom /1 ,
46+ test_whereis_with_bytes /1 ,
47+ test_whereis_invalid_type /1
4248]).
4349
4450all () ->
@@ -63,7 +69,13 @@ all() ->
6369 test_send_from_coroutine ,
6470 test_send_multiple_from_coroutine ,
6571 test_send_is_nonblocking ,
66- test_send_interleaved_with_async
72+ test_send_interleaved_with_async ,
73+ % % whereis tests
74+ test_whereis_registered_process ,
75+ test_whereis_nonexistent ,
76+ test_whereis_with_atom ,
77+ test_whereis_with_bytes ,
78+ test_whereis_invalid_type
6779 ].
6880
6981init_per_suite (Config ) ->
@@ -276,6 +288,64 @@ test_send_interleaved_with_async(_Config) ->
276288 receive <<" interleaved_2" >> -> ok after 5000 -> ct :fail (timeout_interleaved_2 ) end ,
277289 receive <<" interleaved_3" >> -> ok after 5000 -> ct :fail (timeout_interleaved_3 ) end .
278290
291+ % %% ============================================================================
292+ % %% erlang.whereis() Tests
293+ % %% ============================================================================
294+
295+ % % @doc Test erlang.whereis() finds a registered process.
296+ test_whereis_registered_process (_Config ) ->
297+ % % Register this process
298+ Self = self (),
299+ erlang :register (py_whereis_test_proc , Self ),
300+ try
301+ % % Look it up from Python
302+ {ok , Pid } = py :eval (<<" erlang.whereis('py_whereis_test_proc')" >>),
303+ % % Verify we got our PID back
304+ true = is_pid (Pid ),
305+ Self = Pid
306+ after
307+ erlang :unregister (py_whereis_test_proc )
308+ end ,
309+ ok .
310+
311+ % % @doc Test erlang.whereis() returns None for nonexistent process.
312+ test_whereis_nonexistent (_Config ) ->
313+ {ok , none } = py :eval (<<" erlang.whereis('nonexistent_process_12345')" >>),
314+ ok .
315+
316+ % % @doc Test erlang.whereis() with erlang.Atom type.
317+ % % Note: Use erlang._atom() since erlang.atom() is a Python wrapper not
318+ % % available in py:eval context.
319+ test_whereis_with_atom (_Config ) ->
320+ Self = self (),
321+ erlang :register (py_whereis_atom_test , Self ),
322+ try
323+ {ok , Pid } = py :eval (<<" erlang.whereis(erlang._atom('py_whereis_atom_test'))" >>),
324+ true = is_pid (Pid ),
325+ Self = Pid
326+ after
327+ erlang :unregister (py_whereis_atom_test )
328+ end ,
329+ ok .
330+
331+ % % @doc Test erlang.whereis() with bytes argument.
332+ test_whereis_with_bytes (_Config ) ->
333+ Self = self (),
334+ erlang :register (py_whereis_bytes_test , Self ),
335+ try
336+ {ok , Pid } = py :eval (<<" erlang.whereis(b'py_whereis_bytes_test')" >>),
337+ true = is_pid (Pid ),
338+ Self = Pid
339+ after
340+ erlang :unregister (py_whereis_bytes_test )
341+ end ,
342+ ok .
343+
344+ % % @doc Test erlang.whereis() with invalid type raises TypeError.
345+ test_whereis_invalid_type (_Config ) ->
346+ {error , {'TypeError' , _ }} = py :eval (<<" erlang.whereis(123)" >>),
347+ ok .
348+
279349% %% ============================================================================
280350% %% Helper Functions
281351% %% ============================================================================
0 commit comments