def test_renderable_workdir(self): self.setupStep( shell.SetPropertyFromCommand( property="res", command="cmd", workdir=properties.Interpolate('wkdir'))) self.expectCommands( ExpectShell(workdir='wkdir', usePTY='slave-config', command="cmd") + ExpectShell.log('stdio', stdout='\n\nabcdef\n') + 0) self.expectOutcome(result=SUCCESS, state_string="property 'res' set") self.expectProperty("res", "abcdef") # note: stripped self.expectLogfile('property changes', r"res: u'abcdef'") return self.runStep()
def test_run_extract_fn_cmdfail(self): def extract_fn(rc, stdout, stderr): self.assertEqual((rc, stdout, stderr), (3, '', '')) return dict(a=1, b=2) self.setupStep( shell.SetPropertyFromCommand(extract_fn=extract_fn, command="cmd")) self.expectCommands(ExpectShell(workdir='wkdir', command="cmd") + 3) # note that extract_fn *is* called anyway self.expectOutcome(result=FAILURE, state_string="2 properties set (failure)") self.expectLogfile('property changes', 'a: 1\nb: 2') return self.runStep()
def test_run_extract_fn_exception(self): def extract_fn(rc, stdout, stderr): raise RuntimeError("oh noes") self.setupStep( shell.SetPropertyFromCommand(extract_fn=extract_fn, command="cmd")) self.expectCommands(ExpectShell(workdir='wkdir', command="cmd") + 0) # note that extract_fn *is* called anyway, but returns no properties self.expectOutcome(result=EXCEPTION, state_string="'cmd' (exception)") d = self.runStep() d.addCallback(lambda _: self.assertEqual( len(self.flushLoggedErrors(RuntimeError)), 1)) return d
def test_run_extract_fn_cmdfail_empty(self): def extract_fn(rc, stdout, stderr): self.assertEqual((rc, stdout, stderr), (3, '', '')) return dict() self.setupStep( shell.SetPropertyFromCommand(extract_fn=extract_fn, command="cmd")) self.expectCommands( ExpectShell(workdir='wkdir', usePTY='slave-config', command="cmd") + 3) # note that extract_fn *is* called anyway, but returns no properties self.expectOutcome(result=FAILURE, status_text=["'cmd'", "failed"]) return self.runStep()
def test_run_failure(self): self.setupStep( shell.SetPropertyFromCommand(property="res", command="blarg")) self.expectCommands( ExpectShell(workdir='wkdir', usePTY='slave-config', command="blarg") + ExpectShell.log('stdio', stderr='cannot blarg: File not found') + 1 ) self.expectOutcome(result=FAILURE, state_string="'blarg' (failure)") self.expectNoProperty("res") return self.runStep()
def test_run_property_no_strip(self): self.setupStep( shell.SetPropertyFromCommand(property="res", command="cmd", strip=False)) self.expectCommands( ExpectShell(workdir='wkdir', command="cmd") + ExpectShell.log('stdio', stdout='\n\nabcdef\n') + 0) self.expectOutcome(result=SUCCESS, state_string="property 'res' set") self.expectProperty("res", "\n\nabcdef\n") self.expectLogfile('property changes', r"res: " + repr(u'\n\nabcdef\n')) return self.runStep()
def test_run_property_no_strip(self): self.setup_step( shell.SetPropertyFromCommand(property="res", command="cmd", strip=False)) self.expect_commands( ExpectShell(workdir='wkdir', command="cmd").stdout('\n\nabcdef\n').exit(0)) self.expect_outcome(result=SUCCESS, state_string="property 'res' set") self.expect_property("res", "\n\nabcdef\n") self.expect_log_file('property changes', r"res: " + repr('\n\nabcdef\n')) return self.run_step()
def test_renderable_workdir(self): self.setup_step( shell.SetPropertyFromCommand( property="res", command="cmd", workdir=properties.Interpolate('wkdir'))) self.expect_commands( ExpectShell(workdir='wkdir', command="cmd").stdout('\n\nabcdef\n').exit(0)) self.expect_outcome(result=SUCCESS, state_string="property 'res' set") self.expect_property("res", "abcdef") # note: stripped self.expect_log_file('property changes', r"res: " + repr('abcdef')) return self.run_step()
def test_run_property(self): self.setupStep(shell.SetPropertyFromCommand(property="res", command="cmd")) self.expectCommands( ExpectShell(workdir='wkdir', usePTY='slave-config', command="cmd") + ExpectShell.log('stdio', stdout='\n\nabcdef\n') + 0 ) self.expectOutcome(result=SUCCESS, status_text=["property 'res' set"]) self.expectProperty("res", "abcdef") # note: stripped self.expectLogfile('property changes', r"res: 'abcdef'") return self.runStep()
def test_run_extract_fn(self): def extract_fn(rc, stdout, stderr): self.assertEqual((rc, stdout, stderr), (0, 'startend\n', 'STARTEND\n')) return dict(a=1, b=2) self.setup_step( shell.SetPropertyFromCommand(extract_fn=extract_fn, command="cmd")) self.expect_commands( ExpectShell(workdir='wkdir', command="cmd").stdout('start').stderr( 'START').stdout('end').stderr('END').exit(0)) self.expect_outcome(result=SUCCESS, state_string="2 properties set") self.expect_log_file('property changes', 'a: 1\nb: 2') self.expect_property("a", 1) self.expect_property("b", 2) return self.run_step()
def test_run_extract_fn(self): def extract_fn(rc, stdout, stderr): self.assertEqual((rc, stdout, stderr), (0, 'startend', 'STARTEND')) return dict(a=1, b=2) self.setupStep( shell.SetPropertyFromCommand(extract_fn=extract_fn, command="cmd")) self.expectCommands( ExpectShell(workdir='wkdir', usePTY='slave-config', command="cmd") + ExpectShell.log('stdio', stdout='start', stderr='START') + ExpectShell.log('stdio', stdout='end') + ExpectShell.log('stdio', stderr='END') + 0) self.expectOutcome(result=SUCCESS, status_text=["2 properties set"]) self.expectLogfile('property changes', 'a: 1\nb: 2') self.expectProperty("a", 1) self.expectProperty("b", 2) return self.runStep()
def test_constructor_conflict(self): self.assertRaises( config.ConfigErrors, lambda: shell.SetPropertyFromCommand(property='foo', extract_fn=lambda: None))