def testMultipleSegments(self): result = FrameSet('57,1-3,4-2,12-15x2,76-70x-3,5-12y3,1-7:5') self.assertEqual([ 57, 1, 2, 3, 4, 3, 2, 12, 14, 76, 73, 70, 6, 7, 9, 10, 12, 1, 6, 2, 4, 3, 5, 7 ], result.getAll())
def testNormalize(self): reverseOrder = FrameSet('5,3-1x-1') reverseOrder.normalize() self.assertEqual([1, 2, 3, 5], reverseOrder.getAll()) duplicates = FrameSet('1-2,2-3') duplicates.normalize() self.assertEqual([1, 2, 3], duplicates.getAll())
def testShellScript(self, systemMock): """Test a custom shell script layer""" # The script will be copied into the session directory so we have to create a dummy # session to use. layerName = 'arbitrary-layer' with test_utils.TemporarySessionDirectory( ), tempfile.NamedTemporaryFile() as scriptFile: scriptContents = '# !/bin/sh\necho zoom zoom zoom' with open(scriptFile.name, 'w') as fp: fp.write(scriptContents) outln = Outline() outln.setup() expectedSessionPath = outln.get_session().put_file(scriptFile.name, layer=layerName, rename='script') shellScript = ShellScript(layerName, script=scriptFile.name) shellScript.set_outline(outln) shellScript._setup() shellScript._execute(FrameSet('5-6')) with open(expectedSessionPath) as fp: sessionScriptContents = fp.read() self.assertEqual(scriptContents, sessionScriptContents) systemMock.assert_has_calls( [mock.call(expectedSessionPath, frame=5)])
def testShell(self, systemMock): """Test a simple shell command.""" command = ['/bin/ls'] shell = Shell('bah', command=command) shell._execute(FrameSet('5-6')) systemMock.assert_has_calls([ mock.call(command, frame=5), mock.call(command, frame=6), ])
def testShellToString(self, systemMock): """Test a string shell command.""" command = '/bin/ls -l ./' shell = Shell('bah', command=command) shell._execute(FrameSet('5-6')) systemMock.assert_has_calls([ mock.call(command, frame=5), mock.call(command, frame=6), ])
def testShellSequence(self, systemMock): """Test a simple sequence of shell commands""" commandCount = 10 commands = ['/bin/echo %d' % (frame+1) for frame in range(commandCount)] shellSeq = ShellSequence('bah', commands=commands, cores=10, memory='512m') shellSeq._execute(FrameSet('5-6')) self.assertEqual('1-%d' % commandCount, shellSeq.get_frame_range()) systemMock.assert_has_calls([ mock.call('/bin/echo 5'), mock.call('/bin/echo 6'), ])
def testIndex(self): result = FrameSet('1-7') self.assertEqual(5, result.index(6)) self.assertEqual(-1, result.index(22))
def testGet(self): result = FrameSet('1-7') self.assertEqual(5, result.get(4))
def testSize(self): result = FrameSet('1-7') self.assertEqual(7, result.size())