Skip to content

Commit

Permalink
Add formatting to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pt1243 committed Oct 14, 2023
1 parent 7f774a5 commit 393fa06
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 38 deletions.
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ warn_unused_configs = true
line-length = 120
extend-exclude = '''
(
tests
| docs
docs
)
'''
53 changes: 31 additions & 22 deletions tests/test_number_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,50 @@
from my_package.number_functions import add_one, subtract_one, sum_array


@pytest.mark.parametrize("test_input,expected", [
(1, 2),
(0, 1),
(-4, -3),
(2.5, 3.5),
])
@pytest.mark.parametrize(
("test_input", "expected"),
(
(1, 2),
(0, 1),
(-4, -3),
(2.5, 3.5),
),
)
def test_add_one(test_input, expected):
assert add_one(test_input) == expected


@pytest.mark.parametrize("test_input,expected", [
(1, 0),
(0, -1),
(-4, -5),
(2.5, 1.5),
])
@pytest.mark.parametrize(
("test_input", "expected"),
(
(1, 0),
(0, -1),
(-4, -5),
(2.5, 1.5),
),
)
def test_subtract_one(test_input, expected):
assert subtract_one(test_input) == expected


def test_add_one_typeerror():
with pytest.raises(TypeError):
add_one('some string')
add_one("some string")


def test_subtract_one_typeerror():
with pytest.raises(TypeError):
subtract_one('another string')


@pytest.mark.parametrize("test_input,expected", [
(np.array([1, 2]), 3),
(np.array([]), 0),
(np.ones(3), 3),
(np.zeros(5), 0),
])
subtract_one("another string")


@pytest.mark.parametrize(
("test_input", "expected"),
(
(np.array([1, 2]), 3),
(np.array([]), 0),
(np.ones(3), 3),
(np.zeros(5), 0),
),
)
def test_sum_array(test_input, expected):
assert sum_array(test_input) == expected
34 changes: 20 additions & 14 deletions tests/test_string_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,35 @@
from my_package.string_functions import reverse_string, add_exclamation_mark


@pytest.mark.parametrize("test_input,expected", [
('abc', 'cba'),
('aaa', 'aaa'),
('', ''),
])
@pytest.mark.parametrize(
("test_input", "expected"),
(
("abc", "cba"),
("aaa", "aaa"),
("", ""),
),
)
def test_reverse_string(test_input, expected):
assert reverse_string(test_input) == expected


@pytest.mark.parametrize("test_input,expected", [
('Hello world', 'Hello world!'),
('abc', 'abc!'),
('', '!'),
])
@pytest.mark.parametrize(
("test_input", "expected"),
(
("Hello world", "Hello world!"),
("abc", "abc!"),
("", "!"),
),
)
def test_add_exclamation_mark(test_input, expected):
assert add_exclamation_mark(test_input) == expected


# def test_reverse_string_raises_typeerror():
# with pytest.raises(TypeError):
# reverse_string(3)
def test_reverse_string_raises_type_error():
with pytest.raises(TypeError):
reverse_string(3)


def test_add_exclamation_mark_raises_typeerror():
def test_add_exclamation_mark_raises_type_error():
with pytest.raises(TypeError):
add_exclamation_mark(1)

0 comments on commit 393fa06

Please sign in to comment.