Example #1
0
 def test_error_none_set(self):
     """
     If neither ``extract_fn`` and ``property`` are defined,
     ``SetPropertyFromCommandNewStyle`` reports a config error.
     """
     with self.assertRaises(config.ConfigErrors):
         shell.SetPropertyFromCommandNewStyle(command=["echo", "value"])
Example #2
0
 def test_error_both_set(self):
     """
     If both ``extract_fn`` and ``property`` are defined,
     ``SetPropertyFromCommandNewStyle`` reports a config error.
     """
     with self.assertRaises(config.ConfigErrors):
         shell.SetPropertyFromCommandNewStyle(
             command=["echo", "value"],
             property="propname",
             extract_fn=lambda x: {"propname": "hello"})
Example #3
0
 def test_run_failure(self):
     self.setupStep(
         shell.SetPropertyFromCommandNewStyle(property="res",
                                              command="blarg"))
     self.expectCommands(
         ExpectShell(workdir='wkdir', 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()
Example #4
0
 def test_run_property(self):
     self.setupStep(
         shell.SetPropertyFromCommandNewStyle(property="res",
                                              command="cmd"))
     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", "abcdef")  # note: stripped
     self.expectLogfile('property changes', r"res: " + repr('abcdef'))
     return self.runStep()
Example #5
0
    def test_run_extract_fn_exception(self):
        def extract_fn(rc, stdout, stderr):
            raise RuntimeError("oh noes")

        self.setupStep(
            shell.SetPropertyFromCommandNewStyle(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)")
        yield self.runStep()
        self.assertEqual(len(self.flushLoggedErrors(RuntimeError)), 1)
Example #6
0
    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.SetPropertyFromCommandNewStyle(extract_fn=extract_fn,
                                                 command="cmd"))
        self.expectCommands(ExpectShell(workdir='wkdir', command="cmd") + 3)
        # note that extract_fn *is* called anyway, but returns no properties
        self.expectOutcome(result=FAILURE, state_string="'cmd' (failure)")
        return self.runStep()
Example #7
0
    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.SetPropertyFromCommandNewStyle(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()
Example #8
0
    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.setupStep(
            shell.SetPropertyFromCommandNewStyle(extract_fn=extract_fn,
                                                 command="cmd"))
        self.expectCommands(
            ExpectShell(workdir='wkdir', command="cmd") +
            ExpectShell.log('stdio', stdout='start', stderr='START') +
            ExpectShell.log('stdio', stdout='end') +
            ExpectShell.log('stdio', stderr='END') + 0)
        self.expectOutcome(result=SUCCESS, state_string="2 properties set")
        self.expectLogfile('property changes', 'a: 1\nb: 2')
        self.expectProperty("a", 1)
        self.expectProperty("b", 2)
        return self.runStep()
Example #9
0
 def test_constructor_conflict(self):
     with self.assertRaises(config.ConfigErrors):
         shell.SetPropertyFromCommandNewStyle(property='foo',
                                              extract_fn=lambda: None)