<s> from __future__ import absolute_import <EOL> import mock <EOL> from nose . tools import assert_raises <EOL> from . import scheduler <EOL> from . config import config_value <EOL> from . job import Job <EOL> from . webapp import app <EOL> from digits . utils import subclass , override <EOL> class TestScheduler ( ) : <EOL> def get_scheduler ( self ) : <EOL> return scheduler . Scheduler ( config_value ( '<STR_LIT>' ) ) <EOL> def test_add_before_start ( self ) : <EOL> s = self . get_scheduler ( ) <EOL> assert not s . add_job ( None ) , '<STR_LIT>' <EOL> def test_start_twice ( self ) : <EOL> s = self . get_scheduler ( ) <EOL> assert s . start ( ) , '<STR_LIT>' <EOL> assert s . start ( ) , '<STR_LIT>' <EOL> assert s . stop ( ) , '<STR_LIT>' <EOL> def test_stop_before_start ( self ) : <EOL> s = self . get_scheduler ( ) <EOL> assert s . stop ( ) , '<STR_LIT>' <EOL> @ subclass <EOL> class JobForTesting ( Job ) : <EOL> @ override <EOL> def job_type ( self ) : <EOL> return '<STR_LIT>' <EOL> class TestSchedulerFlow ( ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> cls . s = scheduler . Scheduler ( config_value ( '<STR_LIT>' ) ) <EOL> assert cls . s . start ( ) , '<STR_LIT>' <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> assert cls . s . stop ( ) , '<STR_LIT>' <EOL> def test_add_remove_job ( self ) : <EOL> with app . test_request_context ( ) : <EOL> job = JobForTesting ( name = '<STR_LIT>' , username = '<STR_LIT>' ) <EOL> assert self . s . add_job ( job ) , '<STR_LIT>' <EOL> assert len ( self . s . jobs ) == <NUM_LIT:1> , '<STR_LIT>' % len ( self . s . jobs ) <EOL> assert self . s . delete_job ( job ) , '<STR_LIT>' <EOL> assert len ( self . s . jobs ) == <NUM_LIT:0> , '<STR_LIT>' % len ( self . s . jobs ) </s>
