# calc.py
def add(first_number, second_number):
return first_number + second_number
# tests.py
from .calc import add
def test_add_equals_to_8():
assert add(5, 3) == 8
def test_add_equals_to_5():
assert add(2, 3) == 5
import unittest
class TestStringMethods(unittest.TestCase):
def setUp(self):
pass
# Retorna True si la cadena contiene 4 a.
def test_strings_a(self):
self.assertEqual( 'a'*4, 'aaaa')
# Retorna True si la cadena está en mayúsculas
def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')
# Retorna True si la primera letra de la cadena está en
# mayúscula de otro modo retorna False
def test_isupper(self):
self.assertTrue('FOO'.isupper())
self.assertFalse('Foo'.isupper())
from hypothesis import given
import hypothesis.strategies as some
@given (some.lists(some.integers()))
def test_list_size_is_invariant_across_sorting(a_list):
original_length = len(a_list)
a_list.sort()
assert len(a_list) == original_length
@given(some.lists(some.text()))
def test_sorted_result_is_ordered(a_list):
a_list.sort()
for i in range(len(a_list) - 1):
assert a_list[i] <= a_list[i + 1]
@given(some.integers())