Skip to content

Instantly share code, notes, and snippets.

@adithyabsk
Last active August 1, 2019 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adithyabsk/fc60962b0a6d0693cd9ae22569a42235 to your computer and use it in GitHub Desktop.
Save adithyabsk/fc60962b0a6d0693cd9ae22569a42235 to your computer and use it in GitHub Desktop.
Fix the Coverage
git diff 57afaa5
# diff --git a/simplecalc/tests/test_cli.py b/simplecalc/tests/test_cli.py
# index 6130265..253f4ce 100644
# --- a/simplecalc/tests/test_cli.py
# +++ b/simplecalc/tests/test_cli.py
# @@ -27,113 +27,113 @@ def test_exception_handling_error():
# assert "Test" in str(e)
#
#
# -@pytest.mark.parametrize(
# - "err_class", ["CalculatorTypeError", "CalculatorValueError"]
# -)
# -def test_exception_handling_captures_calctypeerror(err_class, capfd):
# - """Test exception handling captures input.
# -
# - Args:
# - capfd: pytest stdout/stderr capture data
# -
# - """
# - from simplecalc.cli import _exception_handler
# - import simplecalc.calculator as calc
# -
# - Error = getattr(calc, err_class)
# -
# - def f(n1, n2):
# - raise Error("Test")
# -
# - _exception_handler(f, None, None)
# -
# - out, err = capfd.readouterr()
# - assert "Test" in out
# -
# -
# -def test_calc_main():
# - """Test main cli runner output."""
# - from simplecalc.cli import simplecalc
# -
# - runner = CliRunner()
# - result = runner.invoke(simplecalc)
# - assert result.exit_code == 0
# - assert "Usage: simplecalc" in result.output
# -
# -
# -def test_calc_sum_fail():
# - """Test sum failure."""
# - from simplecalc.cli import sum as s
# -
# - runner = CliRunner()
# - result = runner.invoke(s)
# - assert result.exit_code == 0
# - assert "Input list must have at least two items" in result.output
# -
# - runner = CliRunner()
# - result = runner.invoke(s, ["Test", "Test"])
# - assert result.exit_code == 0
# - assert "All inputs must be a number" in result.output
# -
# -
# -def test_calc_sum():
# - """Test sum valid inputs."""
# - from simplecalc.cli import sum as s
# -
# - runner = CliRunner()
# - result = runner.invoke(s, ["1", "0.2", "0.3"])
# - assert result.exit_code == 0
# - assert pytest.approx(float(result.output)) == 1.5
# -
# -
# Once fixed pytest should give us 100% coverage
pyetst
# ======================================================== test session starts ========================================================
# platform darwin -- Python 3.6.8, pytest-3.10.1, py-1.8.0, pluggy-0.12.0 -- /Users/adithyabalaji/.pyenv/versions/3.6.8/envs/tooling_example/bin/python
# cachedir: .pytest_cache
# rootdir: /Users/adithyabalaji/Coding/simplecalc, inifile: setup.cfg
# plugins: xdoctest-0.9.1, cov-2.7.1, mock-1.10.4
# collected 28 items
#
# simplecalc/calculator.py::sum_:0 PASSED [ 3%]
# simplecalc/calculator.py::difference:0 PASSED [ 7%]
# simplecalc/calculator.py::product:0 PASSED [ 10%]
# simplecalc/calculator.py::quotient:0 PASSED [ 14%]
# simplecalc/tests/test_calculator.py::test_custom_exceptions PASSED [ 17%]
# simplecalc/tests/test_calculator.py::test_convet_num PASSED [ 21%]
# simplecalc/tests/test_calculator.py::test_check_input_not_list PASSED [ 25%]
# simplecalc/tests/test_calculator.py::test_check_input_list_length PASSED [ 28%]
# simplecalc/tests/test_calculator.py::test_check_input_all_numbers_conversion PASSED [ 32%]
# simplecalc/tests/test_calculator.py::test_check_input_all_numbers_error PASSED [ 35%]
# simplecalc/tests/test_calculator.py::test_check_input_protect_division_zero PASSED [ 39%]
# simplecalc/tests/test_calculator.py::test_sum PASSED [ 42%]
# simplecalc/tests/test_calculator.py::test_difference PASSED [ 46%]
# simplecalc/tests/test_calculator.py::test_product PASSED [ 50%]
# simplecalc/tests/test_calculator.py::test_quotient PASSED [ 53%]
# simplecalc/tests/test_cli.py::test_exception_handling_valid PASSED [ 57%]
# simplecalc/tests/test_cli.py::test_exception_handling_error PASSED [ 60%]
# simplecalc/tests/test_cli.py::test_exception_handling_captures_calctypeerror[CalculatorTypeError] PASSED [ 64%]
# simplecalc/tests/test_cli.py::test_exception_handling_captures_calctypeerror[CalculatorValueError] PASSED [ 67%]
# simplecalc/tests/test_cli.py::test_calc_main PASSED [ 71%]
# simplecalc/tests/test_cli.py::test_calc_sum_fail PASSED [ 75%]
# simplecalc/tests/test_cli.py::test_calc_sum PASSED [ 78%]
# simplecalc/tests/test_cli.py::test_calc_difference_fail PASSED [ 82%]
# simplecalc/tests/test_cli.py::test_calc_difference PASSED [ 85%]
# simplecalc/tests/test_cli.py::test_calc_product_fail PASSED [ 89%]
# simplecalc/tests/test_cli.py::test_calc_product PASSED [ 92%]
# simplecalc/tests/test_cli.py::test_calc_quotient_fail PASSED [ 96%]
# simplecalc/tests/test_cli.py::test_calc_quotient PASSED [100%]
#
# ---------- coverage: platform darwin, python 3.6.8-final-0 -----------
# Name Stmts Miss Branch BrPart Cover
# ------------------------------------------------------------
# simplecalc/__init__.py 12 0 0 0 100%
# simplecalc/calculator.py 31 0 17 0 100%
# simplecalc/cli.py 20 0 0 0 100%
# ------------------------------------------------------------
# TOTAL 63 0 17 0 100%
# Coverage HTML written to dir htmlcov
#
#
# ===================================================== 28 passed in 0.44 seconds =====================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment