Ejemplo n.º 1
0
    def test_SpecifyThatNextValidIdCanBeReset(self):
        newBaseEntity = None

        # arrange
        for i in range(0, 5):
            newBaseEntity = BaseEntity(i)

        # assert
        self.assertEqual(newBaseEntity.Id, 4)
        self.assertEqual(BaseEntity.GetNextValidId(), 5)

        # act
        BaseEntity.ResetNextValidId()

        # assert
        self.assertEqual(BaseEntity.GetNextValidId(), 0)
    def test_SpecifyThatEntityEngineCanBeConstructed(self):

        # Ensure that all singletons are reset
        self.assertEqual(0, BaseEntity.GetNextValidId(), "GetNextValidId 1")
        self.assertEqual({}, EntityManager._getEntityMap(), "_getEntityMap 1")
        self.assertEqual(True,
                         TelegramDispatcher().PriorityQ.IsEmpty(),
                         "PriorityQ 1")

        # Create the engine
        entityEngine = self.CreateTestEntityEngine()

        # Get references to objects under test
        entityMap = EntityManager._getEntityMap()
        actionMap = entityEngine._actionMap
        entityOne = entityMap[0]
        entityTwo = entityMap[1]

        # Assert singletons
        self.assertEqual(True,
                         TelegramDispatcher().PriorityQ.IsEmpty(),
                         "PriorityQ 2")

        # Assert entityMap
        self.assertEqual(2, len(entityMap), "len(entityMap)")
        self.assertEqual("TestEntityOne",
                         type(entityMap[0]).__name__, "entityMap[0]")
        self.assertEqual("TestEntityTwo",
                         type(entityMap[1]).__name__, "entityMap[1]")
        self.assertEqual(0, entityMap[0].Id, "entityMap[0].Id")
        self.assertEqual(1, entityMap[1].Id, "entityMap[1].Id")

        # Assert actionMap
        self.assertEqual(4, len(actionMap), "len(actionMap)")
        self.assertEqual("ActionOn", list(actionMap.keys())[0], "key 0")
        self.assertEqual("ActionOff", list(actionMap.keys())[1], "key 1")
        self.assertEqual("ActionEnable", list(actionMap.keys())[2], "key 2")
        self.assertEqual("ActionDisable", list(actionMap.keys())[3], "key 3")
        self.assertEqual(actionMap['ActionOn']['FunctionToExecute'],
                         entityOne.ActionOn)
        self.assertEqual(actionMap['ActionOff']['FunctionToExecute'],
                         entityOne.ActionOff)
        self.assertEqual(actionMap['ActionEnable']['FunctionToExecute'],
                         entityTwo.ActionEnable)
        self.assertEqual(actionMap['ActionDisable']['FunctionToExecute'],
                         entityTwo.ActionDisable)
Ejemplo n.º 3
0
 def CreateTestTrigger():
     BaseEntity.ResetNextValidId()
     return TestTrigger(BaseEntity.GetNextValidId())
    def __init__(self, lifeTimeInNumberOfUpdates):
        super().__init__(BaseEntity.GetNextValidId())

        # the lifetime of this trigger in update-steps
        self._lifetime = lifeTimeInNumberOfUpdates