def test_header(self): """Test for the ScriptHeader class.""" header = scriptcomposer.ScriptHeader(shebang="#!/bin/sh", scheduler_headers=[ '# FOO', '# BAR', ]) self.assertEqual(header.get_lines(), ['#!/bin/sh', '# FOO', '# BAR'])
def test_scriptComposer(self): """Testing ScriptComposer class variable setting.""" # Testing valid uses. # Testing initialization defaults. composer = scriptcomposer.ScriptComposer() self.assertEqual(composer.header.shebang, '#!/bin/bash') self.assertEqual(composer.header.scheduler_headers, []) # Testing individual assignment test_header_shell = "/usr/env/python" test_header_scheduler = OrderedDict() test_header_scheduler['-G'] = 'pam' test_header_scheduler['-N'] = 'fam' composer.newline() composer.command(['taco', 'burrito', 'nachos']) test_details_path = 'testPath' test_details_group = 'groupies' test_details_perms = 0o543 composer.header.shebang = test_header_shell composer.header.scheduler_headers = test_header_scheduler self.assertEqual(composer.header.shebang, test_header_shell) self.assertEqual(composer.header.scheduler_headers, test_header_scheduler) composer = scriptcomposer.ScriptComposer() self.assertEqual(composer.header.shebang, '#!/bin/bash') self.assertEqual(composer.header.scheduler_headers, []) # Testing object assignment. header = scriptcomposer.ScriptHeader( shebang=test_header_shell, scheduler_headers=test_header_scheduler) composer.header = header self.assertEqual(composer.header.shebang, test_header_shell) self.assertEqual(composer.header.scheduler_headers, test_header_scheduler)
def _get_kickoff_script_header(self, test): # Unused in the base class del test return scriptcomposer.ScriptHeader()
def test_header( self ): """Test for the ScriptHeader class.""" testHeader = scriptcomposer.ScriptHeader() # Testing valid use cases. # Testing initialization. self.assertIsNone( testHeader.shell_path ) self.assertIsNone( testHeader.scheduler_macros ) # Testing individual assignment. testPath = "/bin/bash" testHeader.shell_path = testPath self.assertEqual( testHeader.shell_path, testPath ) testSched = OrderedDict() testSched[ '-G' ] = "12" testSched[ '-L' ] = "testThing" testHeader.scheduler_macros = testSched self.assertEqual( testHeader.scheduler_macros, testSched ) # Testing reset functionality. testHeader.reset() self.assertEqual(scriptcomposer.ScriptHeader().shell_path, testHeader.shell_path) self.assertEqual(scriptcomposer.ScriptHeader().scheduler_macros, testHeader.scheduler_macros) self.assertIsNone( testHeader.shell_path ) self.assertIsNone( testHeader.scheduler_macros ) # Testing initialization assignment. testPath = "/usr/env/python" testSched = OrderedDict() testSched[ "-g" ] = "9" testSched[ "-m" ] = "testThing" testHeader = scriptcomposer.ScriptHeader(shell_path=testPath, scheduler_macros=testSched) self.assertEqual( testHeader.shell_path, testPath ) self.assertEqual( testHeader.scheduler_macros, testSched ) testHeader.reset() # Testing invalid use cases. with self.assertRaises( TypeError ): testHeader.shell_path = 7 with self.assertRaises( TypeError ): testHeader.scheduler_macros = [ '-G 12', '-L testThing' ] with self.assertRaises( TypeError ): testHeader = scriptcomposer.ScriptHeader(shell_path=7, scheduler_macros=testSched ) with self.assertRaises( TypeError ): testHeader = scriptcomposer.ScriptHeader(shell_path=testPath, scheduler_macros=[ '-G 12', '-L testThing' ]) with self.assertRaises( TypeError ): testHeader = scriptcomposer.ScriptHeader(shell_path=12, scheduler_macros=13)
def test_scriptComposer( self ): """Testing ScriptComposer class variable setting.""" # Testing valid uses. # Testing initialization defaults. testComposer = scriptcomposer.ScriptComposer() self.assertIsInstance(testComposer.header, scriptcomposer.ScriptHeader) self.assertIsInstance(testComposer.body, scriptcomposer.ScriptBody) self.assertIsNone( testComposer.header.shell_path ) self.assertIsNone( testComposer.header.scheduler_macros ) self.assertEqual(testComposer.body.script_type, "bash") self.assertEqual(testComposer.body.user, os.environ['USER']) self.assertEqual(testComposer.body.group, os.environ['USER']) self.assertEqual(testComposer.body.owner_perms, 7) self.assertEqual(testComposer.body.group_perms, 5) self.assertEqual(testComposer.body.world_perms, 0) # Testing individual assignment testHeaderShell = "/usr/env/python" testHeaderScheduler = OrderedDict() testHeaderScheduler[ '-G' ] = 'pam' testHeaderScheduler[ '-N' ] = 'fam' testComposer.newline() testComposer.command(['taco', 'burrito', 'nachos']) testDetailsName = 'testName' testDetailsType = 'batch' testDetailsUser = '******' testDetailsGroup = 'groupies' testDetailsOP = 1 testDetailsGP = 2 testDetailsWP = 3 testComposer.header.shell_path = testHeaderShell testComposer.header.scheduler_macros = testHeaderScheduler testComposer.body.name = testDetailsName testComposer.body.script_type = testDetailsType testComposer.body.user = testDetailsUser testComposer.body.group = testDetailsGroup testComposer.body.owner_perms = testDetailsOP testComposer.body.group_perms = testDetailsGP testComposer.body.world_perms = testDetailsWP self.assertEqual( testComposer.header.shell_path, testHeaderShell ) self.assertEqual( testComposer.header.scheduler_macros, testHeaderScheduler ) self.assertEqual(testComposer.body.name, testDetailsName) self.assertEqual(testComposer.body.script_type, testDetailsType) self.assertEqual(testComposer.body.user, testDetailsUser) self.assertEqual(testComposer.body.group, testDetailsGroup) self.assertEqual(testComposer.body.owner_perms, testDetailsOP) self.assertEqual(testComposer.body.group_perms, testDetailsGP) self.assertEqual(testComposer.body.world_perms, testDetailsWP) # Testing reset. testComposer.reset() self.assertIsNone( testComposer.header.shell_path ) self.assertIsNone( testComposer.header.scheduler_macros ) self.assertEqual(testComposer.body.script_type, "bash") self.assertEqual(testComposer.body.user, os.environ['USER']) self.assertEqual(testComposer.body.group, os.environ['USER']) self.assertEqual(testComposer.body.owner_perms, 7) self.assertEqual(testComposer.body.group_perms, 5) self.assertEqual(testComposer.body.world_perms, 0) # Testing object assignment. testHeaderObj = scriptcomposer.ScriptHeader(shell_path=testHeaderShell, scheduler_macros= testHeaderScheduler) testDetailsObj = scriptcomposer.ScriptBody(name=testDetailsName, script_type= testDetailsType, user=testDetailsUser, group=testDetailsGroup, owner_perms= testDetailsOP, group_perms= testDetailsGP, world_perms= testDetailsWP) testComposer.header = testHeaderObj testComposer.body = testDetailsObj self.assertEqual( testComposer.header.shell_path, testHeaderShell ) self.assertEqual( testComposer.header.scheduler_macros, testHeaderScheduler ) self.assertEqual(testComposer.body.name, testDetailsName) self.assertEqual(testComposer.body.script_type, testDetailsType) self.assertEqual(testComposer.body.user, testDetailsUser) self.assertEqual(testComposer.body.group, testDetailsGroup) self.assertEqual(testComposer.body.owner_perms, testDetailsOP) self.assertEqual(testComposer.body.group_perms, testDetailsGP) self.assertEqual(testComposer.body.world_perms, testDetailsWP)
def test_scriptComposer(self): """Testing ScriptComposer class variable setting.""" # Testing valid uses. # Testing initialization defaults. composer = scriptcomposer.ScriptComposer() self.assertIsInstance(composer.header, scriptcomposer.ScriptHeader) self.assertIsInstance(composer.details, scriptcomposer.ScriptDetails) self.assertEqual(composer.header.shell_path, '#!/bin/bash') self.assertEqual(composer.header.scheduler_headers, []) self.assertEqual(composer.details.group, utils.get_login()) self.assertEqual(composer.details.perms, oct(0o770)) # Testing individual assignment test_header_shell = "/usr/env/python" test_header_scheduler = OrderedDict() test_header_scheduler['-G'] = 'pam' test_header_scheduler['-N'] = 'fam' composer.newline() composer.command(['taco', 'burrito', 'nachos']) test_details_path = 'testPath' test_details_group = 'groupies' test_details_perms = 0o543 composer.header.shell_path = test_header_shell composer.header.scheduler_headers = test_header_scheduler composer.details.path = test_details_path composer.details.group = test_details_group composer.details.perms = test_details_perms self.assertEqual(composer.header.shell_path, test_header_shell) self.assertEqual(composer.header.scheduler_headers, test_header_scheduler) self.assertEqual(composer.details.path, Path(test_details_path)) self.assertEqual(composer.details.group, test_details_group) self.assertEqual(composer.details.perms, oct(test_details_perms)) composer = scriptcomposer.ScriptComposer() self.assertEqual(composer.header.shell_path, '#!/bin/bash') self.assertEqual(composer.header.scheduler_headers, []) self.assertEqual(composer.details.group, utils.get_login()) self.assertEqual(composer.details.perms, oct(0o770)) # Testing object assignment. header = scriptcomposer.ScriptHeader( shell_path=test_header_shell, scheduler_headers=test_header_scheduler) testDetailsObj = scriptcomposer.ScriptDetails(path=test_details_path, group=test_details_group, perms=test_details_perms) composer.header = header composer.details = testDetailsObj self.assertEqual(composer.header.shell_path, test_header_shell) self.assertEqual(composer.header.scheduler_headers, test_header_scheduler) self.assertEqual(composer.details.path, Path(test_details_path)) self.assertEqual(composer.details.group, test_details_group) self.assertEqual(composer.details.perms, oct(test_details_perms))