From 08dad842ea50847747dce6ffbd05fc2fde6bb70e Mon Sep 17 00:00:00 2001 From: Carlos Meza Date: Sat, 17 Apr 2021 01:07:57 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=94=EF=B8=8F=20Add=20test=20for=20cli?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fizzbuzzx.py | 8 ++++---- test_fizzbuzzx.py | 10 +++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/fizzbuzzx.py b/fizzbuzzx.py index 92dfaa7..8a69750 100755 --- a/fizzbuzzx.py +++ b/fizzbuzzx.py @@ -1,9 +1,9 @@ #!/usr/bin/env python3 """ Fizzbuzz extreme program (are you ready to see how much of a try hard I am)""" -from typing import List import argparse import logging import sys +from typing import Any, List, Optional, Sequence logging.basicConfig( # filename="fizzbuzz.log", @@ -144,11 +144,11 @@ def input_validation(fizzbuzz_input) -> int: return number -def fizzbuzz_cli(): +def fizzbuzzx_cli(args: Optional[Sequence[Any]] = None): """ CLI for fizzbuzz""" fizzbuzz_parser = argparse.ArgumentParser(description="Fizzbuzz!!!") - fizzbuzz_parser.add_argument("number", type=str, help="Input number to print up to") - fizzbuzz_args = fizzbuzz_parser.parse_args() + fizzbuzz_parser.add_argument("number", type=int, help="Input number to print up to") + fizzbuzz_args = fizzbuzz_parser.parse_args(args) number = input_validation(fizzbuzz_args.number) # LOGGER.error("Input is not an integer!") print(fizzbuzz(number)) diff --git a/test_fizzbuzzx.py b/test_fizzbuzzx.py index ecc8253..20ce047 100644 --- a/test_fizzbuzzx.py +++ b/test_fizzbuzzx.py @@ -1,5 +1,5 @@ """Test file for fizzbuzz""" -from fizzbuzzx import fizzbuzz, check_fizzbuzz, check_buzz, check_fizz +from fizzbuzzx import check_buzz, check_fizz, check_fizzbuzz, fizzbuzz, fizzbuzzx_cli def test_check_fizz(): @@ -51,3 +51,11 @@ def test_fizzbuzz(): "14", "fizzbuzz", ] + + +def test_cli(capsys): + """Test CLI.""" + args = ["3"] + fizzbuzzx_cli(args) + captured = capsys.readouterr() + assert captured.out.strip() == "['1', '2', 'fizz']"