def test_Add_noExistingTasks(): t = task.TaskQueue() f = lambda x: x a = ('abc', ) t.Add(f, a) assert t.hasNext() assert t._TaskList[0] == (f, a)
def test_Add_oneExistingTask(): t = task.TaskQueue() t._TaskList = [('def')] f = lambda x: x a = ('abc', ) t.Add(f, a) assert t._TaskList[1] == (f, a)
def test_Next_oneTaskInQueue(): t = task.TaskQueue() a = ('abc', ) t._TaskList = [a] n = t.Next() assert n == a assert not t.hasNext()
def test_Next_twoTasksInQueue(): t = task.TaskQueue() a = ('abc', ) b = ('def', ) t._TaskList = [a, b] n = t.Next() assert n == a assert t.hasNext()
def test_ExecuteAll_oneExistingTask(): t = task.TaskQueue() f = Mock() a = ('a', 'b') t._TaskList = [(f, a)] t.ExecuteAll() f.assert_called_once_with('a', 'b') assert not t.hasNext()
def test_Next_LocksMutex(): m = Mock() m.__enter__ = Mock() m.__exit__ = Mock() t = task.TaskQueue() t._Mutex = m t._TaskList = [('abc', )] t.Next() m.__enter__.assert_called() m.__exit__.assert_called()
def test_hasNext_LocksMutex(): m = Mock() m.__enter__ = Mock() m.__exit__ = Mock() t = task.TaskQueue() t._Mutex = m t.hasNext() m.__enter__.assert_called_once() m.__exit__.assert_called_once()
def test_ExecuteNext_LocksMutex(): t = task.TaskQueue() m = Mock() m.__enter__ = Mock() m.__exit__ = Mock() t._Mutex = m t.ExecuteNext() m.__enter__.assert_called() m.__exit__.assert_called()
def test_Add_LocksMutex(): m = Mock() m.__enter__ = Mock() m.__exit__ = Mock() t = task.TaskQueue() t._Mutex = m t.Add(lambda x: x, ('abc', )) m.__enter__.assert_called_once() m.__exit__.assert_called_once()
def test_ExecuteAll_twoExistingTasks(): t = task.TaskQueue() f = Mock() a = ('a', 'b') t._TaskList = [(f, a), (f, a)] numTasks = len(t._TaskList) t.ExecuteAll() f.assert_called_with('a', 'b') assert f.call_count == numTasks assert not t.hasNext()
def __init__(self, name, basedir, conf, queue=None, cmdQueue=None): """Initializes an empty project name = the name of the project basedir = the full (existing) base directory of the project queue = an optional shared task queue """ # The Update lock prevents multiple threads from updating values # in the same project. This probably has less impact on performance # than it sounds: Python is single-threaded at its core, and only # emulates multithreading. Also: this would only be a problem if # updating values & scheduling tasks is the rate-limiting step. self.updateLock = threading.RLock() self.conf = conf self.name = name self.basedir = basedir if not os.path.exists(self.basedir): os.mkdir(self.basedir) log.debug("Creating project %s" % name) if queue is None: log.debug("Creating new task queue %s" % name) self.queue = task.TaskQueue() else: self.queue = queue self.cmdQueue = cmdQueue # the file list self.fileList = value.FileList(basedir) # create the active network (the top-level network) self.network = active_network.ActiveNetwork(self, None, self.queue, "", self.updateLock) # now take care of imports. First get the import path self.topLevelImport = lib.ImportLibrary("", "", self.network) # create a list of function definitions self.functions = dict() # create a list of already performed imports self.imports = lib.ImportList() # and this is where we can start importing builtins, etc. self.inputDir = os.path.join(self.basedir, "_inputs") if not os.path.exists(self.inputDir): os.mkdir(self.inputDir) self.inputNr = 0 # a list of scheduled changes and its lock self.transactionStackLock = threading.Lock() tl = transaction.Transaction(self, None, self.network, self.topLevelImport) self.transactionStack = [tl]
req = { "req": "hub.set", "product": productUID, "host": host, "mode": "continuous", "outbound": dataUplinkPeriodMinutes, "inbound": dataDownlinkPeriodMinutes, "sync": True, "align": True } card.Transaction(req) commandTasks = task.TaskQueue() CM.SetSubmitTaskFn(commandTasks.Add) AttnFired = False def startMainLoop(): global AttnFired #Infinite loop that processes tasks while True: if AttnFired: info = attn.QueryTriggerSource(card) attn.ProcessAttnInfo(card, info) attn.Arm(card) AttnFired = False
def test_constructor_hasDefaultProperties(): t = task.TaskQueue() assert t is not None assert len(t._TaskList) == 0
def test_Next_noTasksInQueue(): t = task.TaskQueue() assert t.Next() is None
def test_hasNext_oneTaskInQueue(): t = task.TaskQueue() t._TaskList = [('abc', )] assert t.hasNext()
def test_hasNext_noTasksInQueue(): t = task.TaskQueue() assert not t.hasNext()