Python Forum
how can I test this interactive calculator using pytest
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how can I test this interactive calculator using pytest
#1
hi,

I have small interactive calculator.
could you please give me a hint how could test it using pytest?
I found e.g. this approach, but have no idea how apply it:
https://stackoverflow.com/questions/5347...simulation
or maybe you have another idea.

thank you for any help!
#!/usr/bin/env python3


class Calculator:
    def __init__(self):
        pass

    def add(self, a, b):
        return a + b

    def sub(self, a, b):
        return a - b
		
#!/usr/bin/env python3
import calculator
import cmd


class InteractiveCalculator(cmd.Cmd):
    prompt = '(icalc) '
    cal = calculator.Calculator()

    def do_add(self, arg):
        """A + B"""
        print(self.cal.add(*parse(arg)))

    def do_sub(self, arg):
        """A - B"""
        print(self.cal.sub(*parse(arg)))

    def do_exit(self, arg):
        """quits from the program"""
        exit()


def parse(arg):
    """Convert a series of zero or more numbers to an argument tuple"""
    return tuple(map(int, arg.split()))


if __name__ == '__main__':
    InteractiveCalculator().cmdloop()
Yoriz write Dec-17-2022, 10:28 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
how can I test this interactive calculator using pytest - by medveeee - Dec-17-2022, 08:38 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  call an instance of a class in the interactive nzcan 3 2,985 Aug-23-2018, 10:47 AM
Last Post: nzcan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020