예제 #1
0
    def test_quitting(self, input_values):
        self.input_values = iter(input_values)

        interface.main()

        assert any("Quitting" in s for s in self.output), (
            "Users should be able to quit your program any time")
예제 #2
0
    def test_len_prompts(self, input_values):
        expected = len(input_values)
        self.input_values = iter(input_values)

        interface.main()

        assert len(self.prompts) == expected, (
            f"You should be prompting {expected} times")
예제 #3
0
    def test_ouput_value(self, input_values, expected):
        self.input_values = iter(input_values)

        interface.main()

        pattern = r"The\sresult\sis:\s(-?\d+(.\d)?)"
        match = re.search(pattern, self.output[1])
        assert float(match.group(1)) == expected, (
            "'{}' not implemented properly".format(input_values[0]))
예제 #4
0
    def test_invalid_operator(self):
        self.input_values = iter(['invalid_operator', '1', '3', 'quit'])

        interface.main()

        assert (
            "Sorry, 'invalid_operator' "
            "is not a valid operator") in self.output, (
            "You need to handle invalid operators")
        assert all(["The result is: " not in o for o in self.output]), (
            "If the operator is invalid, you shouldn't display the result")
예제 #5
0
    def test_prompts_values(self, input_values):
        self.input_values = iter(input_values)
        interface.main()

        expected = [
            "Pick an operator (+, -, *, /, //, %): ",
            "First number: ",
            "Second number: "
        ]

        assert all(e in self.prompts for e in expected), (
            "At least one of your prompts value is wrong")
예제 #6
0
    def test_prints(self):
        self.input_values = iter(["+", "3", "1", "quit"])

        interface.main()
        prints = [
            r"Welcome to Calculator, you can quit anytime by typing 'quit'",
            r"The result is: \d+(.\d+)?",
            r"-+"
        ]
        # TODO: Probably split this into individual tests
        #       To provide more guidance
        assert all([
            any([re.search(p, o) is not None for o in self.output])
            for p in prints
        ]), "At least one of your print statement is incorrect"
예제 #7
0
    def test_len_output(self):
        self.input_values = iter(["+", "3", "1", "quit"])

        interface.main()

        assert len(self.output) == 4, "You should print out 4 times"