def main(): """ This function is used to execute the module as a standalone module. """ parser = argparse.ArgumentParser() group1 = parser.add_argument_group() group2 = parser.add_mutually_exclusive_group(required=True) group1.add_argument('x', help='The first value in the equation', type=check_type) group1.add_argument('y', help='The second value in the equation', type=check_type) group2.add_argument('--add', action='store_true') group2.add_argument('--subtract', action='store_true') group2.add_argument('--multiply', action='store_true') group2.add_argument('--divide', action='store_true') group2.add_argument('--modulus', action='store_true') args = parser.parse_args() if args.add: print(add(args.x, args.y)) if args.subtract: print(subtract(args.x, args.y)) if args.multiply: print(multiply(args.x, args.y)) if args.divide: print(divide(args.x, args.y)) if args.modulus: print(modulus(args.x, args.y))
def test_divide_integer_by_zero_float(self): """Validates that an exception raises when dividing by 0""" with self.assertRaises(ZeroDivisionError): calculator.divide(4, 0.0)
def test_divide_non_int_non_float_exception(self): """Validates that an exception raises when adding strings""" data_sets = [[], '', {}] for data_set in data_sets: with self.assertRaises(TypeError): calculator.divide(data_set, data_set)
def test_divide_remainder_float(self): """Validates that add yields the expected results""" self.assertEqual(calculator.divide(5.0, 2.0), 2.0)
def test_divide_remainder_integer(self): """Validates that add yields the expected results""" self.assertEqual(calculator.divide(5, 2), 2)