示例#1
0
    def test_command_with_stdin(self):
        """Test that cli() can handle string input."""
        stdin = 'hi\nthere\n'
        subcommand = '{wc} -l | {grep} -q 2'.format(wc=shutil.which('wc'),
                                                    grep=shutil.which('grep'))

        operation = commandline.cli(command=['/bin/sh', '-c', subcommand],
                                    shell=False,
                                    stdin=stdin)
        assert operation.output.returncode.result() == 0
        operation = commandline.commandline_operation('/bin/sh',
                                                      ['-c', subcommand],
                                                      stdin=stdin)
        assert operation.output.returncode.result() == 0

        subcommand = '{wc} -l | {grep} -q 1'.format(wc=shutil.which('wc'),
                                                    grep=shutil.which('grep'))

        operation = commandline.cli(command=['/bin/sh', '-c', subcommand],
                                    shell=False,
                                    stdin=stdin)
        assert operation.output.returncode.result() != 0
        operation = commandline.commandline_operation('/bin/sh',
                                                      ['-c', subcommand],
                                                      stdin=stdin)
        assert operation.output.returncode.result() != 0
示例#2
0
 def test_false_explicit(self):
     """Test a command known to produce a return code of 1."""
     command = shutil.which('false')
     operation = commandline.cli(command=[command], shell=False)
     # Explicitly run the operation.
     operation.run()
     assert operation.output.returncode.result() == 1
示例#3
0
 def test_false_explicit(self):
     """Test a command known to produce a return code of 1."""
     command = shutil.which('false')
     operation = commandline.cli(command=[command], shell=False)
     # Explicitly run the operation.
     operation.run()
     assert operation.output.returncode.result() == 1
示例#4
0
    def test_true(self):
        """Test a command known to produce a return code of 0."""
        command = shutil.which('true')
        operation = commandline.cli(command=[command], shell=False)

        # Note: getitem not implemented.
        # assert 'stdout' in operation.output
        # assert 'stderr' in operation.output
        assert hasattr(operation.output, 'stdout')
        assert hasattr(operation.output, 'stderr')
        assert not hasattr(operation.output, 'erroroutput')
        assert hasattr(operation.output, 'returncode')

        operation.run()
        # assert operation.output.returncode.result() == 0
        assert operation.output.returncode.result() == 0
示例#5
0
    def test_true(self):
        """Test a command known to produce a return code of 0."""
        command = shutil.which('true')
        operation = commandline.cli(command=[command], shell=False)

        # Note: 'stdout' and 'stderr' not mapped.
        # Note: getitem not implemented.
        # assert not 'stdout' in operation.output
        # assert not 'stderr' in operation.output
        assert not hasattr(operation.output, 'stdout')
        assert not hasattr(operation.output, 'stderr')

        # Check for the attributes that we _do_ expect.
        assert hasattr(operation.output, 'erroroutput')
        assert hasattr(operation.output, 'returncode')

        operation.run()
        # assert operation.output.returncode.result() == 0
        assert operation.output.returncode.result() == 0
示例#6
0
 def test_command_with_arguments(self):
     """Test that cli() can wrap a command with arguments."""
     # TODO: (FR5+) do we want to pipeline or checkpoint stdout somehow?
     operation = commandline.cli(
         command=[shutil.which('echo'), 'hi', 'there'], shell=False)
     assert operation.output.returncode.result() == 0
示例#7
0
 def test_false_implicit(self):
     command = shutil.which('false')
     operation = commandline.cli(command=[command], shell=False)
     # Allow the operation to be executed implicitly to satisfy data constraint.
     assert operation.output.returncode.result() == 1
示例#8
0
 def test_command_with_arguments(self):
     """Test that cli() can wrap a command with arguments."""
     # TODO: (FR5+) do we want to pipeline or checkpoint stdout somehow?
     operation = commandline.cli(command=[shutil.which('echo'), 'hi', 'there'])
     assert operation.output.returncode.result() == 0
示例#9
0
 def test_false_implicit(self):
     command = shutil.which('false')
     operation = commandline.cli(command=[command], shell=False)
     # Allow the operation to be executed implicitly to satisfy data constraint.
     assert operation.output.returncode.result() == 1