# Path: fretwork/task.py
# class Task(object):
#     def __init__(self):
#         pass
# 
#     def started(self):
#         pass
# 
#     def stopped(self):
#         pass
# 
#     def run(self, ticks):
#         pass
# 
# Path: fretwork/task.py
# class TaskEngine(object):
#     def __init__(self, engine):
# 
#         self.engine = engine
# 
#         # self.tasks contains a list of dictionaries.
#         # each contain: task instance, synced or not, and paused or not
#         self.tasks = []
#         self.currentTask = None
# 
#     def checkTask(self, task):
#         '''Check if a task exists'''
# 
#         for taskData in self.tasks:
#             if taskData['task'] is task:
#                 return True
# 
#         return False
# 
#     def addTask(self, task, synced=True):
#         '''Add a task'''
# 
#         if not self.checkTask(task):
#             self.tasks.append({'task': task, 'synced': synced, 'paused': False})
#             task.started()
# 
#     def removeTask(self, task):
#         '''Remove a task'''
# 
#         for taskData in self.tasks:
#             if taskData['task'] is task:
#                 self.tasks.remove(taskData)
#                 task.stopped()
#                 break
# 
#     def pauseTask(self, task):
#         '''Pause a task'''
# 
#         for taskData in self.tasks:
#             if taskData['task'] is task:
#                 taskData['paused'] = True
#                 break
# 
#     def resumeTask(self, task):
#         '''Resume a paused task'''
# 
#         for taskData in self.tasks:
#             if taskData['task'] is task:
#                 taskData['paused'] = False
#                 break
# 
#     def runTask(self, task, tick=0):
#         self.currentTask = task
#         task.run(tick)
#         self.currentTask = None
# 
#     def exit(self):
#         '''Remove all tasks.'''
#         for taskData in list(self.tasks):
#             self.removeTask(taskData['task'])
# 
#     def run(self):
#         '''Run one cycle of the task scheduler engine.'''
#         if not self.tasks:
#             return False
# 
#         # Synced tasks
#         for taskData in self.tasks:
#             if taskData['paused'] or not taskData['synced']:
#                 continue
# 
#             self.runTask(taskData['task'], tick=self.engine.tickDelta)
# 
#         # Unsynced tasks
#         for taskData in self.tasks:
#             if taskData['paused'] or taskData['synced']:
#                 continue
# 
#             self.runTask(taskData['task'])
# 
#         return True


import unittest
from fretwork.task import Task
from fretwork.task import TaskEngine

    def test_checkTask(self):
        # no task
        no_task = "no task"
        self.assertFalse(self.task_engine.checkTask(no_task))  # no task

        # one task
        task = Task()
        self.task_engine.tasks.append({'task': task})
        self.assertTrue(self.task_engine.checkTask(task))  # one task

    def test_addTask(self):
        task = Tasker()
        self.task_engine.addTask(task)
        self.assertTrue(self.task_engine.checkTask(task))  # one task
        self.assertTrue(task.started)  # started

    def test_removeTask(self):
        # add one task
        task = Tasker()
        self.task_engine.addTask(task)
        self.assertTrue(self.task_engine.checkTask(task))  # one task
        self.assertTrue(task.started)  # started

        # remove the task
        self.task_engine.removeTask(task)
        self.assertFalse(self.task_engine.checkTask(task))  # no task
        self.assertFalse(task.started)  # stopped

    def test_pauseTask(self):

# Path: fretwork/task.py
# class Task(object):
#     def __init__(self):
#         pass
# 
#     def started(self):
#         pass
# 
#     def stopped(self):
#         pass
# 
#     def run(self, ticks):
#         pass
# 
# Path: fretwork/task.py
# class TaskEngine(object):
#     def __init__(self, engine):
# 
#         self.engine = engine
# 
#         # self.tasks contains a list of dictionaries.
#         # each contain: task instance, synced or not, and paused or not
#         self.tasks = []
#         self.currentTask = None
# 
#     def checkTask(self, task):
#         '''Check if a task exists'''
# 
#         for taskData in self.tasks:
#             if taskData['task'] is task:
#                 return True
# 
#         return False
# 
#     def addTask(self, task, synced=True):
#         '''Add a task'''
# 
#         if not self.checkTask(task):
#             self.tasks.append({'task': task, 'synced': synced, 'paused': False})
#             task.started()
# 
#     def removeTask(self, task):
#         '''Remove a task'''
# 
#         for taskData in self.tasks:
#             if taskData['task'] is task:
#                 self.tasks.remove(taskData)
#                 task.stopped()
#                 break
# 
#     def pauseTask(self, task):
#         '''Pause a task'''
# 
#         for taskData in self.tasks:
#             if taskData['task'] is task:
#                 taskData['paused'] = True
#                 break
# 
#     def resumeTask(self, task):
#         '''Resume a paused task'''
# 
#         for taskData in self.tasks:
#             if taskData['task'] is task:
#                 taskData['paused'] = False
#                 break
# 
#     def runTask(self, task, tick=0):
#         self.currentTask = task
#         task.run(tick)
#         self.currentTask = None
# 
#     def exit(self):
#         '''Remove all tasks.'''
#         for taskData in list(self.tasks):
#             self.removeTask(taskData['task'])
# 
#     def run(self):
#         '''Run one cycle of the task scheduler engine.'''
#         if not self.tasks:
#             return False
# 
#         # Synced tasks
#         for taskData in self.tasks:
#             if taskData['paused'] or not taskData['synced']:
#                 continue
# 
#             self.runTask(taskData['task'], tick=self.engine.tickDelta)
# 
#         # Unsynced tasks
#         for taskData in self.tasks:
#             if taskData['paused'] or taskData['synced']:
#                 continue
# 
#             self.runTask(taskData['task'])
# 
#         return True


# Path: tests/test_task.py
import unittest
from fretwork.task import Task
from fretwork.task import TaskEngine


    def test_checkTask(self):
        # no task
        no_task = "no task"
        self.assertFalse(self.task_engine.checkTask(no_task))  # no task

        # one task
        task = Task()
        self.task_engine.tasks.append({'task': task})
        self.assertTrue(self.task_engine.checkTask(task))  # one task

    def test_addTask(self):
        task = Tasker()
        self.task_engine.addTask(task)
        self.assertTrue(self.task_engine.checkTask(task))  # one task
        self.assertTrue(task.started)  # started

    def test_removeTask(self):
        # add one task
        task = Tasker()
        self.task_engine.addTask(task)
        self.assertTrue(self.task_engine.checkTask(task))  # one task
        self.assertTrue(task.started)  # started

        # remove the task
        self.task_engine.removeTask(task)
        self.assertFalse(self.task_engine.checkTask(task))  # no task
        self.assertFalse(task.started)  # stopped

    def test_pauseTask(self):

        task = Task()