def test_prompt(self, monkeypatch):
        i = Input("testing")

        def mock_input_yes(label):
            return "yes"

        monkeypatch.setattr("builtins.input", mock_input_yes)
        with captured_output() as (output, error):
            result = i.prompt()
            assert "yes" == result

        def mock_input3(label):
            return "3"

        choices = ["a", "b", "c"]
        i = Input("Pick a Letter", choices=choices, required=True)
        monkeypatch.setattr("builtins.input", mock_input3)
        with captured_output() as (output, error):
            result = i.prompt()
            assert "c" == result

        def mock_input_empty(label):
            return ""

        try:
            i = Input("testing", required=True)
            monkeypatch.setattr("builtins.input", mock_input_empty)
            with captured_output() as (output, error):
                i.prompt()
                # self.assertTrue("required" in output.getstring())
        except RecursionError:
            pass
Exemplo n.º 2
0
def test_hr():
    with captured_output() as (output, error):
        hr(character="=", color=red, size=10)
        assert "===" in output.getvalue()

    with captured_output() as (output, error):
        hr(character="=", size=10)
        assert "===" in output.getvalue()
    def test_prompt(self):
        i = Divider(label="Testing")
        with captured_output() as (output, error):
            i.prompt()

            assert "Testing" in output.getvalue()
            assert "===" in output.getvalue()
def test_get_input(monkeypatch):
    # Without default value.
    def mock_input_testing(label):
        return "testing"

    monkeypatch.setattr("builtins.input", mock_input_testing)
    with captured_output() as (output, error):
        result = get_input("What Is This?")
        assert "testing" == result

    # With default value.
    def mock_input_empty(label):
        return ""

    monkeypatch.setattr("builtins.input", mock_input_empty)
    with captured_output() as (output, error):
        result = get_input("What Is This", default="testing")
        assert "testing" == result
def test_get_choice(monkeypatch):
    # Without choices.

    def mock_input1(label):
        return "1"

    monkeypatch.setattr("builtins.input", mock_input1)
    with captured_output() as (output, error):
        result = get_choice("Yes or No")
        assert "yes" == result

    # With choices.

    def mock_input3(label):
        return "3"

    choices = ["a", "b", "c"]
    monkeypatch.setattr("builtins.input", mock_input3)
    with captured_output() as (output, error):
        result = get_choice("Pick a Letter", choices=choices)
        assert "c" == result

    # With default.
    def mock_input_empty(label):
        return ""

    choices = ["a", "b", "c"]
    monkeypatch.setattr("builtins.input", mock_input_empty)
    with captured_output() as (output, error):
        result = get_choice("Pick a Letter", choices=choices, default="b")
        assert "b" == result

    # With invalid choice.
    def mock_input4(label):
        return "4"

    try:
        choices = ["a", "b", "c"]
        monkeypatch.setattr("builtins.input", mock_input4)
        with captured_output() as (output, error):
            get_choice("Pick a Letter", choices=choices, default="b")
            # self.assertTrue("Invalid" in output.getstring())
    except RecursionError:
        pass
    def test_prompt(self, monkeypatch):
        def mock_input(label):
            return "testing"

        form = TestingForm()

        monkeypatch.setattr("builtins.input", mock_input)
        with captured_output() as (output, error):
            form.prompt()
            assert len(form.values) == 3
Exemplo n.º 7
0
    def test_str(self):
        feedback = Feedback()
        feedback.blue("This is an INFORMATIONAL message.")
        feedback.plain("This is a just a message message.")
        feedback.hr()

        with captured_output() as (output, error):
            print(feedback)
            assert "INFORMATIONAL" in output.getvalue()
            assert "just a message" in output.getvalue()
            assert "---" in output.getvalue()
class test_abort():
    try:
        abort("")
    except SystemExit:
        assert True

    # noinspection PyUnusedLocal
    with captured_output() as (output, error):
        try:
            abort("I can't go on.")
        except SystemExit:
            assert True
    def test_prompt(self, monkeypatch):
        i = Secret("password")

        def mock_raw_input(prompt, stream, input):
            return "secret"

        monkeypatch.setattr("getpass._raw_input", mock_raw_input)
        # with patch("getpass._raw_input", return_value="secret"):
        with captured_output() as (output, error):
            result = i.prompt()
            assert "secret" == result

        def mock_raw_input_empty(prompt, stream, input):
            return ""

        i.required = True
        try:
            monkeypatch.setattr("getpass._raw_input", mock_raw_input_empty)
            # with patch('getpass._raw_input', return_value=""):
            with captured_output() as (output, error):
                i.prompt()
        except RecursionError:
            pass
Exemplo n.º 10
0
    def test_str(self):
        headings = [
            "Column 1",
            "Column 2",
            "Column 3",
        ]

        table = Table(headings=headings)
        table.add(["a", "b", "c"])
        table.add(["d", "e", "f"])
        table.add(["g", "h", "i"])

        with captured_output() as (output, error):
            print(table)
            assert "Column 1" in output.getvalue()
            assert "---" in output.getvalue()
Exemplo n.º 11
0
def test_blue():
    with captured_output() as (output, error):
        blue("This is blue.")

        assert "This is blue." in output.getvalue()
Exemplo n.º 12
0
def test_yellow():
    with captured_output() as (output, error):
        yellow("This is yellow.")
        assert "This is yellow." in output.getvalue()
Exemplo n.º 13
0
def test_red():
    with captured_output() as (output, error):
        red("This is red.")
        assert "This is red." in output.getvalue()
Exemplo n.º 14
0
def test_plain():
    with captured_output() as (output, error):
        plain("This is plain.", prefix="Testing:", suffix="wow")
        assert "This is plain." in output.getvalue()
Exemplo n.º 15
0
def test_green():
    with captured_output() as (output, error):
        green("This is green.")
        assert "This is green." in output.getvalue()