コード例 #1
0
ファイル: test_general.py プロジェクト: KonishchevDmitry/psh
def test_invalid_command_arguments(test):
    """Tests invalid command arguments."""
    class Class:
        pass

    with pytest.raises(psh.InvalidArgument):
        sh.test(Class())

    with pytest.raises(psh.InvalidArgument):
        sh.test(_invalid=None)
コード例 #2
0
ファイル: test_general.py プロジェクト: nekolyanich/psh
def test_invalid_command_arguments(test):
    """Tests invalid command arguments."""

    class Class:
        pass

    with pytest.raises(psh.InvalidArgument):
        sh.test(Class())

    with pytest.raises(psh.InvalidArgument):
        sh.test(_invalid = None)
コード例 #3
0
def test_unsupported_operations(test):
    """Tests operations that aren't supported in the shell mode."""

    with pytest.raises(psh.InvalidOperation):
        sh.test(sh.test(_stdin="stdin"), _shell=True)

    with pytest.raises(psh.InvalidOperation):
        sh.test(sh.test(_stdin=["stdin"]), _shell=True)

    with pytest.raises(psh.InvalidOperation):
        sh.test(sh.test(_stdin=iter(["stdin"])), _shell=True)
コード例 #4
0
def test_unsupported_operations(test):
    """Tests operations that aren't supported in the shell mode."""

    with pytest.raises(psh.InvalidOperation):
        sh.test(sh.test(_stdin="stdin"), _shell=True)

    with pytest.raises(psh.InvalidOperation):
        sh.test(sh.test(_stdin=["stdin"]), _shell=True)

    with pytest.raises(psh.InvalidOperation):
        sh.test(sh.test(_stdin=iter(["stdin"])), _shell=True)
コード例 #5
0
ファイル: test_general.py プロジェクト: KonishchevDmitry/psh
def test_command_arguments(test):
    """Tests command argument parsing."""

    process = sh.test()
    assert process.command() == ["test"]
    assert str(process) == "test"
    assert bytes(process) == psys.b(str(process))

    process = sh.complex_command_name()
    assert process.command() == ["complex-command-name"]
    assert str(process) == "complex-command-name"
    assert bytes(process) == psys.b(str(process))

    process = sh("complex command name")("arg1", "arg2")
    assert process.command() == ["complex command name", "arg1", "arg2"]
    assert str(process) == "'complex command name' arg1 arg2"
    assert bytes(process) == psys.b(str(process))

    process = sh.test(b"arg", b"space arg", b"carriage\rline", b"line\narg",
                      b"tab\targ", br"slash\arg", b"quote'arg", b'quote"arg',
                      psys.b("тест"), psys.b("тест тест"), "arg", "space arg",
                      "carriage\rline", "line\narg", "tab\targ", r"slash\arg",
                      "quote'arg", 'quote"arg', "тест", "тест тест", 3, 2**128,
                      2.0)
    assert process.command() == [
        "test", b"arg", b"space arg", b"carriage\rline", b"line\narg",
        b"tab\targ", br"slash\arg", b"quote'arg", b'quote"arg',
        psys.b("тест"),
        psys.b("тест тест"), "arg", "space arg", "carriage\rline", "line\narg",
        "tab\targ", r"slash\arg", "quote'arg", 'quote"arg', "тест",
        "тест тест", "3", "340282366920938463463374607431768211456", "2.0"
    ]
    assert str(process) == (
        "test "
        r"""arg 'space arg' 'carriage\rline' 'line\narg' 'tab\targ' 'slash\\arg' "quote'arg" 'quote"arg' \xd1\x82\xd0\xb5\xd1\x81\xd1\x82 '\xd1\x82\xd0\xb5\xd1\x81\xd1\x82 \xd1\x82\xd0\xb5\xd1\x81\xd1\x82' """
        r"""arg 'space arg' 'carriage\rline' 'line\narg' 'tab\targ' 'slash\\arg' 'quote\'arg' 'quote"arg' тест 'тест тест' """
        "3 340282366920938463463374607431768211456 2.0")
    assert bytes(process) == psys.b(str(process))

    process = sh.test("space arg", s="short_arg")
    assert process.command() == ["test", "-s", "short_arg", "space arg"]
    assert str(process) == "test -s short_arg 'space arg'"
    assert bytes(process) == psys.b(str(process))

    process = sh.test("arg", long_long_arg="long arg")
    assert process.command() == ["test", "--long-long-arg", "long arg", "arg"]
    assert str(process) == "test --long-long-arg 'long arg' arg"
    assert bytes(process) == psys.b(str(process))

    process = sh.test("arg", bool_arg=True)
    assert process.command() == ["test", "--bool-arg", "arg"]
    assert str(process) == "test --bool-arg arg"
    assert bytes(process) == psys.b(str(process))

    process = sh.test("arg", bool_arg=False)
    assert process.command() == ["test", "arg"]
    assert str(process) == "test arg"
    assert bytes(process) == psys.b(str(process))
コード例 #6
0
def test_disabled_shell_mode(test):
    """
    Tests passing a Process instance to a process which is not in the shell
    mode.
    """

    with pytest.raises(psh.InvalidArgument):
        sh.test(sh.test())

    with pytest.raises(psh.InvalidArgument):
        sh.test(option=sh.test())
コード例 #7
0
ファイル: test_general.py プロジェクト: nekolyanich/psh
def test_command_arguments(test):
    """Tests command argument parsing."""

    process = sh.test()
    assert process.command() == [ "test" ]
    assert unicode(process) == "test"
    assert str(process) == unicode(process).encode("utf-8")

    process = sh.complex_command_name()
    assert process.command() == [ "complex-command-name" ]
    assert unicode(process) == "complex-command-name"
    assert str(process) == unicode(process).encode("utf-8")

    process = sh("complex command name")("arg1", "arg2")
    assert process.command() == [ "complex command name", "arg1", "arg2" ]
    assert unicode(process) == "'complex command name' arg1 arg2"
    assert str(process) == unicode(process).encode("utf-8")

    process = sh.test(
        b"arg", b"space arg", b"carriage\rline", b"line\narg", b"tab\targ", br"slash\arg", b"quote'arg", b'quote"arg', b"тест", b"тест тест",
        "arg", "space arg", "carriage\rline", "line\narg", "tab\targ", r"slash\arg", "quote'arg", 'quote"arg', "тест", "тест тест",
        3, 2 ** 128, 2.0
    )
    assert process.command() == [ "test",
        b"arg", b"space arg", b"carriage\rline", b"line\narg", b"tab\targ", br"slash\arg", b"quote'arg", b'quote"arg', b"тест", b"тест тест",
        "arg", "space arg", "carriage\rline", "line\narg", "tab\targ", r"slash\arg", "quote'arg", 'quote"arg', "тест", "тест тест",
        "3", "340282366920938463463374607431768211456", "2.0"
    ]
    assert unicode(process) == ("test "
        r"""arg 'space arg' 'carriage\rline' 'line\narg' 'tab\targ' 'slash\\arg' "quote'arg" 'quote"arg' \xd1\x82\xd0\xb5\xd1\x81\xd1\x82 '\xd1\x82\xd0\xb5\xd1\x81\xd1\x82 \xd1\x82\xd0\xb5\xd1\x81\xd1\x82' """
        r"""arg 'space arg' 'carriage\rline' 'line\narg' 'tab\targ' 'slash\\arg' 'quote\'arg' 'quote"arg' тест 'тест тест' """
        "3 340282366920938463463374607431768211456 2.0"
    )
    assert str(process) == unicode(process).encode("utf-8")

    process = sh.test("space arg", s = "short_arg")
    assert process.command() == [ "test", "-s", "short_arg", "space arg" ]
    assert unicode(process) == "test -s short_arg 'space arg'"
    assert str(process) == unicode(process).encode("utf-8")

    process = sh.test("arg", long_long_arg = "long arg")
    assert process.command() == [ "test", "--long-long-arg", "long arg", "arg" ]
    assert unicode(process) == "test --long-long-arg 'long arg' arg"
    assert str(process) == unicode(process).encode("utf-8")

    process = sh.test("arg", bool_arg = True)
    assert process.command() == [ "test", "--bool-arg", "arg" ]
    assert unicode(process) == "test --bool-arg arg"
    assert str(process) == unicode(process).encode("utf-8")

    process = sh.test("arg", bool_arg = False)
    assert process.command() == [ "test", "arg" ]
    assert unicode(process) == "test arg"
    assert str(process) == unicode(process).encode("utf-8")
コード例 #8
0
def test_disabled_shell_mode(test):
    """
    Tests passing a Process instance to a process which is not in the shell
    mode.
    """

    with pytest.raises(psh.InvalidArgument):
        sh.test(sh.test())

    with pytest.raises(psh.InvalidArgument):
        sh.test(option=sh.test())