Example #1
0
def test_pickle_error():
    class ErroneousPickleable(object):
        def __reduce__(self):
            return 12345

    with pytest.raises(PicklingError):
        dumps(ErroneousPickleable())
def test_collision_handler_gravity_pickle():
    from panda3d.core import CollisionHandlerGravity

    collider1 = NodePath(CollisionNode("collider1"))
    collider2 = NodePath(CollisionNode("collider2"))
    target1 = NodePath("target1")
    target2 = NodePath("target2")

    handler = CollisionHandlerGravity()
    handler.add_out_pattern("out pattern")
    handler.add_collider(collider1, target1)
    handler.add_collider(collider2, target2)
    handler.offset = 1.0
    handler.reach = 2.0
    handler.max_velocity = 3.0
    handler.gravity = -4.0

    handler = loads(dumps(handler, -1))

    assert tuple(handler.in_patterns) == ()
    assert tuple(handler.again_patterns) == ()
    assert tuple(handler.out_patterns) == ("out pattern", )
    assert handler.center == None
    assert handler.offset == 1.0
    assert handler.reach == 2.0
    assert handler.max_velocity == 3.0
    assert handler.gravity == -4.0
Example #3
0
def test_collision_traverser_pickle():
    from direct.stdpy.pickle import dumps, loads

    handler = CollisionHandlerQueue()

    collider1 = NodePath(CollisionNode("collider1"))
    collider2 = NodePath(CollisionNode("collider2"))

    trav = CollisionTraverser("test123")
    trav.respect_prev_transform = True
    trav.add_collider(collider1, handler)
    trav.add_collider(collider2, handler)

    trav = loads(dumps(trav, -1))
    assert trav.respect_prev_transform is True

    assert trav.name == "test123"
    assert trav.get_num_colliders() == 2
    collider1 = trav.get_collider(0)
    collider2 = trav.get_collider(1)
    assert collider1.name == "collider1"
    assert collider2.name == "collider2"

    # Two colliders must still be the same object; this only works with our own
    # version of the pickle module, in direct.stdpy.pickle.
    assert trav.get_handler(collider1) == trav.get_handler(collider2)
Example #4
0
def test_reduce_persist():
    from panda3d.core import NodePath

    parent = NodePath("parent")
    child = parent.attach_new_node("child")

    parent2, child2 = loads(dumps([parent, child]))
    assert tuple(parent2.children) == (child2, )
Example #5
0
def test_pickle_copy():
    from panda3d.core import PandaNode, NodePath

    # Make two Python wrappers pointing to the same node
    node1 = PandaNode("node")
    node2 = NodePath(node1).node()
    assert node1.this == node2.this
    assert id(node1) != id(node2)

    # Test that pickling and loading still results in the same node object.
    node1, node2 = loads(dumps([node1, node2]))
    assert node1 == node2
def test_cpta_float_pickle():
    from panda3d.core import PTA_float, CPTA_float
    from direct.stdpy.pickle import dumps, loads, HIGHEST_PROTOCOL

    null_pta = CPTA_float(PTA_float())

    empty_pta = CPTA_float([])

    data_pta = CPTA_float([1.0, 2.0, 3.0])
    data = data_pta.get_data()

    for proto in range(1, HIGHEST_PROTOCOL + 1):
        null_pta2 = loads(dumps(null_pta, proto))
        assert null_pta2.is_null()
        assert len(null_pta2) == 0

        empty_pta2 = loads(dumps(empty_pta, proto))
        assert not empty_pta2.is_null()
        assert len(empty_pta2) == 0

        data_pta2 = loads(dumps(data_pta, proto))
        assert tuple(data_pta2) == (1.0, 2.0, 3.0)
        assert data_pta2.get_data() == data_pta.get_data()
def test_collision_handler_event_pickle():
    from panda3d.core import CollisionHandlerEvent

    handler = CollisionHandlerEvent()
    handler.add_in_pattern("abcdefg")
    handler.add_in_pattern("test")
    handler.add_again_pattern("again pattern")
    handler.add_again_pattern("another again pattern")
    handler.add_out_pattern("out pattern")

    handler = loads(dumps(handler, -1))

    assert tuple(handler.in_patterns) == ("abcdefg", "test")
    assert tuple(handler.again_patterns) == ("again pattern",
                                             "another again pattern")
    assert tuple(handler.out_patterns) == ("out pattern", )
Example #8
0
    def showSelection(self,choiceList = ['A','B'],enablesList = None):
        '''This method shows a selection, which sets 'last_choice' in 
        script space to player's choice. (0 is the first, 1 is the second etc.)
        you can disable some of the selections with enablesList
        for example for choiceList ['A','B','C'] and enablesList
        '''
        #Store the last selection
        rdc = copy.deepcopy(self._currentDump)
        rdc.last_choice = None
        self.__tempDumpedLastChoice = pickle.dumps(rdc, 2)

        self._choiceReady = False
        startPos = (0,0,0.1 * len(choiceList))
        frameSize = (-0.6,0.6,-0.05 - 0.1*len(choiceList), 0.1 + 0.1*len(choiceList))
        buttonSize = (-0.5,0.5,-0.050,0.10)
        margin = 0.05
        self.__currentSelection = SogalDialog(enableMask = False, fadeScreen= None, command = self.__selected, 
                                              textList= choiceList, enablesList= enablesList, sortType= 1,noFocus = True,
                                              startPos = startPos,frameSize = frameSize,margin = margin,
                                              buttonSize = buttonSize)
def test_collision_handler_pusher_pickle():
    from panda3d.core import CollisionHandlerPusher

    collider1 = NodePath(CollisionNode("collider1"))
    collider2 = NodePath(CollisionNode("collider2"))
    target1 = NodePath("target1")
    target2 = NodePath("target2")

    handler = CollisionHandlerPusher()
    handler.add_again_pattern("again pattern")
    handler.add_collider(collider1, target1)
    handler.add_collider(collider2, target2)
    handler.horizontal = True

    handler = loads(dumps(handler, -1))

    assert tuple(handler.in_patterns) == ()
    assert tuple(handler.again_patterns) == ("again pattern", )
    assert tuple(handler.out_patterns) == ()
    assert not handler.has_center()
    assert handler.horizontal
def test_collision_handler_queue_pickle():
    from panda3d.core import CollisionHandlerQueue

    handler = CollisionHandlerQueue()
    handler = loads(dumps(handler, -1))
    assert type(handler) == CollisionHandlerQueue
Example #11
0
def test_loader_file_type_registry_pickle():
    from direct.stdpy.pickle import dumps, loads

    registry = LoaderFileTypeRegistry.get_global_ptr()
    assert loads(dumps(registry, -1)) == registry