0

I use pykka python library. I would like to create an actor, and later test if the actor created is of the proper class.

class MyActor( ThreadingActor ):
  # ...

actor = MyActor.start().proxy()

assert actor.__class__ == MyActor # check here?

Here actor.__class__ is pykka.actor.ActorRef. How to check if it refers to MyActor class? I need it for a unit test suite.

Jakub M.
  • 32,471
  • 48
  • 110
  • 179

1 Answers1

2

To get the actor class from an pykka.actor.ActorRef:

ref = MyActor.start()
assert ref.actor_class == MyActor

To get the actor class from an pykka.proxy.ActorProxy:

proxy = MyActor.start().proxy()
assert proxy.actor_ref.actor_class == MyActor

I've forgotten to document the actor_class field on ActorRef objects, but all fields that are not made "private" by prefixing with underscore will continue to be supported in the future.

jodal
  • 193
  • 4
  • I've updated the [documentation](http://pykka.readthedocs.org/en/latest/api/#pykka.actor.ActorRef.actor_class). It now includes the `ActorRef.actor_class` attribute. – jodal Oct 12 '12 at 09:04