def start_handler(self, data_queues, task_queue): main_logger.info("Starting TaskHandler") handler = TaskHandler(data_queues, task_queue) handler.daemon = True handler.start() self.threads.append({'name': 'TaskHandler', 'thread': handler}) return handler
def setup_method(self): """ Setup any state tied to the execution of the given method in a class. setup_method is invoked for every test method of a class. :return: """ self.task_handler = TaskHandler(self.data_queues, self.task_queue) self.task_handler.daemon = True self.task_handler.start() self.task_queue.added_item = None
class TestClass(object): """ TestClass Test the TaskHandler object """ db_connection = None def setup_class(self): """ Setup the class state for pytest :return: """ self.project_dir = os.path.dirname( os.path.dirname(os.path.abspath(__file__))) self.data_queues = data_queues.data_queues self.scheduledtasks = self.data_queues["scheduledtasks"] self.inotifytasks = self.data_queues["inotifytasks"] self.progress_reports = self.data_queues["progress_reports"] self.task_queue = mock_jobqueue_class.MockJobQueue() self.task_handler = None # Create temp config path config_path = tempfile.mkdtemp(prefix='unmanic_tests_') # Create connection to a test DB from unmanic.libs import unmodels app_dir = os.path.dirname(os.path.abspath(__file__)) database_settings = { "TYPE": "SQLITE", "FILE": ':memory:', "MIGRATIONS_DIR": os.path.join(app_dir, 'migrations'), } self.db_connection = unmodels.Database.select_database( database_settings) # Create required tables self.db_connection.create_tables([Settings, Tasks]) # import config from unmanic import config self.settings = config.CONFIG(config_path=config_path, db_connection=self.db_connection) self.settings.set_config_item('debugging', True, save_settings=False) def teardown_class(self): """ Teardown any state that was previously setup with a call to setup_class. :return: """ pass def setup_method(self): """ Setup any state tied to the execution of the given method in a class. setup_method is invoked for every test method of a class. :return: """ self.task_handler = TaskHandler(self.data_queues, self.settings, self.task_queue) self.task_handler.daemon = True self.task_handler.start() self.task_queue.added_item = None def teardown_method(self): """ Teardown any state that was previously setup with a setup_method call. :return: """ self.task_handler.stop() self.task_handler.join() @pytest.mark.integrationtest def test_task_handler_runs_as_a_thread(self): assert self.task_handler.is_alive() @pytest.mark.integrationtest def test_task_handler_thread_can_stop_in_less_than_one_second(self): self.task_handler.stop() time.sleep(1) assert not self.task_handler.is_alive() @pytest.mark.integrationtest @pytest.mark.skip( reason= "This test needs to be re-written to work with the TaskHandler DB integration" ) def test_task_handler_can_process_scheduled_tasks_queue(self): test_path_string = 'scheduledtasks' self.scheduledtasks.put(test_path_string) self.task_handler.process_scheduledtasks_queue() assert (test_path_string == self.task_queue.added_item) @pytest.mark.integrationtest @pytest.mark.skip( reason= "This test needs to be re-written to work with the TaskHandler DB integration" ) def test_task_handler_can_process_inotify_tasks_queue(self): test_path_string = '/tests/support_/videos/small/big_buck_bunny_144p_1mb.3gp' self.inotifytasks.put(test_path_string) self.task_handler.process_inotifytasks_queue() assert (test_path_string == self.task_queue.added_item)
def check_if_task_exists_matching_path(abspath): from unmanic.libs.taskhandler import TaskHandler if TaskHandler.check_if_task_exists_matching_path(abspath): return True return False
class TestClass(object): """ TestClass Test the TaskHandler object """ def setup_class(self): """ Setup the class state for pytest :return: """ self.project_dir = os.path.dirname( os.path.dirname(os.path.abspath(__file__))) self.data_queues = data_queues.data_queues self.scheduledtasks = self.data_queues["scheduledtasks"] self.inotifytasks = self.data_queues["inotifytasks"] self.progress_reports = self.data_queues["progress_reports"] #self.settings = mock_config_class.MockConfig() self.task_queue = mock_jobqueue_class.MockJobQueue() self.task_handler = None # import config from unmanic import config self.settings = config.CONFIG( os.path.join(tempfile.mkdtemp(), 'unmanic_test.db')) self.settings.DEBUGGING = True def teardown_class(self): """ Teardown any state that was previously setup with a call to setup_class. :return: """ pass def setup_method(self): """ Setup any state tied to the execution of the given method in a class. setup_method is invoked for every test method of a class. :return: """ self.task_handler = TaskHandler(self.data_queues, self.settings, self.task_queue) self.task_handler.daemon = True self.task_handler.start() self.task_queue.added_item = None def teardown_method(self): """ Teardown any state that was previously setup with a setup_method call. :return: """ self.task_handler.stop() self.task_handler.join() @pytest.mark.integrationtest def test_task_handler_runs_as_a_thread(self): assert self.task_handler.is_alive() @pytest.mark.integrationtest def test_task_handler_thread_can_stop_in_less_than_one_second(self): self.task_handler.stop() time.sleep(1) assert not self.task_handler.is_alive() @pytest.mark.integrationtest @pytest.mark.skip( reason= "This test needs to be re-written to work with the TaskHandler DB integration" ) def test_task_handler_can_process_scheduled_tasks_queue(self): test_path_string = 'scheduledtasks' self.scheduledtasks.put(test_path_string) self.task_handler.process_scheduledtasks_queue() assert (test_path_string == self.task_queue.added_item) @pytest.mark.integrationtest @pytest.mark.skip( reason= "This test needs to be re-written to work with the TaskHandler DB integration" ) def test_task_handler_can_process_inotify_tasks_queue(self): test_path_string = '/tests/support_/videos/small/big_buck_bunny_144p_1mb.3gp' self.inotifytasks.put(test_path_string) self.task_handler.process_inotifytasks_queue() assert (test_path_string == self.task_queue.added_item)