Skip to content

Instantly share code, notes, and snippets.

@Junch
Forked from ethanwhite/mymath.py
Created February 4, 2021 04:04
Show Gist options
  • Select an option

  • Save Junch/6b0442ed7595c04840cb717b9003eade to your computer and use it in GitHub Desktop.

Select an option

Save Junch/6b0442ed7595c04840cb717b9003eade to your computer and use it in GitHub Desktop.
Simple Python nose testing example
from __future__ import division
def add(num1, num2):
assert type(num1) == int or type(num1) == float
assert type(num2) == int or type(num2) == float
return num1 + num2
def divide(numerator, denominator):
return numerator / denominator
from mymath import *
import nose
def test_add_integers():
assert add(5, 3) == 8
def test_add_integers_zero():
assert add(3, 0) == 3
def test_add_floats():
assert add(1.5, 2.5) == 4
def test_add_strings():
nose.tools.assert_raises(AssertionError, add, 'paul', 'carol')
def test_divide_integers_even():
assert divide(2, 10) == 0.2
def test_divide_integers_repetant():
nose.tools.assert_almost_equal(divide(1, 3), 0.33333333, 7)
if __name__ == '__main__':
nose.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment