<s> import os <EOL> import types <EOL> from focus import errors <EOL> from focus . plugin import registration <EOL> from focus . plugin . modules import tasks as plugins <EOL> from focus_unittest import FocusTestCase , MockEnvironment , MockPlugin <EOL> _TASK_FILE_DATA = """<STR_LIT>""" <EOL> class TestTaskStart ( FocusTestCase ) : <EOL> class ParsedArgs ( object ) : <EOL> pass <EOL> def setUp ( self ) : <EOL> super ( TestTaskStart , self ) . setUp ( ) <EOL> self . env = MockEnvironment ( ) <EOL> self . plugin = plugins . TaskStart ( ) <EOL> def tearDown ( self ) : <EOL> self . plugin = None <EOL> self . env = None <EOL> super ( TestTaskStart , self ) . tearDown ( ) <EOL> def test__execute ( self ) : <EOL> """<STR_LIT>""" <EOL> args = self . ParsedArgs ( ) <EOL> args . task_name = '<STR_LIT>' <EOL> self . plugin . execute ( self . env , args ) <EOL> self . assertEqual ( self . env . io . test__success_data , '<STR_LIT>' ) <EOL> self . assertTrue ( self . env . task . _loaded ) <EOL> class TestTaskStop ( FocusTestCase ) : <EOL> class ParsedArgs ( object ) : <EOL> pass <EOL> def setUp ( self ) : <EOL> super ( TestTaskStop , self ) . setUp ( ) <EOL> self . env = MockEnvironment ( ) <EOL> self . plugin = plugins . TaskStop ( ) <EOL> def tearDown ( self ) : <EOL> self . plugin = None <EOL> self . env = None <EOL> super ( TestTaskStop , self ) . tearDown ( ) <EOL> def test__execute ( self ) : <EOL> """<STR_LIT>""" <EOL> self . env . task . _loaded = True <EOL> self . plugin . execute ( self . env , self . ParsedArgs ( ) ) <EOL> self . assertFalse ( self . env . task . _loaded ) <EOL> class TestTaskCreate ( FocusTestCase ) : <EOL> class ParsedArgs ( object ) : <EOL> skip_edit = True <EOL> clone_task = None <EOL> def setUp ( self ) : <EOL> super ( TestTaskCreate , self ) . setUp ( ) <EOL> self . env = MockEnvironment ( ) <EOL> self . plugin = plugins . TaskCreate ( ) <EOL> def tearDown ( self ) : <EOL> self . plugin = None <EOL> self . env = None <EOL> super ( TestTaskCreate , self ) . tearDown ( ) <EOL> def test__execute ( self ) : <EOL> """<STR_LIT>""" <EOL> args = self . ParsedArgs ( ) <EOL> args . task_name = '<STR_LIT>' <EOL> self . plugin . execute ( self . env , args ) <EOL> self . assertEqual ( self . env . task . test__created [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> with self . assertRaises ( errors . TaskExists ) : <EOL> self . plugin . execute ( self . env , args ) <EOL> args . task_name = '<STR_LIT>' <EOL> args . clone_task = '<STR_LIT>' <EOL> self . plugin . execute ( self . env , args ) <EOL> self . assertEqual ( self . env . task . test__created [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEqual ( self . env . task . test__created [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> class TestTaskEdit ( FocusTestCase ) : <EOL> class ParsedArgs ( object ) : <EOL> task_name = None <EOL> def setUp ( self ) : <EOL> super ( TestTaskEdit , self ) . setUp ( ) <EOL> self . plugin = plugins . TaskEdit ( ) <EOL> self . env = MockEnvironment ( ) <EOL> if '<STR_LIT>' in os . environ : <EOL> self . old_editor = os . environ [ '<STR_LIT>' ] <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . setup_dir ( ) <EOL> self . env . task . _base_dir = self . test_dir <EOL> self . env . task . _task_dir = os . path . join ( self . test_dir , '<STR_LIT>' , '<STR_LIT:test>' ) <EOL> os . makedirs ( self . env . task . _task_dir ) <EOL> self . task_cfg = os . path . join ( self . env . task . _task_dir , '<STR_LIT>' ) <EOL> open ( self . task_cfg , '<STR_LIT:w>' , <NUM_LIT:0> ) . write ( _TASK_FILE_DATA ) <EOL> for k in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> registration . register ( '<STR_LIT>' , k , MockPlugin , { } ) <EOL> def tearDown ( self ) : <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> os . environ [ '<STR_LIT>' ] = self . old_editor <EOL> else : <EOL> del os . environ [ '<STR_LIT>' ] <EOL> self . plugin = None <EOL> self . env = None <EOL> registration . _option_hooks . clear ( ) <EOL> registration . _registered . clear ( ) <EOL> super ( TestTaskEdit , self ) . tearDown ( ) <EOL> def testExist__execute ( self ) : <EOL> """<STR_LIT>""" <EOL> args = self . ParsedArgs ( ) <EOL> args . task_name = '<STR_LIT:test>' <EOL> self . plugin . execute ( self . env , args ) <EOL> self . assertIsNone ( self . env . io . test__error_data ) <EOL> def testExistActiveTask__execute ( self ) : <EOL> """<STR_LIT>""" <EOL> self . env . task . name = '<STR_LIT:test>' <EOL> self . env . task . load ( ) <EOL> args = self . ParsedArgs ( ) <EOL> args . task_name = '<STR_LIT:test>' <EOL> with self . assertRaises ( errors . ActiveTask ) : <EOL> self . plugin . execute ( self . env , args ) <EOL> def testExistFailEdit__execute ( self ) : <EOL> """<STR_LIT>""" <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT:false>' <EOL> args = self . ParsedArgs ( ) <EOL> args . task_name = '<STR_LIT:test>' <EOL> with self . assertRaises ( errors . FocusError ) as cm : <EOL> self . plugin . execute ( self . env , args ) <EOL> output = cm . exception . description <EOL> self . assertRegexpMatches ( output , r'<STR_LIT>' ) <EOL> def testNoExistTask__execute ( self ) : <EOL> """<STR_LIT>""" <EOL> args = self . ParsedArgs ( ) <EOL> args . task_name = '<STR_LIT>' <EOL> with self . assertRaises ( errors . TaskNotFound ) : <EOL> self . plugin . execute ( self . env , args ) <EOL> class TestTaskRename ( FocusTestCase ) : <EOL> class ParsedArgs ( object ) : <EOL> old_task_name = None <EOL> new_task_name = None <EOL> def setUp ( self ) : <EOL> super ( TestTaskRename , self ) . setUp ( ) <EOL> self . plugin = plugins . TaskRename ( ) <EOL> self . env = MockEnvironment ( ) <EOL> self . setup_dir ( ) <EOL> self . env . task . _base_dir = self . test_dir <EOL> self . env . task . _task_dir = os . path . join ( self . test_dir , '<STR_LIT>' , '<STR_LIT:test>' ) <EOL> os . makedirs ( self . env . task . _task_dir ) <EOL> def tearDown ( self ) : <EOL> self . env = None <EOL> self . plugin = None <EOL> super ( TestTaskRename , self ) . tearDown ( ) <EOL> def test__execute ( self ) : <EOL> """<STR_LIT>""" <EOL> self . env . task . test__renamed = dict ( test = True , test2 = True ) <EOL> args = self . ParsedArgs ( ) <EOL> args . old_task_name = '<STR_LIT:test>' <EOL> args . new_task_name = '<STR_LIT>' <EOL> with self . assertRaises ( errors . TaskExists ) : <EOL> self . plugin . execute ( self . env , args ) <EOL> args . new_task_name = '<STR_LIT>' <EOL> self . plugin . execute ( self . env , args ) <EOL> self . assertIn ( '<STR_LIT>' , self . env . task . test__renamed ) <EOL> self . assertNotIn ( '<STR_LIT:test>' , self . env . task . test__renamed ) <EOL> with self . assertRaises ( errors . TaskNotFound ) : <EOL> self . plugin . execute ( self . env , args ) <EOL> args . old_task_name = '<STR_LIT>' <EOL> with self . assertRaises ( errors . FocusError ) as cm : <EOL> self . plugin . execute ( self . env , args ) <EOL> output = cm . exception . description <EOL> self . assertEqual ( output , u'<STR_LIT>' ) <EOL> class TestTaskRemove ( FocusTestCase ) : <EOL> class ParsedArgs ( object ) : <EOL> task_name = None <EOL> force = False <EOL> def setUp ( self ) : <EOL> super ( TestTaskRemove , self ) . setUp ( ) <EOL> self . plugin = plugins . TaskRemove ( ) <EOL> self . env = MockEnvironment ( ) <EOL> self . setup_dir ( ) <EOL> self . env . task . _base_dir = self . test_dir <EOL> self . env . task . _task_dir = os . path . join ( self . test_dir , '<STR_LIT>' , '<STR_LIT:test>' ) <EOL> os . makedirs ( self . env . task . _task_dir ) <EOL> def tearDown ( self ) : <EOL> self . env = None <EOL> self . plugin = None <EOL> super ( TestTaskRemove , self ) . tearDown ( ) <EOL> def testExists__execute ( self ) : <EOL> """<STR_LIT>""" <EOL> args = self . ParsedArgs ( ) <EOL> args . task_name = '<STR_LIT:test>' <EOL> args . force = True <EOL> self . plugin . execute ( self . env , args ) <EOL> self . assertFalse ( self . env . task . exists ( '<STR_LIT:test>' ) ) <EOL> def testNoExist__execute ( self ) : <EOL> """<STR_LIT>""" <EOL> args = self . ParsedArgs ( ) <EOL> args . task_name = '<STR_LIT>' <EOL> with self . assertRaises ( errors . TaskNotFound ) : <EOL> self . plugin . execute ( self . env , args ) <EOL> def testExistActiveTask__execute ( self ) : <EOL> """<STR_LIT>""" <EOL> self . env . task . name = '<STR_LIT:test>' <EOL> self . env . task . load ( ) <EOL> args = self . ParsedArgs ( ) <EOL> args . task_name = '<STR_LIT:test>' <EOL> with self . assertRaises ( errors . ActiveTask ) : <EOL> self . plugin . execute ( self . env , args ) <EOL> class TestTaskList ( FocusTestCase ) : <EOL> class ParsedArgs ( object ) : <EOL> verbose = False <EOL> def setUp ( self ) : <EOL> super ( TestTaskList , self ) . setUp ( ) <EOL> self . env = MockEnvironment ( ) <EOL> self . plugin = plugins . TaskList ( ) <EOL> def tearDown ( self ) : <EOL> self . plugin = None <EOL> self . env = None <EOL> super ( TestTaskList , self ) . tearDown ( ) <EOL> def testVerbose__execute ( self ) : <EOL> """<STR_LIT>""" <EOL> args = self . ParsedArgs ( ) <EOL> args . verbose = True <EOL> self . plugin . execute ( self . env , args ) <EOL> output = self . env . io . test__write_data <EOL> for name in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . assertRegexpMatches ( output , name ) <EOL> def testNonVerbose__execute ( self ) : <EOL> """<STR_LIT>""" <EOL> args = self . ParsedArgs ( ) <EOL> args . verbose = False <EOL> self . plugin . execute ( self . env , args ) <EOL> output = self . env . io . test__write_data <EOL> self . assertEqual ( output , '<STR_LIT>' ) <EOL> def testNoTasks__execute ( self ) : <EOL> """<STR_LIT>""" <EOL> self . env . task . get_list_info = types . MethodType ( lambda name : [ ] , <EOL> self . env . task ) <EOL> self . plugin . execute ( self . env , self . ParsedArgs ( ) ) <EOL> self . assertEqual ( self . env . io . test__write_data , '<STR_LIT>' ) <EOL> class TestTaskView ( FocusTestCase ) : <EOL> class ParsedArgs ( object ) : <EOL> task_name = None <EOL> def setUp ( self ) : <EOL> super ( TestTaskView , self ) . setUp ( ) <EOL> self . env = MockEnvironment ( ) <EOL> self . plugin = plugins . TaskView ( ) <EOL> def tearDown ( self ) : <EOL> self . plugin = None <EOL> self . env = None <EOL> super ( TestTaskView , self ) . tearDown ( ) <EOL> def testTaskName__execute ( self ) : <EOL> """<STR_LIT>""" <EOL> args = self . ParsedArgs ( ) <EOL> args . task_name = '<STR_LIT>' <EOL> self . plugin . execute ( self . env , args ) <EOL> output = self . env . io . test__write_data <EOL> self . assertRegexpMatches ( output , r'<STR_LIT>' ) <EOL> def testNotActive__execute ( self ) : <EOL> """<STR_LIT>""" <EOL> args = self . ParsedArgs ( ) <EOL> args . task_name = None <EOL> self . assertFalse ( self . env . task . active ) <EOL> with self . assertRaises ( errors . NoActiveTask ) : <EOL> self . plugin . execute ( self . env , args ) <EOL> def testActive__execute ( self ) : <EOL> """<STR_LIT>""" <EOL> args = self . ParsedArgs ( ) <EOL> args . task_name = None <EOL> self . env . task . load ( ) <EOL> self . env . task . name = '<STR_LIT>' <EOL> self . assertTrue ( self . env . task . active ) <EOL> self . plugin . execute ( self . env , args ) <EOL> output = self . env . io . test__write_data <EOL> self . assertRegexpMatches ( output , r'<STR_LIT>' ) </s>
